Neko 1.99.1
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
jobctrl.f90
Go to the documentation of this file.
1! Copyright (c) 2021, The Neko Authors
2! All rights reserved.
3!
4! Redistribution and use in source and binary forms, with or without
5! modification, are permitted provided that the following conditions
6! are met:
7!
8! * Redistributions of source code must retain the above copyright
9! notice, this list of conditions and the following disclaimer.
10!
11! * Redistributions in binary form must reproduce the above
12! copyright notice, this list of conditions and the following
13! disclaimer in the documentation and/or other materials provided
14! with the distribution.
15!
16! * Neither the name of the authors nor the names of its
17! contributors may be used to endorse or promote products derived
18! from this software without specific prior written permission.
19!
20! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31! POSSIBILITY OF SUCH DAMAGE.
32!
34module jobctrl
35 use num_types, only : rp, dp
38 use utils, onlY : neko_error
39 use mpi_f08, only : mpi_bcast, mpi_logical, mpi_wtime
40 use comm
41 use logger
42 implicit none
43 private
44
47 end interface jobctrl_set_time_limit
48
51
52contains
53
55 subroutine jobctrl_init()
56 real(kind=dp) :: jobtime
57
58 ! Start the job clock
59 jobtime = jobctrl_jobtime()
60
61 ! Catch SIGXCPU
63
64 ! Catch SIGUSR1 and SIGUSR2
65 call signal_trap_usr()
66
67 end subroutine jobctrl_init
68
70 subroutine jobctrl_set_time_limit_str(limit_str)
71 character(len=*) limit_str
72 integer :: str_len, sep_h, h, m, s
73
74 str_len = len_trim(limit_str)
75
76 if (str_len .lt. 8) then
77 call neko_error('Invalid job limit')
78 end if
79
80 ! hour
81 sep_h = scan(trim(limit_str), ':')
82 read(limit_str(1:sep_h-1), *) h
83
84 !min
85 read(limit_str(sep_h+1:sep_h+2), *) m
86
87 !sec
88 read(limit_str(sep_h+4:str_len), *) s
89
90 call jobctrl_set_time_limit_sec(h*3600 + m * 60 + s)
91
92 end subroutine jobctrl_set_time_limit_str
93
96 integer :: sec
97 integer :: jstop_sec
98
99 if (sec .gt. 0) then
100 jstop_sec = sec - jobctrl_jobtime()
101 call signal_set_timeout(jstop_sec)
102 end if
103
104 end subroutine jobctrl_set_time_limit_sec
105
107 function jobctrl_time_limit() result(jstop)
108 logical :: jstop
109 integer :: ierr
110 character(len=LOG_SIZE) :: log_buf
111
112 jstop = (signal_timeout() .or. signal_usr(1))
113
114 if (jstop) then
115 ! Todo: This might be a warning instead of a message?
116 write(log_buf, '(A)') '! stop at job limit >>>'
117 call neko_log%message(log_buf, neko_log_quiet)
118 end if
119
120 ! Let rank zero decide if we should stop
121 call mpi_bcast(jstop, 1, mpi_logical, 0, neko_comm, ierr)
122
123 end function jobctrl_time_limit
124
126 function jobctrl_jobtime() result(jobtime)
127 real(kind=rp), save :: stime
128 real(kind=rp) :: jobtime
129 logical, save :: init = .false.
130
131 if (.not. init) then
132 stime = mpi_wtime()
133 init = .true.
134 end if
135
136 jobtime = mpi_wtime() - stime
137 end function jobctrl_jobtime
138
139end module jobctrl
Definition comm.F90:1
type(mpi_comm), public neko_comm
MPI communicator.
Definition comm.F90:42
Job control.
Definition jobctrl.f90:34
subroutine jobctrl_set_time_limit_str(limit_str)
Set a job's time limit (in walltime 'HH:MM:SS')
Definition jobctrl.f90:71
logical function, public jobctrl_time_limit()
Check if the job's time limit has been reached.
Definition jobctrl.f90:108
real(kind=rp) function, public jobctrl_jobtime()
Returns a job's time in seconds relative to the first call.
Definition jobctrl.f90:127
subroutine jobctrl_set_time_limit_sec(sec)
Set a job's time limit (in seconds)
Definition jobctrl.f90:96
subroutine, public jobctrl_init()
Initialize jobctrl.
Definition jobctrl.f90:56
Logging routines.
Definition log.f90:34
integer, parameter, public neko_log_quiet
Always logged.
Definition log.f90:72
type(log_t), public neko_log
Global log stream.
Definition log.f90:70
integer, parameter, public dp
Definition num_types.f90:9
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Interface to signal handler.
Definition signal.f90:34
subroutine, public signal_set_timeout(sec)
Set a timeout after seconds.
Definition signal.f90:116
logical function, public signal_usr(usr)
Check if a user signal has been raised.
Definition signal.f90:96
subroutine, public signal_trap_usr()
Initialize signal handler to trap SIGUSR1 and SIGUSR2.
Definition signal.f90:139
logical function, public signal_timeout()
Check if any timeout has occurred (either SIGXCPU or SIGALRM)
Definition signal.f90:84
subroutine, public signal_trap_cpulimit()
Initialize signal handler to trap SIGXCPU.
Definition signal.f90:126
Utilities.
Definition utils.f90:35