ctest wham & cluster src-M
[unres.git] / source / unres / src_MD / 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 #ifdef MPI
20       walltime=MPI_WTIME()
21       time_reduce=0.0d0
22       time_allreduce=0.0d0
23       time_bcast=0.0d0
24       time_gather=0.0d0
25       time_sendrecv=0.0d0
26       time_scatter=0.0d0
27       time_scatter_fmat=0.0d0
28       time_scatter_ginv=0.0d0
29       time_scatter_fmatmult=0.0d0
30       time_scatter_ginvmult=0.0d0
31       time_barrier_e=0.0d0
32       time_barrier_g=0.0d0
33       time_enecalc=0.0d0
34       time_sumene=0.0d0
35       time_lagrangian=0.0d0
36       time_sumgradient=0.0d0
37       time_intcartderiv=0.0d0
38       time_inttocart=0.0d0
39       time_ginvmult=0.0d0
40       time_fricmatmult=0.0d0
41       time_cartgrad=0.0d0
42       time_bcastc=0.0d0
43       time_bcast7=0.0d0
44       time_bcastw=0.0d0
45       time_intfcart=0.0d0
46       time_vec=0.0d0
47       time_mat=0.0d0
48       time_fric=0.0d0
49       time_stoch=0.0d0
50       time_fricmatmult=0.0d0
51       time_fsample=0.0d0
52 #endif
53 cd    print *,' in SET_TIMERS stime=',stime
54       return 
55       end
56 C------------------------------------------------------------------------------
57       logical function stopx(nf)
58 C This function returns .true. if one of the following reasons to exit SUMSL
59 C occurs. The "reason" code is stored in WHATSUP passed thru a COMMON block:
60 C
61 C... WHATSUP = 0 - go on, no reason to stop. Stopx will return .false.
62 C...           1 - Time up in current node;
63 C...           2 - STOP signal was received from another node because the
64 C...               node's task was accomplished (parallel only);
65 C...          -1 - STOP signal was received from another node because of error;
66 C...          -2 - STOP signal was received from another node, because 
67 C...               the node's time was up.
68       implicit real*8 (a-h,o-z)
69       include 'DIMENSIONS'
70       integer nf
71       logical ovrtim
72 #ifdef MP
73       include 'mpif.h'
74       include 'COMMON.INFO'
75 #endif
76       include 'COMMON.IOUNITS'
77       include 'COMMON.TIME1'
78       integer Kwita
79
80 cd    print *,'Processor',MyID,' NF=',nf
81 #ifndef MPI
82       if (ovrtim()) then
83 C Finish if time is up.
84          stopx = .true.
85          WhatsUp=1
86 #ifdef MPL
87       else if (mod(nf,100).eq.0) then
88 C Other processors might have finished. Check this every 100th function 
89 C evaluation.
90 C Master checks if any other processor has sent accepted conformation(s) to it. 
91          if (MyID.ne.MasterID) call receive_mcm_info
92          if (MyID.eq.MasterID) call receive_conf
93 cd       print *,'Processor ',MyID,' is checking STOP: nf=',nf
94          call recv_stop_sig(Kwita)
95          if (Kwita.eq.-1) then
96            write (iout,'(a,i4,a,i5)') 'Processor',
97      &     MyID,' has received STOP signal in STOPX; NF=',nf
98            write (*,'(a,i4,a,i5)') 'Processor',
99      &     MyID,' has received STOP signal in STOPX; NF=',nf
100            stopx=.true.
101            WhatsUp=2
102          elseif (Kwita.eq.-2) then
103            write (iout,*)
104      &    'Processor',MyID,' received TIMEUP-STOP signal in SUMSL.'
105            write (*,*)
106      &    'Processor',MyID,' received TIMEUP-STOP signal in SUMSL.'
107            WhatsUp=-2
108            stopx=.true.  
109          else if (Kwita.eq.-3) then
110            write (iout,*)
111      &    'Processor',MyID,' received ERROR-STOP signal in SUMSL.'
112            write (*,*)
113      &    'Processor',MyID,' received ERROR-STOP signal in SUMSL.'
114            WhatsUp=-1
115            stopx=.true.
116          else
117            stopx=.false.
118            WhatsUp=0
119          endif
120 #endif
121       else
122          stopx = .false.
123          WhatsUp=0
124       endif
125 #else
126       stopx=.false.
127 #endif
128
129 #ifdef OSF
130 c Check for FOUND_NAN flag
131       if (FOUND_NAN) then
132         write(iout,*)"   ***   stopx : Found a NaN"
133         stopx=.true.
134       endif
135 #endif
136
137       return
138       end
139 C--------------------------------------------------------------------------
140       logical function ovrtim() 
141       include 'DIMENSIONS'
142       include 'COMMON.IOUNITS'
143       include 'COMMON.TIME1'
144       include 'COMMON.SETUP'
145       include 'COMMON.CONTROL'
146       real*8 tcpu
147 #ifdef MPI
148       include "mpif.h"
149       curtim = MPI_Wtime()-walltime
150 #else
151       curtim= tcpu()
152 #endif
153 C  curtim is the current time in seconds.
154 c      write (iout,*) "curtim",curtim," timlim",timlim," safety",safety
155       if (curtim .ge. timlim - safety) then
156        if (me.eq.king .or. .not. out1file)
157      &   write (iout,'(a,f10.2,a,f10.2,a,f10.2,a)') 
158      &  "***************** Elapsed time (",curtim,
159      &  " s) is within the safety limit (",safety,
160      &  " s) of the allocated time (",timlim," s). Terminating."
161         ovrtim=.true.
162       else
163         ovrtim=.false.
164       endif
165       return                                               
166       end
167 **************************************************************************      
168       double precision function tcpu()
169       include 'COMMON.TIME1'
170 #ifdef ES9000 
171 ****************************
172 C Next definition for EAGLE (ibm-es9000)
173       real*8 micseconds
174       integer rcode
175       tcpu=cputime(micseconds,rcode)
176       tcpu=(micseconds/1.0E6) - stime
177 ****************************
178 #endif
179 #ifdef SUN
180 ****************************
181 C Next definitions for sun
182       REAL*8  ECPU,ETIME,ETCPU
183       dimension tarray(2)
184       tcpu=etime(tarray)
185       tcpu=tarray(1)
186 ****************************
187 #endif
188 #ifdef KSR
189 ****************************
190 C Next definitions for ksr
191 C this function uses the ksr timer ALL_SECONDS from the PMON library to
192 C return the elapsed time in seconds
193       tcpu= all_seconds() - stime
194 ****************************
195 #endif
196 #ifdef SGI
197 ****************************
198 C Next definitions for sgi
199       real timar(2), etime
200       seconds = etime(timar)
201 Cd    print *,'seconds=',seconds,' stime=',stime
202 C      usrsec = timar(1)
203 C      syssec = timar(2)
204       tcpu=seconds - stime
205 ****************************
206 #endif
207
208 c#ifdef LINUX
209 c****************************
210 cC Next definitions for sgi
211 c      real timar(2), etime
212 c      seconds = etime(timar)
213 Cd    print *,'seconds=',seconds,' stime=',stime
214 C      usrsec = timar(1)
215 C      syssec = timar(2)
216 c      tcpu=seconds - stime
217 c****************************
218 c#endif
219
220
221 #ifdef CRAY
222 ****************************
223 C Next definitions for Cray
224 C     call date(curdat)
225 C     curdat=curdat(1:9)
226 C     call clock(curtim)
227 C     curtim=curtim(1:8)
228       cpusec = second()
229       tcpu=cpusec - stime
230 ****************************
231 #endif
232 #ifdef AIX
233 ****************************
234 C Next definitions for RS6000
235 c       integer*4 i1,mclock
236        i1 = mclock()
237        tcpu = (i1+0.0D0)/100.0D0
238 #endif
239 #ifdef WINPGI
240 ****************************
241 c next definitions for windows NT Digital fortran
242        real time_real
243        call cpu_time(time_real)
244        tcpu = time_real
245 #endif
246 #ifdef WINIFL
247 ****************************
248 c next definitions for windows NT Digital fortran
249        real time_real
250        call cpu_time(time_real)
251        tcpu = time_real
252 #endif
253
254       return     
255       end  
256 C---------------------------------------------------------------------------
257       subroutine dajczas(rntime,hrtime,mintime,sectime)
258       include 'COMMON.IOUNITS'
259       real*8 rntime,hrtime,mintime,sectime 
260       hrtime=rntime/3600.0D0 
261       hrtime=aint(hrtime)
262       mintime=aint((rntime-3600.0D0*hrtime)/60.0D0)
263       sectime=aint((rntime-3600.0D0*hrtime-60.0D0*mintime)+0.5D0)
264       if (sectime.eq.60.0D0) then
265         sectime=0.0D0
266         mintime=mintime+1.0D0
267       endif
268       ihr=hrtime
269       imn=mintime
270       isc=sectime
271       write (iout,328) ihr,imn,isc
272   328 FORMAT(//'***** Computation time: ',I4  ,' hours ',I2  ,
273      1         ' minutes ', I2  ,' seconds *****')       
274       return
275       end
276 C---------------------------------------------------------------------------
277       subroutine print_detailed_timing
278       implicit real*8 (a-h,o-z)
279       include 'DIMENSIONS'
280 #ifdef MPI
281       include 'mpif.h'
282 #endif
283       include 'COMMON.IOUNITS'
284       include 'COMMON.TIME1'
285       include 'COMMON.SETUP'
286 #ifdef MPI
287       time1=MPI_WTIME()
288          write (iout,'(80(1h=)/a/(80(1h=)))') 
289      &    "Details of FG communication time"
290          write (*,'(7(a40,1pe15.5/),40(1h-)/a40,1pe15.5/80(1h=))') 
291      &    "BROADCAST:",time_bcast,"REDUCE:",time_reduce,
292      &    "GATHER:",time_gather,
293      &    "SCATTER:",time_scatter,"SENDRECV:",time_sendrecv,
294      &    "BARRIER ene",time_barrier_e,
295      &    "BARRIER grad",time_barrier_g,
296      &    "TOTAL:",
297      &    time_bcast+time_reduce+time_gather+time_scatter+time_sendrecv
298          write (*,*) fg_rank,myrank,
299      &     ': Total wall clock time',time1-walltime,' sec'
300          write (*,*) "Processor",fg_rank,myrank,
301      &     ": BROADCAST time",time_bcast," REDUCE time",
302      &      time_reduce," GATHER time",time_gather," SCATTER time",
303      &      time_scatter,
304      &     " SCATTER fmatmult",time_scatter_fmatmult,
305      &     " SCATTER ginvmult",time_scatter_ginvmult,
306      &     " SCATTER fmat",time_scatter_fmat,
307      &     " SCATTER ginv",time_scatter_ginv,
308      &      " SENDRECV",time_sendrecv,
309      &      " BARRIER ene",time_barrier_e,
310      &      " BARRIER GRAD",time_barrier_g,
311      &      " BCAST7",time_bcast7," BCASTC",time_bcastc,
312      &      " BCASTW",time_bcastw," ALLREDUCE",time_allreduce,
313      &      " TOTAL",
314      &      time_bcast+time_reduce+time_gather+time_scatter+
315      &      time_sendrecv+time_barrier+time_bcastc
316 #else
317       time1=tcpu()
318 #endif
319          write (*,*) "Processor",fg_rank,myrank," enecalc",time_enecalc
320          write (*,*) "Processor",fg_rank,myrank," sumene",time_sumene
321          write (*,*) "Processor",fg_rank,myrank," intfromcart",
322      &     time_intfcart
323          write (*,*) "Processor",fg_rank,myrank," vecandderiv",
324      &     time_vec
325          write (*,*) "Processor",fg_rank,myrank," setmatrices",
326      &     time_mat
327          write (*,*) "Processor",fg_rank,myrank," ginvmult",
328      &     time_ginvmult
329          write (*,*) "Processor",fg_rank,myrank," fricmatmult",
330      &     time_fricmatmult
331          write (*,*) "Processor",fg_rank,myrank," inttocart",
332      &     time_inttocart
333          write (*,*) "Processor",fg_rank,myrank," sumgradient",
334      &     time_sumgradient
335          write (*,*) "Processor",fg_rank,myrank," intcartderiv",
336      &     time_intcartderiv
337          if (fg_rank.eq.0) then
338            write (*,*) "Processor",fg_rank,myrank," lagrangian",
339      &       time_lagrangian
340            write (*,*) "Processor",fg_rank,myrank," cartgrad",
341      &       time_cartgrad
342          endif
343       return
344       end