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_);
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();
prefixOSstream Perr
OSstream wrapped stderr (std::cerr) with parallel prefix.
bool good() const noexcept
True if the Switch represents a valid enumeration.
static void setHandler(const char *what, int sigNum, void(*handler)(int))
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
static bool nanActive()
True if NaN memory initialisation is currently active.
static void unset(bool verbose=false)
Deactivate SIGFPE signal handler and NaN memory initialisation.
static void shutdown()
Simple shutdown (finalize) of JobInfo.
Ostream & endl(Ostream &os)
Add newline and flush stream.
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, any/none. Also accepts 0/1 as a string and shortcuts t/f, y/n.
string getEnv(const std::string &envName)
Get environment value for given envName.
ignore()
Constructor deactivates any previously active SIGFPE handler.
~sigFpe()
Destructor calls unset() to deactivate the FPE signal handler as required.
static bool isTrue(const char *envName, bool deflt)
static void set(bool verbose=false)
Activate SIGFPE signal handler when FOAM_SIGFPE is set.
static void resetHandler(const char *what, int sigNum)
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Set up trapping for floating point exceptions (signal FPE).
static void printStack(Ostream &os)
Helper function to print a stack.
File-local code for setting/resetting signal handlers.
static void fillNan(UList< scalar > &list)
Fill data block with NaN values.
~ignore()
Destructor restores the original state of SIGFPE handler.
errorManip< error > abort(error &err)
int optimisationSwitch(const char *name, const int deflt=0)
Lookup optimisation switch or add default value.
static bool requested()
Check if SIGFPE signals handler is to be enabled.
messageStream Info
Information stream (stdout output on master, null elsewhere)
sigFpe()
Constructor calls set() to activate the FPE signal handler if it was was not previously activate and ...
void restore()
Restore the original state of SIGFPE handler.
static Switch find(const std::string &str)
Find switchType for the given string, returning as a Switch that can be tested for good() or bad()...