gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
a Global And Modular Bsm Inference Tool
functors_with_signals.cpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
19 
21 #include "gambit/Utils/signal_handling.hpp" // Don't want this in standlone mode
22 #include "gambit/Logs/logger.hpp"
23 
24 namespace Gambit
25 {
26 
28 
31  namespace FunctorHelp {
32 
33  // Both OBSOLETE
34  // /// Thin wrapper to isolate signal handling from other components of the functors
35  // bool emergency_shutdown_begun()
36  // {
37  // return signaldata().emergency_shutdown_begun();
38  // }
39  //
40  // /// Check if shutdown in progress and take appropriate action.
41  // /// Now only cancels evaluations if it is an emergency shutdown; soft shutdown requires
42  // /// valid likelihood calculation to continue until synchronisation can be achieved.
43  // void check_for_shutdown_signal(module_functor_common& functor)
44  // {
45  // /* Check if shutdown signal received, and either throw Shutdown exception or break out of loop */
46  // if(functor.emergency_shutdown_begun())
47  // {
48  // #pragma omp critical (module_functor_calculate)
49  // {
50  // std::ostringstream ss;
51  // ss << "Shutdown signal detected while computing functor "<<functor.myName<<"! (omp_get_level()==" << omp_get_level() << ", thread="<<omp_get_thread_num()<<")";
52  // std::cerr << ss.str() << std::endl;
53  // logger() << LogTags::core << LogTags::debug << ss.str() << EOM;
54  // }
55  // if(omp_get_level()==0) /* If shutdown signal received and we are not in an */
56  // { /* OpenMP parallel block, perform the shutdown. */
57  // signaldata().check_for_emergency_shutdown_signal();/* (but only if it is an emergency) */
58  // // Throw error if we haven't jumped!
59  // std::cerr << "rank " << signaldata().myrank() <<": No emergency shutdown occurred, but according to previous logic the signal to do so must have already been received! Please file a bug report." << std::endl;
60  // exit(EXIT_FAILURE);
61  // }
62  // else if(functor.iCanManageLoops)
63  // {
64  // functor.breakLoop();
65  // logger() << LogTags::core << LogTags::debug << "breakLoop triggered (iCanManageLoops==1) in functor " << functor.myName << EOM;
66  // }
67  // else /* Must be a managed functor (since type is not void, cannot be a loop manager) */
68  // {
69  // functor.breakLoopFromManagedFunctor();
70  // functor.breakLoop(); /* Set this as well anyway in case I didn't understand the logic correctly. */
71  // logger() << LogTags::core << LogTags::debug << "breakLoop triggered while computing functor "<<functor.myName<<" (thread="<<omp_get_thread_num()<<")" << EOM;
72  // }
73  // }
74  // }
75 
77  {
78  if(functor.iCanManageLoops and not signaldata().inside_multithreaded_region())
79  {
80  /* Debugging */
81  if(omp_get_level()!=0)
82  {
83  std::cerr << "rank " << signaldata().myrank() <<": Tried to set signaldata().inside_omp_block=1 (in "<<functor.myName<<"), but we are already in a parellel region! Please file a bug report." << std::endl;
84  exit(EXIT_FAILURE);
85  } \
86  /* end debugging */
87  signaldata().entering_multithreaded_region(); /* Switch signal handler to threadsafe mode */
88  functor.signal_mode_locked = false; /* We are allowed to switch off sighandler threadsafe mode */
89  }
90  }
91 
93  {
94  if(functor.iCanManageLoops and not functor.signal_mode_locked)
95  {
96  /* Debugging */
97  if(omp_get_level()!=0)
98  {
99  std::cerr << "rank " << signaldata().myrank() <<": Tried to set signaldata().inside_omp_block=0 (in "<<functor.myName<<"), but we are still inside a parellel region! Please file a bug report." << std::endl;
100  exit(EXIT_FAILURE);
101  }
102  /* end debugging */
103  signaldata().leaving_multithreaded_region(); /* Switch signal handler back to normal mode */
104  }
105  }
106  }
108 
110 
111 
112 }
void leaving_multithreaded_region(module_functor_common &functor)
bool iCanManageLoops
Flag indicating whether this function can manage a loop over other functions.
Definition: functors.hpp:624
void entering_multithreaded_region()
Check if shutdown is in progress and raise appropriate termination exception if so.
Function wrapper (functor) base class.
Definition: functors.hpp:87
Logging access header for GAMBIT.
void leaving_multithreaded_region()
Exit threadsafe signal handling mode.
GAMBIT signal handling functions.
Functor derived class for module functions.
Definition: functors.hpp:399
Functor class definitions.
EXPORT_SYMBOLS SignalData & signaldata()
Retrieve global instance of signal handler options struct.
std::string myrank()
Retrieve MPI rank as a string (for log messages etc.)
str myName
Internal storage of the function name.
Definition: functors.hpp:320
TODO: see if we can use this one:
Definition: Analysis.hpp:33
void entering_multithreaded_region(module_functor_common &functor)
bool signal_mode_locked
While locked, prevent this function switching off threadsafe* emergency signal handling.
Definition: functors.hpp:727