TABLE OF CONTENTS


ABINIT/m_exit [ Modules ]

[ Top ] [ Modules ]

NAME

 m_exit

FUNCTION

COPYRIGHT

  Copyright (C) 2008-2018 ABINIT group (MG, DCA, XG, GMR)
  This file is distributed under the terms of the
  GNU General Public License, see ~abinit/COPYING
  or http://www.gnu.org/copyleft/gpl.txt .

PARENTS

SOURCE

18 #if defined HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21 
22 #include "abi_common.h"
23 
24 MODULE m_exit
25 
26  use defs_basis
27  use m_xmpi
28  use m_abicore
29  use m_errors
30 
31  use m_time,      only : abi_wtime, sec2str, timein
32  use m_fstrings,  only : inupper
33  use m_io_tools,  only : open_file
34 
35  implicit none
36 
37  private

m_exit/disable_timelimit [ Functions ]

[ Top ] [ m_exit ] [ Functions ]

NAME

 disable_timelimit

FUNCTION

  Disable the time limit handler. This function should be called by a driver
  routine that is not able to handle time limit events and wants to prevent
  its children from installing their handlers.

PARENTS

      dfpt_looppert

CHILDREN

      inupper,timein,wrtout,xmpi_bcast

SOURCE

129 subroutine disable_timelimit()
130 
131 
132 !This section has been created automatically by the script Abilint (TD).
133 !Do not modify the following lines by hand.
134 #undef ABI_FUNC
135 #define ABI_FUNC 'disable_timelimit'
136 !End of the abilint section
137 
138  implicit none
139 
140 !This section has been created automatically by the script Abilint (TD).
141 !Do not modify the following lines by hand.
142 #undef ABI_FUNC
143 #define ABI_FUNC 'disable_timelimit'
144 !End of the abilint section
145 
146 !Local variables-------------------------------
147 !scalars
148  character(len=500) :: msg
149 
150 ! *************************************************************************
151 
152  WTIME_LIMIT = -one
153 
154  if (TIMELIMIT_INABIFUNC /= "__None__") then
155    msg = "Timelimit is already activated in function: "//trim(TIMELIMIT_INABIFUNC)
156    MSG_WARNING(msg)
157    !MSG_ERROR(msg)
158  end if
159 
160 end subroutine disable_timelimit

m_exit/enable_timelimit_in [ Functions ]

[ Top ] [ m_exit ] [ Functions ]

NAME

 enable_timelimit_in

FUNCTION

  Eable time limit handler in the given function if not already done in one of the callers.
  Return the name of procedure that is handling the time limit.
  Example:

    ! enable time limit handler if not done in callers.
    if (enable_timelimit_in(ABI_FUNC) == ABI_FUNC) then
      write(std_out,*)"Enabling timelimit check in function: ",trim(ABI_FUNC)," with timelimit: ",trim(sec2str(get_timelimit()))
    end if

PARENTS

SOURCE

224 function enable_timelimit_in(abifunc) result(prev_func)
225 
226 
227 !This section has been created automatically by the script Abilint (TD).
228 !Do not modify the following lines by hand.
229 #undef ABI_FUNC
230 #define ABI_FUNC 'enable_timelimit_in'
231 !End of the abilint section
232 
233  implicit none
234 
235 !This section has been created automatically by the script Abilint (TD).
236 !Do not modify the following lines by hand.
237 #undef ABI_FUNC
238 #define ABI_FUNC 'enable_timelimit_in'
239 !End of the abilint section
240 
241 !Arguments -----------------------------------
242  character(len=*),intent(in) :: abifunc
243  character(len=fnlen) :: prev_func
244 
245 ! *************************************************************************
246 
247  if (WTIME_LIMIT > zero .and. TIMELIMIT_INABIFUNC == "__None__") TIMELIMIT_INABIFUNC = abifunc
248  prev_func = TIMELIMIT_INABIFUNC
249 
250 end function enable_timelimit_in

m_exit/exit_check [ Functions ]

[ Top ] [ m_exit ] [ Functions ]

NAME

 exit_check

FUNCTION

 This routine checks whether the CPU time limit is exceeded or not.
 If openexit is non-zero, it also checks the "filename" file
 for the "exit" character string in its first line and returns the location
 of the string on the line (0 if not found).  Maps both strings to upper case
 before attempting to match them. Also checks for the existence
 of the "abinit.exit" file in the directory where the job was started.
 Finally, checks whether the CPU time limit was not exceeded.
 If one of these conditions occurs, will induce graceful exit of iterations.

INPUTS

  cpus = CPU time limit
  filename = character string giving name of file to be opened
  iout = unit number to print output to
  openexit = if 1, open the "filename" and "abinit.exit" files
  comm=MPI communicator.

OUTPUT

  iexit = index of "exit" on first line of file (0 if not found),
      or -1 if the exit was ordered through the existence of the "exit" file
      or -2 if the exit was ordered through the CPU time limit.

PARENTS

      dfpt_looppert,driver,gstate,respfn,scprqt

CHILDREN

      inupper,timein,wrtout,xmpi_bcast

SOURCE

395 subroutine exit_check(cpus,filename,iexit,iout,comm,openexit)
396 
397 
398 !This section has been created automatically by the script Abilint (TD).
399 !Do not modify the following lines by hand.
400 #undef ABI_FUNC
401 #define ABI_FUNC 'exit_check'
402 !End of the abilint section
403 
404  implicit none
405 
406 !Arguments ------------------------------------
407  integer,intent(in) :: comm
408  real(dp),intent(in) :: cpus
409  character(len=*),intent(in) :: filename
410  integer,intent(in) :: openexit,iout
411  integer,intent(out) :: iexit
412 
413 !Local variables-------------------------------
414 !scalars
415  integer,parameter :: master=0
416  integer,save :: iexit_save=0
417  integer :: ierr,temp_unit,ierrmpi
418  logical :: ex
419  real(dp),save :: tcpu_last=zero
420  character(len=500) :: message
421  character(len=fnlen) :: line
422  character(len=4), parameter :: string='EXIT'
423 !arrays
424  real(dp) :: tsec(2)
425 
426 ! *************************************************************************
427 
428  if (iexit_save==0) then
429    ! ABINIT will pass again in this routine even after exit call has been detected
430 
431    if (xmpi_comm_rank(comm)==master) then
432      ! Master tests and broadcast the result to others
433      iexit=0
434 
435      ! Is it worth to test the cpu time ?
436      if (abs(cpus)>1.0d-5 .or. openexit==1) then
437        call timein(tsec(1),tsec(2))
438      end if
439 
440      ! A first way of exiting: the cpu time limit
441      if (abs(cpus)>1.0d-5) then
442        if(cpus<tsec(1))iexit=-2
443      end if
444 
445      ! Test the content of files only when sufficient time (2 sec) has elapsed from last time it was tested.
446      if (openexit==1 .and. iexit==0 .and. tsec(1)-tcpu_last>two ) then
447        ! TODO Remove this approach. Use abinit.exit!
448        tcpu_last=tsec(1)
449        ! Open file and read first line as character string
450        if (open_file(filename,message,newunit=temp_unit,form='formatted',status='old') /= 0) then
451          MSG_ERROR(message)
452        end if
453        rewind (unit=temp_unit)
454        read (unit=temp_unit,fmt='(a)',iostat=ierr) line
455        if(ierr/=0)then
456          write(message, '(a,a,a,i5,a,a)' )&
457 &         'Problem when reading file=',TRIM(filename),'iostat =',ierr,ch10,&
458 &         'Action: check whether this file is OK.'
459          MSG_ERROR(message)
460        end if
461        ! Make a local copy of matching string of length equal to nonblank length of input string
462        ! Map to upper case
463        call inupper(line)
464        iexit=index(line,string)
465        close (unit=temp_unit)
466 
467        ! This is another way of exiting : the previous one does not work
468        ! on some machines, may be because they keep a copy of the initial input file.
469        if(iexit==0)then
470          inquire(file='abinit.exit',exist=ex)
471          if(ex)iexit=-1
472        end if
473 
474      end if
475    end if
476 
477    call xmpi_bcast(iexit,master,comm,ierrmpi)
478 
479  else
480    ! In case the exit mechanism has already been activated
481    iexit=iexit_save
482  end if
483 
484  if (iexit/=0) then
485    if (iexit>0) write(message, '(a,a,a,a,a,a,a)' ) ch10,&
486 &   ' chkexi: WARNING -',ch10,&
487 &   '  Exit has been requested from file ',trim(filename),'.',ch10
488    if (iexit==-1) write(message, '(a,a,a,a,a)' ) ch10,&
489 &   ' chkexi: WARNING -',ch10,&
490 &   '  Exit has been requested from file "abinit.exit".',ch10
491    if (iexit==-2) write(message, '(a,a,a,a,a)' ) ch10,&
492 &   ' chkexi: WARNING -',ch10,&
493 &   '  Exit due to cpu time limit exceeded.',ch10
494    if (iout/=std_out) then
495      call wrtout(iout,message,'COLL')
496    end if
497    call wrtout(std_out,  message,'COLL')
498  end if
499 
500  iexit_save=iexit
501 
502 end subroutine exit_check

m_exit/exit_init [ Functions ]

[ Top ] [ m_exit ] [ Functions ]

NAME

 exit_init

FUNCTION

  Initialize the global variables of the modules.
  This is a collective function that should be called by all the nodes in COMM_WORLD

INPUTS

PARENTS

      m_argparse

CHILDREN

      inupper,timein,wrtout,xmpi_bcast

SOURCE

 88 subroutine exit_init(time_limit)
 89 
 90 
 91 !This section has been created automatically by the script Abilint (TD).
 92 !Do not modify the following lines by hand.
 93 #undef ABI_FUNC
 94 #define ABI_FUNC 'exit_init'
 95 !End of the abilint section
 96 
 97  implicit none
 98 
 99 !Arguments ------------------------------------
100  real(dp),intent(in) :: time_limit
101 
102 ! *************************************************************************
103 
104  WTIME_LIMIT = time_limit
105  WALL0 = abi_wtime()
106 
107 end subroutine exit_init

m_exit/get_start_time [ Functions ]

[ Top ] [ m_exit ] [ Functions ]

NAME

 get_start_time

FUNCTION

  Return the origin of execution time in seconds

PARENTS

SOURCE

347 real(dp) pure function get_start_time()
348 
349 
350 !This section has been created automatically by the script Abilint (TD).
351 !Do not modify the following lines by hand.
352 #undef ABI_FUNC
353 #define ABI_FUNC 'get_start_time'
354 !End of the abilint section
355 
356  get_start_time = WALL0
357 
358 end function get_start_time

m_exit/get_timelimit [ Functions ]

[ Top ] [ m_exit ] [ Functions ]

NAME

 get_timelimit

FUNCTION

  Return the time limit in seconds

PARENTS

SOURCE

266 real(dp) pure function get_timelimit()
267 
268 
269 !This section has been created automatically by the script Abilint (TD).
270 !Do not modify the following lines by hand.
271 #undef ABI_FUNC
272 #define ABI_FUNC 'get_timelimit'
273 !End of the abilint section
274 
275  implicit none
276 
277 !This section has been created automatically by the script Abilint (TD).
278 !Do not modify the following lines by hand.
279 #undef ABI_FUNC
280 #define ABI_FUNC 'get_timelimit'
281 !End of the abilint section
282 
283  get_timelimit = WTIME_LIMIT
284 
285 end function get_timelimit

m_exit/get_timelimit_string [ Functions ]

[ Top ] [ m_exit ] [ Functions ]

NAME

 get_timelimit_string

FUNCTION

  Return the time limit in string form.

PARENTS

SOURCE

301 pure function get_timelimit_string() result(string)
302 
303 
304 !This section has been created automatically by the script Abilint (TD).
305 !Do not modify the following lines by hand.
306 #undef ABI_FUNC
307 #define ABI_FUNC 'get_timelimit_string'
308 !End of the abilint section
309 
310  implicit none
311 
312 !This section has been created automatically by the script Abilint (TD).
313 !Do not modify the following lines by hand.
314 #undef ABI_FUNC
315 #define ABI_FUNC 'get_timelimit'
316 !End of the abilint section
317 
318 !Local variables-------------------------------
319 !scalars
320  real(dp) :: timelimit
321  character(len=500) :: string
322 
323 ! *************************************************************************
324 
325  ! Handle negative values
326  timelimit = get_timelimit()
327  if (timelimit > zero) then
328    string = sec2str(timelimit)
329  else
330    string = "0"
331  end if
332 
333 end function get_timelimit_string

m_exit/have_timelimit_in [ Functions ]

[ Top ] [ m_exit ] [ Functions ]

NAME

 have_timelimit_in

FUNCTION

  Return .True. if timelimit is enabled in this caller

PARENTS

SOURCE

176 logical pure function have_timelimit_in(abifunc) result(ans)
177 
178 
179 !This section has been created automatically by the script Abilint (TD).
180 !Do not modify the following lines by hand.
181 #undef ABI_FUNC
182 #define ABI_FUNC 'have_timelimit_in'
183 !End of the abilint section
184 
185  implicit none
186 
187 !This section has been created automatically by the script Abilint (TD).
188 !Do not modify the following lines by hand.
189 #undef ABI_FUNC
190 #define ABI_FUNC 'have_timelimit_in'
191 !End of the abilint section
192 
193 !Arguments -----------------------------------
194 
195  character(len=*),intent(in) :: abifunc
196 
197 ! *************************************************************************
198 
199  ans = WTIME_LIMIT > zero .and. abifunc == TIMELIMIT_INABIFUNC
200 
201 end function have_timelimit_in