NEURON
nrntimeout.cpp
Go to the documentation of this file.
1 /*
2 # =============================================================================
3 # Copyright (c) 2016 - 2021 Blue Brain Project/EPFL
4 #
5 # See top-level LICENSE file for details.
6 # =============================================================================.
7 */
8 
9 #include "coreneuron/nrnconf.h"
11 #include "coreneuron/mpi/nrnmpi.h"
13 
14 #if NRNMPI
15 
16 #include <csignal>
17 #include <sys/time.h>
18 
19 /* if you are using any sampling based profiling tool,
20 setitimer will conflict with profiler. In that case,
21 user can disable setitimer which is just safety for
22 deadlock situations */
23 namespace coreneuron {
24 #if (defined(DISABLE_TIMEOUT) || defined(MINGW))
25 
26 void nrn_timeout(int seconds) {}
27 
28 #else
29 
30 static double told;
31 static struct itimerval value;
32 static struct sigaction act, oact;
33 
34 static void timed_out(int sig) {
35  (void) sig; /* unused */
36 #if CORENRN_DEBUG
37  printf("timed_out told=%g t=%g\n", told, t);
38 #endif
39  if (nrn_threads->_t == told) { /* nothing has been accomplished since last signal*/
40  printf("nrn_timeout t=%g\n", nrn_threads->_t);
41  nrn_abort(0);
42  }
43  told = nrn_threads->_t;
44 }
45 
46 void nrn_timeout(int seconds) {
47  if (nrnmpi_myid != 0) {
48  return;
49  }
50 #if CORENRN_DEBUG
51  printf("nrn_timeout %d\n", seconds);
52 #endif
53  if (seconds) {
54  told = nrn_threads->_t;
55  act.sa_handler = timed_out;
56  act.sa_flags = SA_RESTART;
57  if (sigaction(SIGALRM, &act, &oact)) {
58  printf("sigaction failed\n");
59  nrn_abort(0);
60  }
61  } else {
62  sigaction(SIGALRM, &oact, (struct sigaction*) 0);
63  }
64  value.it_interval.tv_sec = seconds;
65  value.it_interval.tv_usec = 0;
66  value.it_value.tv_sec = seconds;
67  value.it_value.tv_usec = 0;
68  if (setitimer(ITIMER_REAL, &value, (struct itimerval*) 0)) {
69  printf("setitimer failed\n");
70  nrn_abort(0);
71  }
72 }
73 
74 #endif /* DISABLE_TIMEOUT */
75 } // namespace coreneuron
76 
77 #endif /*NRNMPI*/
printf
Definition: extdef.h:5
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
NrnThread * nrn_threads
Definition: multicore.cpp:56
void nrn_abort(int errcode)
Definition: utils.cpp:13
static uint32_t value
Definition: scoprand.cpp:25