Merge branch 'sigint-to-quit' into 'development'

better use SIGINT for actions triggered by the user

See merge request damask/DAMASK!581
This commit is contained in:
Vitesh 2022-05-14 17:00:42 +00:00
commit c9d7cf405c
5 changed files with 21 additions and 24 deletions

@ -1 +1 @@
Subproject commit ede67b6488f0a0a116fe5aa8b36980d11e0f29e7
Subproject commit df33ba9a1360439c5c18a241a1e439dab0cdcafd

View File

@ -58,8 +58,8 @@ void getusername_c(char username[], int *stat){
}
void signalterm_c(void (*handler)(int)){
signal(SIGTERM, handler);
void signalint_c(void (*handler)(int)){
signal(SIGINT, handler);
}
void signalusr1_c(void (*handler)(int)){

View File

@ -471,7 +471,7 @@ program DAMASK_grid
call materialpoint_restartWrite
endif
if (signal) call signals_setSIGUSR2(.false.)
call MPI_Allreduce(signals_SIGTERM,signal,1_MPI_INTEGER_KIND,MPI_LOGICAL,MPI_LOR,MPI_COMM_WORLD,err_MPI)
call MPI_Allreduce(signals_SIGINT,signal,1_MPI_INTEGER_KIND,MPI_LOGICAL,MPI_LOR,MPI_COMM_WORLD,err_MPI)
if (err_MPI /= 0_MPI_INTEGER_KIND) error stop 'MPI error'
if (signal) exit loadCaseLooping
endif skipping

View File

@ -10,13 +10,13 @@ module signals
private
logical, volatile, public, protected :: &
signals_SIGTERM, & !< termination signal
signals_SIGUSR1, & !< 1. user-defined signal
signals_SIGUSR2 !< 2. user-defined signal
signals_SIGINT = .false., & !< interrupt signal
signals_SIGUSR1 = .false., & !< 1. user-defined signal
signals_SIGUSR2 = .false. !< 2. user-defined signal
public :: &
signals_init, &
signals_setSIGTERM, &
signals_setSIGINT, &
signals_setSIGUSR1, &
signals_setSIGUSR2
@ -28,29 +28,26 @@ contains
!--------------------------------------------------------------------------------------------------
subroutine signals_init()
call signalterm_c(c_funloc(catchSIGTERM))
call signalint_c(c_funloc(catchSIGINT))
call signalusr1_c(c_funloc(catchSIGUSR1))
call signalusr2_c(c_funloc(catchSIGUSR2))
call signals_setSIGTERM(.false.)
call signals_setSIGUSR1(.false.)
call signals_setSIGUSR2(.false.)
end subroutine signals_init
!--------------------------------------------------------------------------------------------------
!> @brief Set global variable signals_SIGTERM to .true.
!> @brief Set global variable signals_SIGINT to .true.
!> @details This function can be registered to catch signals send to the executable.
!--------------------------------------------------------------------------------------------------
subroutine catchSIGTERM(signal) bind(C)
subroutine catchSIGINT(signal) bind(C)
integer(C_INT), value :: signal
print'(a,i0)', ' received signal ',signal
call signals_setSIGTERM(.true.)
call signals_setSIGINT(.true.)
end subroutine catchSIGTERM
end subroutine catchSIGINT
!--------------------------------------------------------------------------------------------------
@ -84,17 +81,17 @@ end subroutine catchSIGUSR2
!--------------------------------------------------------------------------------------------------
!> @brief Set global variable signals_SIGTERM.
!> @brief Set global variable signals_SIGINT.
!--------------------------------------------------------------------------------------------------
subroutine signals_setSIGTERM(state)
subroutine signals_setSIGINT(state)
logical, intent(in) :: state
signals_SIGTERM = state
print*, 'set SIGTERM to',state
signals_SIGINT = state
print*, 'set SIGINT to',state
end subroutine signals_setSIGTERM
end subroutine signals_setSIGINT
!--------------------------------------------------------------------------------------------------

View File

@ -15,7 +15,7 @@ module system_routines
getCWD, &
getHostName, &
getUserName, &
signalterm_C, &
signalint_C, &
signalusr1_C, &
signalusr2_C, &
f_c_string, &
@ -55,11 +55,11 @@ module system_routines
integer(C_INT), intent(out) :: stat
end subroutine getUserName_C
subroutine signalterm_C(handler) bind(C)
subroutine signalint_C(handler) bind(C)
use, intrinsic :: ISO_C_Binding, only: C_FUNPTR
type(C_FUNPTR), intent(in), value :: handler
end subroutine signalterm_C
end subroutine signalint_C
subroutine signalusr1_C(handler) bind(C)
use, intrinsic :: ISO_C_Binding, only: C_FUNPTR