copy src_MD-M-SAXS-homology src-HCD-5D
[unres.git] / source / wham / src-HCD-5D / 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       implicit none
9       double precision tcpu
10       include 'COMMON.TIME1'
11 #ifdef MP
12       include 'mpif.h'
13 #endif
14 C Diminish the assigned time limit a little so that there is some time to
15 C end a batch job
16 c     timlim=batime-150.0
17 C Calculate the initial time, if it is not zero (e.g. for the SUN).
18       stime=tcpu()
19 cd    print *,' in SET_TIMERS stime=',stime
20       return 
21       end
22 C------------------------------------------------------------------------------
23       logical function stopx(nf)
24 C This function returns .true. if one of the following reasons to exit SUMSL
25 C occurs. The "reason" code is stored in WHATSUP passed thru a COMMON block:
26 C
27 C... WHATSUP = 0 - go on, no reason to stop. Stopx will return .false.
28 C...           1 - Time up in current node;
29 C...           2 - STOP signal was received from another node because the
30 C...               node's task was accomplished (parallel only);
31 C...          -1 - STOP signal was received from another node because of error;
32 C...          -2 - STOP signal was received from another node, because 
33 C...               the node's time was up.
34       implicit real*8 (a-h,o-z)
35       include 'DIMENSIONS'
36       integer nf
37       logical ovrtim
38 #ifdef MP
39       include 'mpif.h'
40       include 'COMMON.INFO'
41 #endif
42       include 'COMMON.IOUNITS'
43       include 'COMMON.TIME1'
44       integer Kwita
45
46 cd    print *,'Processor',MyID,' NF=',nf
47 #ifndef MPI
48       if (ovrtim()) then
49 C Finish if time is up.
50          stopx = .true.
51          WhatsUp=1
52 #ifdef MPL
53       else if (mod(nf,100).eq.0) then
54 C Other processors might have finished. Check this every 100th function 
55 C evaluation.
56 C Master checks if any other processor has sent accepted conformation(s) to it. 
57          if (MyID.ne.MasterID) call receive_mcm_info
58          if (MyID.eq.MasterID) call receive_conf
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            WhatsUp=2
68          elseif (Kwita.eq.-2) then
69            write (iout,*)
70      &    'Processor',MyID,' received TIMEUP-STOP signal in SUMSL.'
71            write (*,*)
72      &    'Processor',MyID,' received TIMEUP-STOP signal in SUMSL.'
73            WhatsUp=-2
74            stopx=.true.  
75          else if (Kwita.eq.-3) then
76            write (iout,*)
77      &    'Processor',MyID,' received ERROR-STOP signal in SUMSL.'
78            write (*,*)
79      &    'Processor',MyID,' received ERROR-STOP signal in SUMSL.'
80            WhatsUp=-1
81            stopx=.true.
82          else
83            stopx=.false.
84            WhatsUp=0
85          endif
86 #endif
87       else
88          stopx = .false.
89          WhatsUp=0
90       endif
91 #else
92       stopx=.false.
93 #endif
94
95 #ifdef OSF
96 c Check for FOUND_NAN flag
97       if (FOUND_NAN) then
98         write(iout,*)"   ***   stopx : Found a NaN"
99         stopx=.true.
100       endif
101 #endif
102
103       return
104       end
105 C--------------------------------------------------------------------------
106       logical function ovrtim() 
107       include 'DIMENSIONS'
108       include 'COMMON.IOUNITS'
109       include 'COMMON.TIME1'
110       real*8 tcpu
111 #ifdef MPI
112       include "mpif.h"
113       curtim = MPI_Wtime()-walltime
114 #else
115       curtim= tcpu()
116 #endif
117 C  curtim is the current time in seconds.
118 c      write (iout,*) "curtim",curtim," timlim",timlim," safety",safety
119       if (curtim .ge. timlim - safety) then
120         write (iout,'(a,f10.2,a,f10.2,a,f10.2,a)') 
121      &  "***************** Elapsed time (",curtim,
122      &  " s) is within the safety limit (",safety,
123      &  " s) of the allocated time (",timlim," s). Terminating."
124         ovrtim=.true.
125       else
126         ovrtim=.false.
127       endif
128       return                                               
129       end
130 **************************************************************************      
131       double precision function tcpu()
132       include 'COMMON.TIME1'
133 #ifdef ES9000 
134 ****************************
135 C Next definition for EAGLE (ibm-es9000)
136       real*8 micseconds
137       integer rcode
138       tcpu=cputime(micseconds,rcode)
139       tcpu=(micseconds/1.0E6) - stime
140 ****************************
141 #endif
142 #ifdef SUN
143 ****************************
144 C Next definitions for sun
145       REAL*8  ECPU,ETIME,ETCPU
146       dimension tarray(2)
147       tcpu=etime(tarray)
148       tcpu=tarray(1)
149 ****************************
150 #endif
151 #ifdef KSR
152 ****************************
153 C Next definitions for ksr
154 C this function uses the ksr timer ALL_SECONDS from the PMON library to
155 C return the elapsed time in seconds
156       tcpu= all_seconds() - stime
157 ****************************
158 #endif
159 #ifdef SGI
160 ****************************
161 C Next definitions for sgi
162       real timar(2), etime
163       seconds = etime(timar)
164 Cd    print *,'seconds=',seconds,' stime=',stime
165 C      usrsec = timar(1)
166 C      syssec = timar(2)
167       tcpu=seconds - stime
168 ****************************
169 #endif
170
171 #ifdef LINUX
172 ****************************
173 C Next definitions for sgi
174       real timar(2), etime
175       seconds = etime(timar)
176 Cd    print *,'seconds=',seconds,' stime=',stime
177 C      usrsec = timar(1)
178 C      syssec = timar(2)
179       tcpu=seconds - stime
180 ****************************
181 #endif
182
183
184 #ifdef CRAY
185 ****************************
186 C Next definitions for Cray
187 C     call date(curdat)
188 C     curdat=curdat(1:9)
189 C     call clock(curtim)
190 C     curtim=curtim(1:8)
191       cpusec = second()
192       tcpu=cpusec - stime
193 ****************************
194 #endif
195 #ifdef AIX
196 ****************************
197 C Next definitions for RS6000
198        integer*4 i1,mclock
199        i1 = mclock()
200        tcpu = (i1+0.0D0)/100.0D0
201 #endif
202 #ifdef WINPGI
203 ****************************
204 c next definitions for windows NT Digital fortran
205        real time_real
206        call cpu_time(time_real)
207        tcpu = time_real
208 #endif
209 #ifdef WINIFL
210 ****************************
211 c next definitions for windows NT Digital fortran
212        real time_real
213        call cpu_time(time_real)
214        tcpu = time_real
215 #endif
216
217       return     
218       end  
219 C---------------------------------------------------------------------------
220       subroutine dajczas(rntime,hrtime,mintime,sectime)
221       include 'COMMON.IOUNITS'
222       real*8 rntime,hrtime,mintime,sectime 
223       hrtime=rntime/3600.0D0 
224       hrtime=aint(hrtime)
225       mintime=aint((rntime-3600.0D0*hrtime)/60.0D0)
226       sectime=aint((rntime-3600.0D0*hrtime-60.0D0*mintime)+0.5D0)
227       if (sectime.eq.60.0D0) then
228         sectime=0.0D0
229         mintime=mintime+1.0D0
230       endif
231       ihr=hrtime
232       imn=mintime
233       isc=sectime
234       write (iout,328) ihr,imn,isc
235   328 FORMAT(//'***** Computation time: ',I4  ,' hours ',I2  ,
236      1         ' minutes ', I2  ,' seconds *****')       
237       return
238       end