Go to the documentation of this file.
39 #if defined(__linux__) && defined(__GNUC__)
41 #define __USE_GNU // To use feenableexcept()
60 bool Foam::sigFpe::sigActive_ =
false;
61 bool Foam::sigFpe::nanActive_ =
false;
68 static bool isTrue(
const char* envName,
bool deflt)
74 return static_cast<bool>(sw);
85 extern void* __libc_malloc(
size_t size);
88 void* malloc(
size_t size)
92 return Foam::sigFpe::mallocNan(size);
96 return __libc_malloc(size);
102 void* Foam::sigFpe::mallocNan(
size_t size)
105 void* result = __libc_malloc(size);
108 UList<scalar> list(
reinterpret_cast<scalar*
>(result), size/
sizeof(scalar));
118 void Foam::sigFpe::sigHandler(
int)
120 #if (defined(__linux__) && defined(__GNUC__)) || defined(__APPLE__)
128 #endif // (__linux__ && __GNUC__) || __APPLE__
142 wasActive_(sigFpe::active())
179 return isTrue(
"FOAM_SIGFPE", switchFpe_);
185 if (!sigActive_ && requested())
187 #if (defined(__linux__) && defined(__GNUC__)) || defined(__APPLE__)
203 Info<<
"trapFpe: Floating point exception trapping ";
207 Info<<
"enabled (FOAM_SIGFPE)." <<
endl;
211 Info<<
"- not supported on this platform" <<
endl;
218 if (
isTrue(
"FOAM_SETNAN", switchNan_))
226 Info<<
"setNaN : Initialise allocated memory to NaN ";
230 Info<<
"enabled (FOAM_SETNAN)." <<
endl;
234 Info<<
" - not supported on this platform" <<
endl;
243 #if (defined(__linux__) && defined(__GNUC__)) || defined(__APPLE__)
248 Info<<
"sigFpe : Disabling floating point exception trapping"
255 const int oldExcept = fedisableexcept
265 <<
"Cannot reset SIGFPE trapping"
279 list = std::numeric_limits<scalar>::signaling_NaN();
static void set(bool verbose=false)
Activate SIGFPE signal handler when FOAM_SIGFPE is set.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
static void printStack(Ostream &os)
Helper function to print a stack.
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
static void resetHandler(const char *what, int sigNum)
static bool nanActive()
True if NaN memory initialisation is currently active.
ignore()
Constructor deactivates any previously active SIGFPE handler.
static void unset(bool verbose=false)
Deactivate SIGFPE signal handler and NaN memory initialisation.
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool good() const noexcept
True if the Switch represents a valid enumeration.
static Switch find(const std::string &str)
string getEnv(const std::string &envName)
Get environment value for given envName.
static void fillNan(UList< scalar > &list)
Fill data block with NaN values.
static bool isTrue(const char *envName, bool deflt)
messageStream Info
Information stream (uses stdout - output is on the master only)
File-local code for setting/resetting signal handlers.
~ignore()
Destructor restores the original state of SIGFPE handler.
int optimisationSwitch(const char *name, const int deflt=0)
Lookup optimisation switch or add default value.
errorManip< error > abort(error &err)
static bool requested()
Check if SIGFPE signals handler is to be enabled.
prefixOSstream Perr
An Ostream wrapper for parallel output to std::cerr.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
static void setHandler(const char *what, int sigNum, void(*handler)(int))
void restore()
Restore the original state of SIGFPE handler.
void signalEnd() const
Update job info and relocate the file from running to finished.