2010-10-06 23:03:47 -03:00
|
|
|
!!******************************************************************************
|
2008-11-04 13:08:01 -06:00
|
|
|
!!
|
2012-07-22 12:30:20 -03:00
|
|
|
!! This file is part of the AMUN source code, a program to perform
|
|
|
|
!! Newtonian or relativistic magnetohydrodynamical simulations on uniform or
|
|
|
|
!! adaptive mesh.
|
2008-11-04 13:08:01 -06:00
|
|
|
!!
|
2024-03-07 09:34:43 -03:00
|
|
|
!! Copyright (C) 2008-2024 Grzegorz Kowal <grzegorz@amuncode.org>
|
2008-11-04 13:08:01 -06:00
|
|
|
!!
|
2012-07-22 12:30:20 -03:00
|
|
|
!! This program is free software: you can redistribute it and/or modify
|
|
|
|
!! it under the terms of the GNU General Public License as published by
|
|
|
|
!! the Free Software Foundation, either version 3 of the License, or
|
|
|
|
!! (at your option) any later version.
|
2008-11-04 13:08:01 -06:00
|
|
|
!!
|
2011-04-29 11:21:30 -03:00
|
|
|
!! This program is distributed in the hope that it will be useful,
|
2008-11-04 13:08:01 -06:00
|
|
|
!! but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
!! GNU General Public License for more details.
|
|
|
|
!!
|
|
|
|
!! You should have received a copy of the GNU General Public License
|
2012-07-22 12:30:20 -03:00
|
|
|
!! along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-11-04 13:08:01 -06:00
|
|
|
!!
|
2010-10-06 23:03:47 -03:00
|
|
|
!!******************************************************************************
|
2008-11-04 13:08:01 -06:00
|
|
|
!!
|
2012-07-22 12:30:20 -03:00
|
|
|
!! program: AMUN
|
|
|
|
!!
|
2012-07-28 12:24:12 -03:00
|
|
|
!! AMUN is a code to perform numerical simulations in a fluid approximation on
|
|
|
|
!! adaptive mesh for Newtonian and relativistic environments with or without
|
|
|
|
!! magnetic field.
|
|
|
|
!!
|
2012-07-22 12:30:20 -03:00
|
|
|
!!******************************************************************************
|
2008-11-04 13:08:01 -06:00
|
|
|
!
|
2011-04-25 13:44:34 -03:00
|
|
|
program amun
|
2008-11-04 13:08:01 -06:00
|
|
|
|
2021-11-18 17:36:18 -03:00
|
|
|
use helpers , only : print_welcome, print_section, print_parameter
|
|
|
|
use helpers , only : print_message
|
|
|
|
use io , only : initialize_io, finalize_io
|
|
|
|
use mpitools , only : initialize_mpitools, finalize_mpitools
|
2021-12-03 10:55:46 -03:00
|
|
|
use mpitools , only : verbose => master, nproc, check_status
|
2012-07-22 19:01:27 -03:00
|
|
|
#ifdef MPI
|
2024-07-30 22:24:24 -03:00
|
|
|
use mpitools , only : reduce_sum, nodes, nprocs
|
2012-07-22 19:01:27 -03:00
|
|
|
#endif /* MPI */
|
2021-11-18 17:36:18 -03:00
|
|
|
use parameters, only : read_parameters, finalize_parameters
|
|
|
|
use random , only : initialize_random, finalize_random
|
|
|
|
use system , only : initialize_system, finalize_system
|
2021-11-18 17:54:26 -03:00
|
|
|
use system , only : print_system_info, prepare_system, evolve_system
|
2021-12-03 10:43:07 -03:00
|
|
|
use system , only : nsteps, nwork
|
|
|
|
#ifdef SIGNALS
|
|
|
|
use system , only : quit
|
|
|
|
#endif /* SIGNALS */
|
2021-11-18 17:36:18 -03:00
|
|
|
use timers , only : initialize_timers, finalize_timers
|
|
|
|
use timers , only : start_timer, stop_timer, set_timer, get_timer
|
|
|
|
use timers , only : get_timer_total, timer_enabled, timer_description
|
|
|
|
use timers , only : get_count, ntimers
|
|
|
|
use workspace , only : initialize_workspace, finalize_workspace
|
2012-07-28 12:24:12 -03:00
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
2021-11-18 17:36:18 -03:00
|
|
|
! the timings printing and execution status flags
|
2019-02-08 09:56:03 -02:00
|
|
|
!
|
2021-11-18 17:18:58 -03:00
|
|
|
logical :: timings = .false.
|
2021-11-16 22:39:30 -03:00
|
|
|
integer :: status = 0
|
2019-02-08 09:56:03 -02:00
|
|
|
|
2021-11-17 12:49:35 -03:00
|
|
|
! timer indices, iteration number and other time variables
|
2012-07-22 15:46:56 -03:00
|
|
|
!
|
2021-11-18 17:36:18 -03:00
|
|
|
integer :: iin, iev, itm
|
|
|
|
integer :: ed, eh, em, es
|
2012-07-28 13:48:15 -03:00
|
|
|
|
2021-12-07 10:37:56 -03:00
|
|
|
! OpenMP
|
|
|
|
!
|
|
|
|
integer :: nthreads = 1
|
|
|
|
!$ integer :: omp_get_num_threads
|
|
|
|
|
2021-11-17 12:49:35 -03:00
|
|
|
! the format string
|
2012-07-28 13:48:15 -03:00
|
|
|
!
|
2021-11-17 12:49:35 -03:00
|
|
|
character(len=80) :: sfmt
|
2012-07-22 15:46:56 -03:00
|
|
|
|
2021-11-17 12:49:35 -03:00
|
|
|
! an array pointer for timings
|
|
|
|
!
|
|
|
|
real(kind=8), dimension(:), allocatable :: tm
|
|
|
|
|
2020-07-30 11:49:43 -03:00
|
|
|
#ifndef __GFORTRAN__
|
2021-11-17 12:49:35 -03:00
|
|
|
! signal is a subroutine only for the GNU compiler, otherwise it is a function
|
2012-07-28 12:24:12 -03:00
|
|
|
!
|
2021-11-17 12:49:35 -03:00
|
|
|
integer(kind=4) :: signal
|
2020-07-30 11:49:43 -03:00
|
|
|
#endif /* __GFORTRAN__ */
|
2012-07-28 12:24:12 -03:00
|
|
|
|
2011-05-06 09:51:40 -03:00
|
|
|
#ifdef SIGNALS
|
2020-07-30 11:06:59 -03:00
|
|
|
#ifdef __GFORTRAN__
|
2011-04-29 00:51:28 -03:00
|
|
|
intrinsic signal
|
2020-07-30 11:06:59 -03:00
|
|
|
#endif /* __GFORTRAN__ */
|
2011-04-29 00:51:28 -03:00
|
|
|
|
2021-11-16 22:39:30 -03:00
|
|
|
integer, parameter :: SIGERR = -1
|
|
|
|
integer, parameter :: SIGINT = 2, SIGABRT = 6, SIGTERM = 15
|
2011-04-29 00:51:28 -03:00
|
|
|
#endif /* SIGNALS */
|
2012-07-28 12:03:17 -03:00
|
|
|
|
2021-11-17 11:57:38 -03:00
|
|
|
character(len=*), parameter :: loc = 'AMUN::amun()'
|
|
|
|
|
2008-12-08 21:11:17 -06:00
|
|
|
!-------------------------------------------------------------------------------
|
2008-11-04 21:00:50 -06:00
|
|
|
!
|
2011-04-29 00:51:28 -03:00
|
|
|
#ifdef SIGNALS
|
2021-11-16 22:39:30 -03:00
|
|
|
! signals handling
|
2020-07-30 11:06:59 -03:00
|
|
|
!
|
|
|
|
#ifdef __GFORTRAN__
|
|
|
|
if (signal(SIGINT , signal_handler) == SIGERR) status = 1
|
|
|
|
if (signal(SIGABRT, signal_handler) == SIGERR) status = 2
|
|
|
|
if (signal(SIGTERM, signal_handler) == SIGERR) status = 3
|
|
|
|
#else /* __GFORTRAN__ */
|
|
|
|
if (signal(SIGINT , signal_handler, -1) == SIGERR) status = 1
|
|
|
|
if (signal(SIGABRT, signal_handler, -1) == SIGERR) status = 2
|
|
|
|
if (signal(SIGTERM, signal_handler, -1) == SIGERR) status = 3
|
|
|
|
#endif /* __GFORTRAN__ */
|
2014-12-24 15:04:24 -02:00
|
|
|
|
2019-02-12 13:56:59 -02:00
|
|
|
if (status /= 0) then
|
2021-11-18 17:36:18 -03:00
|
|
|
call print_message(loc, "Could not initialize the signal handling!")
|
2021-11-16 22:39:30 -03:00
|
|
|
call exit(status)
|
2019-01-28 15:30:52 -02:00
|
|
|
end if
|
2011-04-29 00:51:28 -03:00
|
|
|
#endif /* SIGNALS */
|
2011-06-17 20:21:10 -03:00
|
|
|
|
2021-11-16 22:39:30 -03:00
|
|
|
! timers
|
2008-12-22 14:57:31 -06:00
|
|
|
!
|
2021-11-16 22:39:30 -03:00
|
|
|
call initialize_timers()
|
2019-01-28 15:30:52 -02:00
|
|
|
|
2021-11-16 22:39:30 -03:00
|
|
|
call set_timer('INITIALIZATION', iin)
|
|
|
|
call set_timer('EVOLUTION' , iev)
|
|
|
|
call set_timer('TERMINATION' , itm)
|
2019-02-08 09:56:03 -02:00
|
|
|
|
2021-11-16 22:39:30 -03:00
|
|
|
! parallelization
|
2019-02-08 09:56:03 -02:00
|
|
|
!
|
2021-11-16 22:39:30 -03:00
|
|
|
call initialize_mpitools(status)
|
2021-11-18 17:36:18 -03:00
|
|
|
if (status /= 0) &
|
|
|
|
call print_message(loc, "Could not initialize module MPITOOLS!")
|
2021-11-16 22:39:30 -03:00
|
|
|
if (check_status(status /= 0)) call exit(status)
|
2019-02-08 09:56:03 -02:00
|
|
|
|
|
|
|
call start_timer(iin)
|
2008-12-22 14:57:31 -06:00
|
|
|
|
2021-11-16 22:39:30 -03:00
|
|
|
call print_welcome(verbose)
|
2019-01-28 15:03:19 -02:00
|
|
|
#ifdef MPI
|
2021-11-16 22:39:30 -03:00
|
|
|
call print_section(verbose, "Parallelization")
|
2024-07-30 22:24:24 -03:00
|
|
|
call print_parameter(verbose, "MPI nodes" , nodes)
|
|
|
|
call print_parameter(verbose, "MPI processes per node" , nprocs / nodes)
|
2021-12-07 10:37:56 -03:00
|
|
|
#else /* MPI */
|
|
|
|
!$ call print_section(verbose, "Parallelization")
|
2019-01-28 15:03:19 -02:00
|
|
|
#endif /* MPI */
|
2021-12-07 10:37:56 -03:00
|
|
|
!$omp parallel
|
|
|
|
!$omp master
|
|
|
|
!$ nthreads = omp_get_num_threads()
|
2024-07-30 22:24:24 -03:00
|
|
|
#ifdef MPI
|
|
|
|
!$ call print_parameter(verbose, "OpenMP threads per process", nthreads)
|
|
|
|
#else /* MPI */
|
2021-12-07 10:37:56 -03:00
|
|
|
!$ call print_parameter(verbose, "OpenMP threads", nthreads)
|
2024-07-30 22:24:24 -03:00
|
|
|
#endif /* MPI */
|
2021-12-07 10:37:56 -03:00
|
|
|
!$omp end master
|
|
|
|
!$omp end parallel
|
2019-01-28 15:45:35 -02:00
|
|
|
|
2021-11-16 22:39:30 -03:00
|
|
|
! read parameters
|
2012-07-22 19:32:21 -03:00
|
|
|
!
|
2021-11-16 22:39:30 -03:00
|
|
|
call read_parameters(verbose, status)
|
2021-11-18 17:36:18 -03:00
|
|
|
if (status /= 0) &
|
|
|
|
call print_message(loc, "Could not read parameters!")
|
2021-11-17 11:47:09 -03:00
|
|
|
if (check_status(status /= 0)) go to 6000
|
2012-07-22 19:32:21 -03:00
|
|
|
|
2021-11-25 11:48:45 -03:00
|
|
|
! initialize a few basic modules: IO, RANDOM, SYSTEM, and WORKSPACE
|
2021-11-16 22:39:30 -03:00
|
|
|
!
|
|
|
|
call initialize_io(verbose, status)
|
2021-11-18 17:36:18 -03:00
|
|
|
if (status /= 0) &
|
|
|
|
call print_message(loc, "Could not initialize module IO!")
|
2021-11-17 11:47:09 -03:00
|
|
|
if (check_status(status /= 0)) go to 5000
|
2012-07-22 19:32:21 -03:00
|
|
|
|
2021-11-25 11:48:45 -03:00
|
|
|
call initialize_random("same", 1, 0, nproc, status)
|
2021-11-18 17:36:18 -03:00
|
|
|
if (status /= 0) &
|
2021-11-25 11:48:45 -03:00
|
|
|
call print_message(loc, "Could not initialize module RANDOM!")
|
2021-11-17 11:47:09 -03:00
|
|
|
if (check_status(status /= 0)) go to 4000
|
2021-11-17 09:19:23 -03:00
|
|
|
|
2021-11-25 11:48:45 -03:00
|
|
|
call initialize_system(verbose, status)
|
2021-11-18 17:36:18 -03:00
|
|
|
if (status /= 0) &
|
2021-11-25 11:48:45 -03:00
|
|
|
call print_message(loc, "Could not initialize module SYSTEM!")
|
2021-11-17 11:47:09 -03:00
|
|
|
if (check_status(status /= 0)) go to 3000
|
2021-11-17 10:50:51 -03:00
|
|
|
|
2021-12-07 10:46:18 -03:00
|
|
|
call initialize_workspace(nwork, nthreads, status)
|
2021-11-18 17:36:18 -03:00
|
|
|
if (status /= 0) &
|
|
|
|
call print_message(loc, "Could not initialize module WORKSPACE!")
|
2021-11-17 11:47:09 -03:00
|
|
|
if (check_status(status /= 0)) go to 2000
|
2021-11-17 11:22:54 -03:00
|
|
|
|
2021-11-17 11:57:38 -03:00
|
|
|
! show some info before the simulation starts
|
2014-01-08 18:07:54 -02:00
|
|
|
!
|
2021-11-18 16:48:29 -03:00
|
|
|
call print_system_info(verbose)
|
2012-08-02 00:35:37 -03:00
|
|
|
|
2021-11-18 16:48:29 -03:00
|
|
|
! prepare the system
|
2011-04-11 16:27:08 +02:00
|
|
|
!
|
2021-11-18 16:48:29 -03:00
|
|
|
call prepare_system(status)
|
2021-11-18 17:36:18 -03:00
|
|
|
if (status /= 0) &
|
|
|
|
call print_message(loc, "Could not prepare the system for integration!")
|
2021-11-18 13:20:43 -03:00
|
|
|
if (check_status(status /= 0)) go to 1000
|
2012-07-28 13:48:15 -03:00
|
|
|
|
2012-07-22 15:46:56 -03:00
|
|
|
call stop_timer(iin)
|
|
|
|
|
2021-11-18 17:18:58 -03:00
|
|
|
timings = .true.
|
2019-02-08 09:56:03 -02:00
|
|
|
|
2021-11-18 17:36:18 -03:00
|
|
|
! the system evolution
|
2012-07-22 15:46:56 -03:00
|
|
|
!
|
|
|
|
call start_timer(iev)
|
2011-05-02 23:43:58 -03:00
|
|
|
|
2021-11-18 16:48:29 -03:00
|
|
|
call evolve_system(verbose, status)
|
2021-11-18 17:36:18 -03:00
|
|
|
if (status /= 0) &
|
|
|
|
call print_message(loc, "Could not integrate the system!")
|
2021-11-18 14:29:06 -03:00
|
|
|
if (check_status(status /= 0)) go to 1000
|
2011-02-27 22:39:56 -03:00
|
|
|
|
2012-07-22 15:46:56 -03:00
|
|
|
call stop_timer(iev)
|
|
|
|
|
2021-11-17 11:47:09 -03:00
|
|
|
1000 continue
|
|
|
|
call start_timer(itm)
|
2021-11-17 11:57:38 -03:00
|
|
|
|
2021-11-18 17:36:18 -03:00
|
|
|
! finalize all initialized modules
|
2021-11-17 11:57:38 -03:00
|
|
|
!
|
2021-11-12 22:26:50 -03:00
|
|
|
call finalize_workspace(status)
|
2021-11-18 17:36:18 -03:00
|
|
|
if (status /= 0) &
|
|
|
|
call print_message(loc, "Could not finalize module WORKSPACE!")
|
2021-11-17 11:47:09 -03:00
|
|
|
2000 continue
|
2021-11-17 11:57:38 -03:00
|
|
|
|
2021-11-25 11:48:45 -03:00
|
|
|
call finalize_system(verbose, status)
|
2021-11-18 17:36:18 -03:00
|
|
|
if (status /= 0) &
|
2021-11-25 11:48:45 -03:00
|
|
|
call print_message(loc, "Could not finalize module SYSTEM!")
|
2021-11-17 11:47:09 -03:00
|
|
|
3000 continue
|
2021-11-17 11:57:38 -03:00
|
|
|
|
2021-11-25 11:48:45 -03:00
|
|
|
call finalize_random(status)
|
2021-11-18 17:36:18 -03:00
|
|
|
if (status /= 0) &
|
2021-11-25 11:48:45 -03:00
|
|
|
call print_message(loc, "Could not finalize module RANDOM!")
|
2021-11-17 11:47:09 -03:00
|
|
|
4000 continue
|
2021-11-17 11:57:38 -03:00
|
|
|
|
2019-02-12 13:56:59 -02:00
|
|
|
call finalize_io(status)
|
2021-11-18 17:36:18 -03:00
|
|
|
if (status /= 0) &
|
|
|
|
call print_message(loc, "Could not finalize module IO!")
|
2021-11-17 11:47:09 -03:00
|
|
|
5000 continue
|
2021-11-17 11:57:38 -03:00
|
|
|
|
2019-02-08 09:56:03 -02:00
|
|
|
call finalize_parameters()
|
|
|
|
|
2021-11-17 12:49:35 -03:00
|
|
|
call stop_timer(itm)
|
2012-07-22 15:46:56 -03:00
|
|
|
|
2021-11-18 17:36:18 -03:00
|
|
|
! print the execution summary (only if the initialization was successful)
|
2008-12-07 14:06:04 -06:00
|
|
|
!
|
2021-11-18 17:18:58 -03:00
|
|
|
if (timings) then
|
2021-11-17 12:49:35 -03:00
|
|
|
allocate(tm(ntimers), stat=status)
|
|
|
|
if (status /= 0) then
|
2021-11-18 17:36:18 -03:00
|
|
|
call print_message(loc, "Could not allocate memory for timings!")
|
2021-11-17 12:49:35 -03:00
|
|
|
go to 6000
|
|
|
|
end if
|
2012-07-22 15:46:56 -03:00
|
|
|
|
2021-11-17 12:49:35 -03:00
|
|
|
tm(1) = get_timer_total()
|
2021-11-18 17:18:58 -03:00
|
|
|
do es = 2, ntimers
|
|
|
|
tm(es) = get_timer(es)
|
2019-02-08 09:56:03 -02:00
|
|
|
end do
|
2014-01-06 11:37:27 -02:00
|
|
|
#ifdef MPI
|
2020-08-14 19:40:10 -03:00
|
|
|
call reduce_sum(tm(1:ntimers))
|
2014-01-06 11:37:27 -02:00
|
|
|
#endif /* MPI */
|
2012-07-22 15:46:56 -03:00
|
|
|
|
2021-11-16 22:39:30 -03:00
|
|
|
if (verbose) then
|
|
|
|
write(* ,'(a)') ''
|
|
|
|
write(*,'(1x,a)') 'EXECUTION TIMINGS'
|
2021-11-18 17:18:58 -03:00
|
|
|
sfmt = "(2x,a32,1x,':',3x,1f16.3,' secs = ',f6.2,' %')"
|
|
|
|
do es = 2, ntimers
|
|
|
|
if (timer_enabled(es) .and. get_count(es) > 0) then
|
|
|
|
write(*,sfmt) timer_description(es), tm(es), 1.0d+02 * tm(es) / tm(1)
|
2021-11-16 22:39:30 -03:00
|
|
|
end if
|
2019-02-08 09:56:03 -02:00
|
|
|
end do
|
2012-07-22 15:46:56 -03:00
|
|
|
|
2021-11-19 11:26:25 -03:00
|
|
|
sfmt = "(1x,a20,14x,':',3x,1f16.3,' secs = ',f6.2,' %')"
|
2021-11-18 17:18:58 -03:00
|
|
|
write(*,sfmt) 'TOTAL EXECUTION TIME', tm(1) , 1.0d+02
|
|
|
|
write(*,sfmt) 'TIME PER STEP ', tm(1) / nsteps, 1.0d+02 / nsteps
|
2012-07-22 15:46:56 -03:00
|
|
|
#ifdef MPI
|
2021-11-18 17:18:58 -03:00
|
|
|
write(*,sfmt) 'TIME PER MPI PROCESS', tm(1) / nprocs, 1.0d+02 / nprocs
|
2012-07-22 15:46:56 -03:00
|
|
|
#endif /* MPI */
|
|
|
|
|
2021-11-18 17:18:58 -03:00
|
|
|
es = int(get_timer_total())
|
2019-02-18 16:57:35 -03:00
|
|
|
ed = es / 86400
|
2021-11-18 17:18:58 -03:00
|
|
|
es = mod(es, 86400)
|
|
|
|
eh = es / 3600
|
|
|
|
es = mod(es, 3600)
|
|
|
|
em = es / 60
|
|
|
|
es = mod(es, 60)
|
2021-11-16 22:39:30 -03:00
|
|
|
|
2021-11-18 17:18:58 -03:00
|
|
|
sfmt = "(1x,'EXECUTION TIME',20x,':',3x,i14," // &
|
|
|
|
"'d',i3.2,'h',i3.2,'m',i3.2,'s')"
|
|
|
|
write(*,sfmt) ed, eh, em, es
|
2012-07-22 15:46:56 -03:00
|
|
|
|
2019-02-08 09:56:03 -02:00
|
|
|
end if
|
2021-11-17 12:49:35 -03:00
|
|
|
deallocate(tm, stat=status)
|
2021-11-18 17:36:18 -03:00
|
|
|
if (status /= 0) &
|
|
|
|
call print_message(loc, "Could not deallocate memory for timings!")
|
2012-07-22 15:46:56 -03:00
|
|
|
end if
|
2021-11-17 11:47:09 -03:00
|
|
|
6000 continue
|
2021-11-17 11:57:38 -03:00
|
|
|
|
2019-02-12 13:56:59 -02:00
|
|
|
call finalize_mpitools(status)
|
2021-11-18 17:36:18 -03:00
|
|
|
if (status /= 0) &
|
|
|
|
call print_message(loc, "Could not finalize module MPITOOLS!")
|
2008-12-07 14:06:04 -06:00
|
|
|
|
2013-12-11 17:18:56 -02:00
|
|
|
call finalize_timers()
|
|
|
|
|
2011-04-29 00:51:28 -03:00
|
|
|
#ifdef SIGNALS
|
2021-11-16 22:39:30 -03:00
|
|
|
contains
|
2020-07-30 16:15:46 -03:00
|
|
|
#ifdef __INTEL_COMPILER
|
2011-04-29 00:51:28 -03:00
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
2020-07-30 11:06:59 -03:00
|
|
|
! function SIGNAL_HANDLER:
|
|
|
|
! -----------------------
|
2012-07-28 13:48:15 -03:00
|
|
|
!
|
2021-11-17 12:49:35 -03:00
|
|
|
! Function sets the variable quit after receiving a signal.
|
2012-07-28 13:48:15 -03:00
|
|
|
!
|
2020-07-30 11:06:59 -03:00
|
|
|
! Arguments:
|
|
|
|
!
|
|
|
|
! sig_num - the number of the signal to be handled;
|
2011-04-29 00:51:28 -03:00
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
2021-11-17 11:57:38 -03:00
|
|
|
integer(kind=4) function signal_handler(sig_num)
|
2011-04-29 00:51:28 -03:00
|
|
|
|
2021-11-17 11:57:38 -03:00
|
|
|
use iso_fortran_env, only : error_unit
|
2021-07-16 11:33:49 -03:00
|
|
|
|
2021-11-17 11:57:38 -03:00
|
|
|
implicit none
|
2011-04-29 00:51:28 -03:00
|
|
|
|
2021-11-17 11:57:38 -03:00
|
|
|
integer(kind=4), intent(in) :: sig_num
|
2011-06-07 17:29:03 -03:00
|
|
|
|
2011-04-29 00:51:28 -03:00
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
2021-11-17 11:57:38 -03:00
|
|
|
quit = sig_num
|
|
|
|
write(error_unit,*)
|
2022-02-14 18:48:10 -03:00
|
|
|
write(error_unit,*) "Received signal:", sig_num
|
2021-11-17 11:57:38 -03:00
|
|
|
write(error_unit,*) "Closing program..."
|
|
|
|
signal_handler = 1
|
2020-07-30 16:15:46 -03:00
|
|
|
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
2021-11-17 11:57:38 -03:00
|
|
|
end function
|
2020-07-30 11:06:59 -03:00
|
|
|
#else /* __INTEL_COMPILER */
|
2020-07-30 16:15:46 -03:00
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
|
|
|
! subroutine SIGNAL_HANDLER:
|
|
|
|
! -------------------------
|
|
|
|
!
|
2021-11-17 12:49:35 -03:00
|
|
|
! Subroutine sets the variable quit after receiving a signal.
|
2020-07-30 16:15:46 -03:00
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
2021-11-17 11:57:38 -03:00
|
|
|
subroutine signal_handler()
|
2020-07-30 16:15:46 -03:00
|
|
|
|
2021-11-17 11:57:38 -03:00
|
|
|
use iso_fortran_env, only : error_unit
|
2021-07-16 11:33:49 -03:00
|
|
|
|
2021-11-17 11:57:38 -03:00
|
|
|
implicit none
|
2020-07-30 16:15:46 -03:00
|
|
|
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
2021-11-17 11:57:38 -03:00
|
|
|
quit = 15
|
|
|
|
write(error_unit,*)
|
|
|
|
write(error_unit,*) "Received signal: 2, 9, or 15"
|
|
|
|
write(error_unit,*) "Closing program..."
|
|
|
|
return
|
2011-04-29 00:51:28 -03:00
|
|
|
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
2021-11-17 11:57:38 -03:00
|
|
|
end subroutine
|
2020-07-30 16:15:46 -03:00
|
|
|
#endif /* __INTEL_COMPILER */
|
2011-04-29 00:51:28 -03:00
|
|
|
#endif /* SIGNALS */
|
|
|
|
|
|
|
|
!===============================================================================
|
|
|
|
!
|
2021-11-16 22:39:30 -03:00
|
|
|
end program
|