42 #if defined(__linux__) && defined(__GNUC__) 44 #define __USE_GNU // To use feenableexcept() 61 bool Foam::sigFpe::sigActive_ =
false;
62 bool Foam::sigFpe::nanActive_ =
false;
69 static bool isTrue(
const char* envName,
bool deflt)
75 return static_cast<bool>(sw);
86 extern void* __libc_malloc(
size_t size);
89 void* malloc(
size_t size)
92 void* ptr = __libc_malloc(size);
97 const auto val = std::numeric_limits<Foam::scalar>::signaling_NaN();
104 reinterpret_cast<Foam::scalar*>(ptr),
105 (size/
sizeof(Foam::scalar)),
119 void Foam::sigFpe::sigHandler(
int)
121 #if (defined(__linux__) && defined(__GNUC__)) || defined(__APPLE__) 129 #endif // (__linux__ && __GNUC__) || __APPLE__ 153 return isTrue(
"FOAM_SIGFPE", switchFpe_);
159 if (!sigActive_ && requested())
161 #if (defined(__linux__) && defined(__GNUC__)) || defined(__APPLE__) 177 Info<<
"trapFpe: Floating point exception trapping ";
181 Info<<
"enabled (FOAM_SIGFPE)." <<
endl;
185 Info<<
"- not supported on this platform" <<
endl;
192 if (
isTrue(
"FOAM_SETNAN", switchNan_))
200 Info<<
"setNaN : Fill allocated memory with NaN ";
204 Info<<
"enabled (FOAM_SETNAN)." <<
endl;
208 Info<<
" - not supported on this platform" <<
endl;
217 #if (defined(__linux__) && defined(__GNUC__)) || defined(__APPLE__) 222 Info<<
"sigFpe : Disabling floating point exception trapping" 229 const int oldExcept = fedisableexcept
239 <<
"Cannot reset SIGFPE trapping" 253 if (!buf || !
count)
return;
256 const auto val = std::numeric_limits<scalar>::signaling_NaN();
263 reinterpret_cast<scalar*>(buf), (
count/
sizeof(scalar)), val
270 if (list.
empty())
return;
273 const auto val = std::numeric_limits<scalar>::signaling_NaN();
prefixOSstream Perr
OSstream wrapped stderr (std::cerr) with parallel prefix.
void size(const label n)
Older name for setAddressableSize.
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 void unset(bool verbose=false)
Deactivate SIGFPE handler and NaN memory initialisation.
bool empty() const noexcept
True if List is empty (ie, size() is zero)
T * data() noexcept
Return pointer to the underlying array serving as data storage.
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.
~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 handler when FOAM_SIGFPE is enabled. Activate fill memory with signaling_NaN when FOA...
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...
void unset(List< bool > &bools, const labelUList &locations)
Unset the listed locations (assign 'false').
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
File-local code for setting/resetting signal handlers.
errorManip< error > abort(error &err)
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
int optimisationSwitch(const char *name, const int deflt=0)
Lookup optimisation switch or add default value.
static bool nanActive() noexcept
True if NaN memory initialisation is currently active.
static void fillNan(char *buf, size_t count)
Fill data block with signaling_NaN values.
static bool requested()
Check if SIGFPE signals handler is to be enabled.
messageStream Info
Information stream (stdout output on master, null elsewhere)
static void printStack(Ostream &os, int size=-1)
Helper function to print a stack, with optional upper limit.
sigFpe()
Constructor calls set() to activate the FPE signal handler if it was was not previously activate and ...
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()...