forked from openmc-dev/openmc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
signal.patch
148 lines (138 loc) · 3.69 KB
/
signal.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
diff --git a/.gitignore b/.gitignore
index 8aa7c1f..4c50efb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,7 @@
*.mod
*.log
*.out
+*__genmod.f90
# Compiler python objects
*.pyc
diff --git a/src/Makefile b/src/Makefile
index bab47d2..92f3228 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -43,6 +43,7 @@ GIT_SHA1 = $(shell git log -1 2>/dev/null | head -n 1 | awk '{print $$2}')
#===============================================================================
ifeq ($(COMPILER),gnu)
+ CC = gcc
F90 = gfortran
F90FLAGS := -cpp -fbacktrace -DNO_F2008
LDFLAGS =
@@ -71,6 +72,7 @@ endif
#===============================================================================
ifeq ($(COMPILER),intel)
+ CC = icc
F90 = ifort
F90FLAGS := -cpp -warn -assume byterecl -traceback
LDFLAGS =
@@ -98,6 +100,7 @@ endif
#===============================================================================
ifeq ($(COMPILER),pgi)
+ CC = pgcc
F90 = pgf90
F90FLAGS := -Mpreprocess -DNO_F2008 -Minform=inform -traceback
LDFLAGS =
@@ -125,6 +128,7 @@ endif
#===============================================================================
ifeq ($(COMPILER),ibm)
+ CC = xlc
F90 = xlf2003
F90FLAGS := -WF,-DNO_F2008 -O2
@@ -235,7 +239,7 @@ distclean: clean
cd xml-fortran; make clean
cd templates; make clean
clean:
- @rm -f *.o *.mod $(program)
+ @rm -f *.o *.mod *__genmod.f90 $(program)
neat:
@rm -f *.o *.mod
@@ -249,6 +253,9 @@ neat:
%.o: %.F90
$(F90) $(F90FLAGS) -DGIT_SHA1="\"$(GIT_SHA1)\"" -Ixml-fortran -Itemplates -c $<
+csignal.o: csignal.c
+ $(CC) -c $<
+
#===============================================================================
# Dependencies
#===============================================================================
diff --git a/src/OBJECTS b/src/OBJECTS
index d53f0a5..b2a7f52 100644
--- a/src/OBJECTS
+++ b/src/OBJECTS
@@ -15,6 +15,7 @@ cmfd_prod_operator.o \
cmfd_snes_solver.o \
constants.o \
cross_section.o \
+csignal.o \
dict_header.o \
doppler.o \
eigenvalue.o \
@@ -28,6 +29,7 @@ fixed_source.o \
geometry.o \
geometry_header.o \
global.o \
+handle_sigint.o \
hdf5_interface.o \
initialize.o \
interpolation.o \
diff --git a/src/csignal.c b/src/csignal.c
new file mode 100644
index 0000000..96bfdb5
--- /dev/null
+++ b/src/csignal.c
@@ -0,0 +1,7 @@
+#include <signal.h>
+
+typedef void (*sighandler_t)(int);
+void signal_(int* signum, sighandler_t handler)
+{
+ signal(*signum, handler);
+}
diff --git a/src/handle_sigint.F90 b/src/handle_sigint.F90
new file mode 100644
index 0000000..b2f7d1b
--- /dev/null
+++ b/src/handle_sigint.F90
@@ -0,0 +1,27 @@
+!===============================================================================
+! HANDLE_SIGINT
+!===============================================================================
+
+subroutine handle_sigint()
+
+ use, intrinsic :: ISO_FORTRAN_ENV
+
+ integer :: option ! selected user option
+
+ ! Display interrupt options
+ write(OUTPUT_UNIT,*) 'Run interrupted. Select one of the options below:'
+ write(OUTPUT_UNIT,*) ' 1. Continue simulation'
+ write(OUTPUT_UNIT,*) ' 2. Kill simulation'
+
+ ! Read input from user
+ read(INPUT_UNIT,*) option
+
+ ! Handle selected option
+ select case (option)
+ case (1)
+ return
+ case (2)
+ stop
+ end select
+
+end subroutine handle_sigint
diff --git a/src/initialize.F90 b/src/initialize.F90
index ff3a209..fd2e222 100644
--- a/src/initialize.F90
+++ b/src/initialize.F90
@@ -42,6 +42,10 @@ contains
subroutine initialize_run()
+ ! Set up signal handler for SIGINT
+ external handle_sigint
+ call signal(2, handle_sigint)
+
! Start total and initialization timer
call time_total % start()
call time_initialize % start()