added source code
[unres.git] / source / cluster / wham / src-M / timing.F
1 C $Date: 1994/10/05 16:41:52 $
2 C $Revision: 2.2 $
3 C
4 C
5 C
6       subroutine set_timers
7 c
8       include 'COMMON.TIME1'
9 C Diminish the assigned time limit a little so that there is some time to
10 C end a batch job
11 c     timlim=batime-150.0
12 C Calculate the initial time, if it is not zero (e.g. for the SUN).
13       stime=tcpu()
14       return 
15       end
16       logical function stopx(nf)
17 C
18 C     ..................................................................
19 C
20 C     *****PURPOSE...
21 C     THIS FUNCTION MAY SERVE AS THE STOPX (ASYNCHRONOUS INTERRUPTION)
22 C     FUNCTION FOR THE NL2SOL (NONLINEAR LEAST-SQUARES) PACKAGE AT
23 C     THOSE INSTALLATIONS WHICH DO NOT WISH TO IMPLEMENT A
24 C     DYNAMIC STOPX.
25 C
26 C     *****ALGORITHM NOTES...
27 C     AT INSTALLATIONS WHERE THE NL2SOL SYSTEM IS USED
28 C     INTERACTIVELY, THIS DUMMY STOPX SHOULD BE REPLACED BY A
29 C     FUNCTION THAT RETURNS .TRUE. IF AND ONLY IF THE INTERRUPT
30 C     (BREAK) KEY HAS BEEN PRESSED SINCE THE LAST CALL ON STOPX.
31 C
32 C     $$$ MODIFIED FOR USE AS  THE TIMER ROUTINE.
33 C     $$$                              WHEN THE TIME LIMIT HAS BEEN
34 C     $$$ REACHED     STOPX IS SET TO .TRUE  AND INITIATES (IN ITSUM)
35 C     $$$ AND ORDERLY EXIT OUT OF SUMSL.  IF ARRAYS IV AND V ARE
36 C     $$$ SAVED, THE SUMSL ROUTINES CAN BE RESTARTED AT THE SAME
37 C     $$$ POINT AT WHICH THEY WERE INTERRUPTED.
38 C
39 C     ..................................................................
40 C
41       include 'DIMENSIONS'
42       integer nf
43       logical ovrtim
44       include 'COMMON.IOUNITS'
45       include 'COMMON.TIME1'
46 #ifdef MPL
47       include 'COMMON.INFO'
48       integer Kwita
49
50 cd    print *,'Processor',MyID,' NF=',nf
51 #endif
52       if (ovrtim()) then
53 C Finish if time is up.
54          stopx = .true.
55 #ifdef MPL
56       else if (mod(nf,100).eq.0) then
57 C Other processors might have finished. Check this every 100th function 
58 C evaluation.
59 cd       print *,'Processor ',MyID,' is checking STOP: nf=',nf
60          call recv_stop_sig(Kwita)
61          if (Kwita.eq.-1) then
62            write (iout,'(a,i4,a,i5)') 'Processor',
63      &     MyID,' has received STOP signal in STOPX; NF=',nf
64            write (*,'(a,i4,a,i5)') 'Processor',
65      &     MyID,' has received STOP signal in STOPX; NF=',nf
66            stopx=.true.
67          else
68            stopx=.false.
69          endif
70 #endif
71       else
72          stopx = .false.
73       endif
74       return
75       end
76       logical function ovrtim() 
77       include 'COMMON.TIME1'
78 C Set a 100.0 secs. safety margin, so as to allow for the termination of 
79 C a batch job.
80 c      double  safety /150.0D0/
81       curtim= tcpu()
82 cd    print *,'curtim=',curtim,' timlim=',timlim
83 C  curtim is the current time in seconds.
84       ovrtim=(curtim .ge. timlim - safety )
85       return                                               
86       end
87 **************************************************************************      
88       double precision function tcpu()
89       include 'COMMON.TIME1'
90 #ifdef ES9000 
91 ****************************
92 C Next definition for EAGLE (ibm-es9000)
93       real*8 micseconds
94       integer rcode
95       tcpu=cputime(micseconds,rcode)
96       tcpu=(micseconds/1.0E6) - stime
97 ****************************
98 #endif
99 #ifdef SUN
100 ****************************
101 C Next definitions for sun
102       integer seconds
103       call clock(seconds)
104       tcpu=seconds - stime
105 ****************************
106 #endif
107 #ifdef KSR
108 ****************************
109 C Next definitions for ksr
110 C this function uses the ksr timer ALL_SECONDS from the PMON library to
111 C return the elapsed time in seconds
112       tcpu= all_seconds() - stime
113 ****************************
114 #endif
115 #ifdef SGI
116 ****************************
117 C Next definitions for sgi
118       real timar(2), etime
119       seconds = etime(timar)
120 C      usrsec = timar(1)
121 C      syssec = timar(2)
122       tcpu=seconds - stime
123 ****************************
124 #endif
125 #ifdef CRAY
126 ****************************
127 C Next definitions for Cray
128 C     call date(curdat)
129 C     curdat=curdat(1:9)
130 C     call clock(curtim)
131 C     curtim=curtim(1:8)
132       cpusec = second()
133       tcpu=cpusec - stime
134 ****************************
135 #endif
136 #ifdef AIX
137 ****************************
138 C Next definitions for RS6000
139        integer*4 i1,mclock
140        i1 = mclock()
141        tcpu = (i1+0.0D0)/100.0D0
142 #endif
143 #ifdef LINUX
144 ****************************
145 C Next definitions for sgi
146       real timar(2), etime
147       seconds = etime(timar)
148 Cd    print *,'seconds=',seconds,' stime=',stime
149 C      usrsec = timar(1)
150 C      syssec = timar(2)
151       tcpu=seconds - stime
152 ****************************
153 #endif
154       return     
155       end  
156 *
157       subroutine dajczas(rntime,hrtime,mintime,sectime)
158       include 'COMMON.IOUNITS'
159       real*8 rntime,hrtime,mintime,sectime 
160       hrtime=rntime/3600.0D0 
161       hrtime=aint(hrtime)
162       mintime=aint((rntime-3600.0D0*hrtime)/60.0D0)
163       sectime=aint((rntime-3600.0D0*hrtime-60.0D0*mintime)+0.5D0)
164       if (sectime.eq.60.0D0) then
165         sectime=0.0D0
166         mintime=mintime+1.0D0
167       endif
168       ihr=hrtime
169       imn=mintime
170       isc=sectime
171       write (iout,328) ihr,imn,isc
172   328 FORMAT(//'***** Computation time: ',I4  ,' hours ',I2  ,
173      1         ' minutes ', I2  ,' seconds *****')       
174       return
175       end