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