Neko 1.99.3
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-2025, 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, read_duration
39 use mpi_f08, only : mpi_bcast, mpi_logical, mpi_wtime
40 use comm, only : neko_comm
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=*), intent(in) :: limit_str
72 real(kind=rp) :: limit_sec
73 integer :: ierr
74
75 limit_sec = 0.0_rp
76 call read_duration(limit_str, limit_sec)
77 call jobctrl_set_time_limit_sec(int(limit_sec))
78
79 end subroutine jobctrl_set_time_limit_str
80
83 integer :: sec
84 integer :: jstop_sec
85
86 if (sec .gt. 0) then
87 jstop_sec = sec - jobctrl_jobtime()
88 call signal_set_timeout(jstop_sec)
89 end if
90
91 end subroutine jobctrl_set_time_limit_sec
92
94 function jobctrl_time_limit() result(jstop)
95 logical :: jstop
96 integer :: ierr
97 character(len=LOG_SIZE) :: log_buf
98
99 jstop = (signal_timeout() .or. signal_usr(1))
100
101 if (jstop) then
102 ! Todo: This might be a warning instead of a message?
103 write(log_buf, '(A)') '! stop at job limit >>>'
104 call neko_log%message(log_buf, neko_log_quiet)
105 end if
106
107 ! Let rank zero decide if we should stop
108 call mpi_bcast(jstop, 1, mpi_logical, 0, neko_comm, ierr)
109
110 end function jobctrl_time_limit
111
113 function jobctrl_jobtime() result(jobtime)
114 real(kind=rp), save :: stime
115 real(kind=rp) :: jobtime
116 logical, save :: init = .false.
117
118 if (.not. init) then
119 stime = mpi_wtime()
120 init = .true.
121 end if
122
123 jobtime = mpi_wtime() - stime
124 end function jobctrl_jobtime
125
126end module jobctrl
Definition comm.F90:1
type(mpi_comm), public neko_comm
MPI communicator.
Definition comm.F90:45
Job control.
Definition jobctrl.f90:34
subroutine jobctrl_set_time_limit_str(limit_str)
Set a job's time limit from a duration string.
Definition jobctrl.f90:71
logical function, public jobctrl_time_limit()
Check if the job's time limit has been reached.
Definition jobctrl.f90:95
real(kind=rp) function, public jobctrl_jobtime()
Returns a job's time in seconds relative to the first call.
Definition jobctrl.f90:114
subroutine jobctrl_set_time_limit_sec(sec)
Set a job's time limit (in seconds)
Definition jobctrl.f90:83
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:82
type(log_t), public neko_log
Global log stream.
Definition log.f90:80
integer, parameter, public log_size
Definition log.f90:46
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