Neko  0.8.1
A portable framework for high-order spectral element flow simulations
signal.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 !
34 module signal
35  use utils
36  use, intrinsic :: iso_c_binding
37  implicit none
38 
39  interface
40  integer (c_int8_t) function sighdl_timeout() &
41  bind(c, name='sighdl_timeout')
42  use, intrinsic :: iso_c_binding
43  end function sighdl_timeout
44  end interface
45 
46  interface
47  integer (c_int8_t) function sighdl_usr() &
48  bind(c, name='sighdl_usr')
49  use, intrinsic :: iso_c_binding
50  end function sighdl_usr
51  end interface
52 
53  interface
54  integer (c_int) function sighdl_set_timeout(sec) &
55  bind(c, name='sighdl_set_timeout')
56  use, intrinsic :: iso_c_binding
57  implicit none
58  integer(c_int) :: sec
59  end function sighdl_set_timeout
60  end interface
61 
62  interface
63  integer (c_int) function sighdl_trap_cpulimit() &
64  bind(c, name='sighdl_trap_cpulimit')
65  use, intrinsic :: iso_c_binding
66  end function sighdl_trap_cpulimit
67  end interface
68 
69  interface
70  integer (c_int) function sighdl_trap_usr() &
71  bind(c, name='sighdl_trap_usr')
72  use, intrinsic :: iso_c_binding
73  end function sighdl_trap_usr
74  end interface
75 
76 contains
77 
79  function signal_timeout() result(timeout)
80  logical :: timeout
81 
82  if (sighdl_timeout() .gt. 0) then
83  timeout = .true.
84  else
85  timeout = .false.
86  end if
87 
88  end function signal_timeout
89 
91  function signal_usr(usr) result(raised)
92  integer, intent(in) :: usr
93  logical :: raised
94  integer(kind=c_int8_t) :: usr12
95 
96  if (usr .gt. 2) then
97  call neko_error('Invalid usr signal')
98  end if
99 
100  usr12 = sighdl_usr()
101 
102  if (bge(usr12, usr)) then
103  raised = .true.
104  else
105  raised = .false.
106  end if
107 
108  end function signal_usr
109 
111  subroutine signal_set_timeout(sec)
112  integer(kind=c_int) :: sec
113 
114  if (sighdl_set_timeout(sec) .lt. 0) then
115  call neko_error('sighdl failed to set SIGALRM')
116  end if
117 
118  end subroutine signal_set_timeout
119 
121  subroutine signal_trap_cpulimit()
122  logical, save :: initialized = .false.
123 
124  if (.not. initialized) then
125  if (sighdl_trap_cpulimit() .lt. 0) then
126  call neko_error('sighdl failed to trap SIGXCPU')
127  end if
128  initialized = .true.
129  end if
130 
131  end subroutine signal_trap_cpulimit
132 
134  subroutine signal_trap_usr()
135  logical, save :: initialized = .false.
136 
137  if (.not. initialized) then
138  if (sighdl_trap_usr() .lt. 0) then
139  call neko_error('sighdl failed to trap SIGUSR*')
140  end if
141  initialized = .true.
142  end if
143 
144  end subroutine signal_trap_usr
145 
146 end module signal
Interface to signal handler.
Definition: signal.f90:34
subroutine signal_trap_usr()
Initialize signal handler to trap SIGUSR1 and SIGUSR2.
Definition: signal.f90:135
logical function signal_timeout()
Check if any timeout has occurred (either SIGXCPU or SIGALRM)
Definition: signal.f90:80
subroutine signal_set_timeout(sec)
Set a timeout after seconds.
Definition: signal.f90:112
logical function signal_usr(usr)
Check if a user signal has been raised.
Definition: signal.f90:92
subroutine signal_trap_cpulimit()
Initialize signal handler to trap SIGXCPU.
Definition: signal.f90:122
Utilities.
Definition: utils.f90:35