mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
EHN: make signal verbosity an optional calling argument.
This commit is contained in:
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -29,10 +29,11 @@ License
|
|||||||
#include "OSspecific.H"
|
#include "OSspecific.H"
|
||||||
#include "IOstreams.H"
|
#include "IOstreams.H"
|
||||||
#include "Switch.H"
|
#include "Switch.H"
|
||||||
|
#include "UList.H"
|
||||||
|
|
||||||
#ifdef LINUX_GNUC
|
#if defined(__linux__) && defined(__GNUC__)
|
||||||
#ifndef __USE_GNU
|
#ifndef __USE_GNU
|
||||||
#define __USE_GNU
|
#define __USE_GNU // To use feenableexcept()
|
||||||
#endif
|
#endif
|
||||||
#include <fenv.h>
|
#include <fenv.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
@ -48,21 +49,23 @@ bool Foam::sigFpe::switchFpe_(Foam::debug::optimisationSwitch("trapFpe", 0));
|
|||||||
bool Foam::sigFpe::switchNan_(Foam::debug::optimisationSwitch("setNaN", 0));
|
bool Foam::sigFpe::switchNan_(Foam::debug::optimisationSwitch("setNaN", 0));
|
||||||
|
|
||||||
bool Foam::sigFpe::sigActive_ = false;
|
bool Foam::sigFpe::sigActive_ = false;
|
||||||
bool Foam::sigFpe::mallocNanActive_ = false;
|
bool Foam::sigFpe::nanActive_ = false;
|
||||||
|
|
||||||
struct sigaction Foam::sigFpe::oldAction_;
|
struct sigaction Foam::sigFpe::oldAction_;
|
||||||
|
|
||||||
|
|
||||||
// File-scope function.
|
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||||
// Controlled by env variable containing a bool (true|false|on|off ...)
|
|
||||||
|
// Can turn on/off via env variable containing a bool (true|false|on|off ...)
|
||||||
// or by the specified flag
|
// or by the specified flag
|
||||||
static bool isTrue(const char* envName, const bool flag)
|
static bool isTrue(const char* envName, bool deflt)
|
||||||
{
|
{
|
||||||
const std::string str = Foam::getEnv(envName);
|
const auto str(Foam::getEnv(envName));
|
||||||
|
|
||||||
if (str.size())
|
if (str.size())
|
||||||
{
|
{
|
||||||
Foam::Switch sw(str, true); // silently ignore bad input
|
Foam::Switch sw(str, true); // Silently ignores bad input
|
||||||
|
|
||||||
if (sw.valid())
|
if (sw.valid())
|
||||||
{
|
{
|
||||||
return sw;
|
return sw;
|
||||||
@ -70,17 +73,11 @@ static bool isTrue(const char* envName, const bool flag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Env was not set or did not contain a valid bool value
|
// Env was not set or did not contain a valid bool value
|
||||||
return flag;
|
return deflt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::sigFpe::fillNan(UList<scalar>& lst)
|
#ifdef __linux__
|
||||||
{
|
|
||||||
lst = std::numeric_limits<scalar>::signaling_NaN();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef LINUX
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
extern void* __libc_malloc(size_t size);
|
extern void* __libc_malloc(size_t size);
|
||||||
@ -88,7 +85,7 @@ extern "C"
|
|||||||
// Override the GLIBC malloc to support mallocNan
|
// Override the GLIBC malloc to support mallocNan
|
||||||
void* malloc(size_t size)
|
void* malloc(size_t size)
|
||||||
{
|
{
|
||||||
if (Foam::sigFpe::mallocNanActive_)
|
if (Foam::sigFpe::nanActive())
|
||||||
{
|
{
|
||||||
return Foam::sigFpe::mallocNan(size);
|
return Foam::sigFpe::mallocNan(size);
|
||||||
}
|
}
|
||||||
@ -99,21 +96,21 @@ extern "C"
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void* Foam::sigFpe::mallocNan(size_t size)
|
void* Foam::sigFpe::mallocNan(size_t size)
|
||||||
{
|
{
|
||||||
// Call the low-level GLIBC malloc function
|
// Call the low-level GLIBC malloc function
|
||||||
void * result = __libc_malloc(size);
|
void* result = __libc_malloc(size);
|
||||||
|
|
||||||
// Initialize to signalling NaN
|
// Initialize to signalling NaN
|
||||||
UList<scalar> lst(reinterpret_cast<scalar*>(result), size/sizeof(scalar));
|
UList<scalar> list(reinterpret_cast<scalar*>(result), size/sizeof(scalar));
|
||||||
sigFpe::fillNan(lst);
|
sigFpe::fillNan(list);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef LINUX_GNUC
|
#ifdef __GNUC__
|
||||||
void Foam::sigFpe::sigHandler(int)
|
void Foam::sigFpe::sigHandler(int)
|
||||||
{
|
{
|
||||||
// Reset old handling
|
// Reset old handling
|
||||||
@ -124,15 +121,12 @@ void Foam::sigFpe::sigHandler(int)
|
|||||||
<< abort(FatalError);
|
<< abort(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update jobInfo file
|
jobInfo.signalEnd(); // Update jobInfo file
|
||||||
jobInfo.signalEnd();
|
|
||||||
|
|
||||||
error::printStack(Perr);
|
error::printStack(Perr);
|
||||||
|
raise(SIGFPE); // Throw signal (to old handler)
|
||||||
// Throw signal (to old handler)
|
|
||||||
raise(SIGFPE);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif // __GNUC__
|
||||||
|
#endif // __linux__
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
@ -159,14 +153,11 @@ bool Foam::sigFpe::requested()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::sigFpe::set(const bool verbose)
|
void Foam::sigFpe::set(bool verbose)
|
||||||
{
|
{
|
||||||
if (!sigActive_ && requested())
|
if (!sigActive_ && requested())
|
||||||
{
|
{
|
||||||
bool supported = false;
|
#if defined(__linux__) && defined(__GNUC__)
|
||||||
|
|
||||||
#ifdef LINUX_GNUC
|
|
||||||
supported = true;
|
|
||||||
|
|
||||||
feenableexcept
|
feenableexcept
|
||||||
(
|
(
|
||||||
@ -179,6 +170,7 @@ void Foam::sigFpe::set(const bool verbose)
|
|||||||
newAction.sa_handler = sigHandler;
|
newAction.sa_handler = sigHandler;
|
||||||
newAction.sa_flags = SA_NODEFER;
|
newAction.sa_flags = SA_NODEFER;
|
||||||
sigemptyset(&newAction.sa_mask);
|
sigemptyset(&newAction.sa_mask);
|
||||||
|
|
||||||
if (sigaction(SIGFPE, &newAction, &oldAction_) < 0)
|
if (sigaction(SIGFPE, &newAction, &oldAction_) < 0)
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
@ -189,7 +181,6 @@ void Foam::sigFpe::set(const bool verbose)
|
|||||||
sigActive_ = true;
|
sigActive_ = true;
|
||||||
|
|
||||||
#elif defined(sgiN32) || defined(sgiN32Gcc)
|
#elif defined(sgiN32) || defined(sgiN32Gcc)
|
||||||
supported = true;
|
|
||||||
|
|
||||||
sigfpe_[_DIVZERO].abort=1;
|
sigfpe_[_DIVZERO].abort=1;
|
||||||
sigfpe_[_OVERFL].abort=1;
|
sigfpe_[_OVERFL].abort=1;
|
||||||
@ -211,7 +202,6 @@ void Foam::sigFpe::set(const bool verbose)
|
|||||||
);
|
);
|
||||||
|
|
||||||
sigActive_ = true;
|
sigActive_ = true;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -219,7 +209,7 @@ void Foam::sigFpe::set(const bool verbose)
|
|||||||
{
|
{
|
||||||
Info<< "trapFpe: Floating point exception trapping ";
|
Info<< "trapFpe: Floating point exception trapping ";
|
||||||
|
|
||||||
if (supported)
|
if (sigActive_)
|
||||||
{
|
{
|
||||||
Info<< "enabled (FOAM_SIGFPE)." << endl;
|
Info<< "enabled (FOAM_SIGFPE)." << endl;
|
||||||
}
|
}
|
||||||
@ -231,17 +221,18 @@ void Foam::sigFpe::set(const bool verbose)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
nanActive_ = false;
|
||||||
if (isTrue("FOAM_SETNAN", switchNan_))
|
if (isTrue("FOAM_SETNAN", switchNan_))
|
||||||
{
|
{
|
||||||
#ifdef LINUX
|
#ifdef __linux__
|
||||||
mallocNanActive_ = true;
|
nanActive_ = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
Info<< "setNaN : Initialise allocated memory to NaN ";
|
Info<< "setNaN : Initialise allocated memory to NaN ";
|
||||||
|
|
||||||
if (mallocNanActive_)
|
if (nanActive_)
|
||||||
{
|
{
|
||||||
Info<< "enabled (FOAM_SETNAN)." << endl;
|
Info<< "enabled (FOAM_SETNAN)." << endl;
|
||||||
}
|
}
|
||||||
@ -254,10 +245,9 @@ void Foam::sigFpe::set(const bool verbose)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::sigFpe::unset(const bool verbose)
|
void Foam::sigFpe::unset(bool verbose)
|
||||||
{
|
{
|
||||||
#ifdef LINUX_GNUC
|
#if defined(__linux__) && defined(__GNUC__)
|
||||||
// Reset signal
|
|
||||||
if (sigActive_)
|
if (sigActive_)
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
@ -274,7 +264,7 @@ void Foam::sigFpe::unset(const bool verbose)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reset exception raising
|
// Reset exception raising
|
||||||
int oldExcept = fedisableexcept
|
const int oldExcept = fedisableexcept
|
||||||
(
|
(
|
||||||
FE_DIVBYZERO
|
FE_DIVBYZERO
|
||||||
| FE_INVALID
|
| FE_INVALID
|
||||||
@ -287,14 +277,18 @@ void Foam::sigFpe::unset(const bool verbose)
|
|||||||
<< "Cannot reset SIGFPE trapping"
|
<< "Cannot reset SIGFPE trapping"
|
||||||
<< abort(FatalError);
|
<< abort(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
sigActive_ = false;
|
sigActive_ = false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LINUX
|
nanActive_ = false;
|
||||||
// Disable initialization to NaN
|
}
|
||||||
mallocNanActive_ = false;
|
|
||||||
#endif
|
|
||||||
|
void Foam::sigFpe::fillNan(UList<scalar>& list)
|
||||||
|
{
|
||||||
|
list = std::numeric_limits<scalar>::signaling_NaN();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -55,23 +55,16 @@ SourceFiles
|
|||||||
#define sigFpe_H
|
#define sigFpe_H
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include "scalar.H"
|
||||||
#if defined(linux) || defined(linux64) || defined(linuxIA64) || \
|
|
||||||
defined(linuxARM7) || defined(linuxPPC64) || defined(linuxPPC64le)
|
|
||||||
#define LINUX
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(LINUX) && defined(__GNUC__)
|
|
||||||
#define LINUX_GNUC
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "UList.H"
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
template<class T> class UList;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class sigFpe Declaration
|
Class sigFpe Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
@ -91,13 +84,16 @@ class sigFpe
|
|||||||
//- Flag to indicate floating point trapping is currently active
|
//- Flag to indicate floating point trapping is currently active
|
||||||
static bool sigActive_;
|
static bool sigActive_;
|
||||||
|
|
||||||
|
//- Flag to indicate mallocNan is currently active
|
||||||
|
static bool nanActive_;
|
||||||
|
|
||||||
//- Saved old signal trapping setting
|
//- Saved old signal trapping setting
|
||||||
static struct sigaction oldAction_;
|
static struct sigaction oldAction_;
|
||||||
|
|
||||||
|
|
||||||
// Static data members
|
// Static data members
|
||||||
|
|
||||||
#ifdef LINUX_GNUC
|
#if defined(__linux__) && defined(__GNUC__)
|
||||||
//- Handler for caught signals
|
//- Handler for caught signals
|
||||||
static void sigHandler(int);
|
static void sigHandler(int);
|
||||||
#endif
|
#endif
|
||||||
@ -105,12 +101,6 @@ class sigFpe
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Public data
|
|
||||||
|
|
||||||
//- Flag to indicate mallocNan is enabled
|
|
||||||
static bool mallocNanActive_;
|
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct null
|
//- Construct null
|
||||||
@ -128,20 +118,32 @@ public:
|
|||||||
// environment variable
|
// environment variable
|
||||||
static bool requested();
|
static bool requested();
|
||||||
|
|
||||||
|
//- True if SIGFPE handling is currently active.
|
||||||
|
static inline bool active()
|
||||||
|
{
|
||||||
|
return sigActive_;
|
||||||
|
}
|
||||||
|
|
||||||
|
//- True if NaN memory initialisation is currently active.
|
||||||
|
static inline bool nanActive()
|
||||||
|
{
|
||||||
|
return nanActive_;
|
||||||
|
}
|
||||||
|
|
||||||
//- Activate SIGFPE signal handler when FOAM_SIGFPE is %set
|
//- Activate SIGFPE signal handler when FOAM_SIGFPE is %set
|
||||||
// Fill memory with NaN when FOAM_SETNAN is %set
|
// Fill memory with NaN when FOAM_SETNAN is %set
|
||||||
static void set(const bool verbose);
|
static void set(bool verbose=false);
|
||||||
|
|
||||||
//- Deactivate SIGFPE signal handler and NaN memory initialisation
|
//- Deactivate SIGFPE signal handler and NaN memory initialisation
|
||||||
static void unset(const bool verbose);
|
static void unset(bool verbose=false);
|
||||||
|
|
||||||
#ifdef LINUX
|
#ifdef __linux__
|
||||||
//- Malloc function which initializes to NaN
|
//- Malloc function which initializes to NaN
|
||||||
static void* mallocNan(size_t size);
|
static void* mallocNan(size_t size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//- Fill block of data with NaN
|
//- Fill data block with NaN values
|
||||||
static void fillNan(UList<scalar>& lst);
|
static void fillNan(UList<scalar>& list);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -47,11 +47,8 @@ void Foam::sigInt::sigHandler(int)
|
|||||||
<< abort(FatalError);
|
<< abort(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update jobInfo file
|
jobInfo.signalEnd(); // Update jobInfo file
|
||||||
jobInfo.signalEnd();
|
raise(SIGINT); // Throw signal (to old handler)
|
||||||
|
|
||||||
// Throw signal (to old handler)
|
|
||||||
raise(SIGINT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -73,7 +70,7 @@ Foam::sigInt::~sigInt()
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
void Foam::sigInt::set(const bool)
|
void Foam::sigInt::set(bool)
|
||||||
{
|
{
|
||||||
if (!sigActive_)
|
if (!sigActive_)
|
||||||
{
|
{
|
||||||
@ -92,7 +89,7 @@ void Foam::sigInt::set(const bool)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::sigInt::unset(const bool)
|
void Foam::sigInt::unset(bool)
|
||||||
{
|
{
|
||||||
if (sigActive_)
|
if (sigActive_)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -87,10 +87,10 @@ public:
|
|||||||
// Member functions
|
// Member functions
|
||||||
|
|
||||||
//- Activate SIGINT signal handler
|
//- Activate SIGINT signal handler
|
||||||
static void set(const bool verbose);
|
static void set(bool verbose=false);
|
||||||
|
|
||||||
//- Deactivate SIGINT signal handler
|
//- Deactivate SIGINT signal handler
|
||||||
static void unset(const bool verbose);
|
static void unset(bool verbose=false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -47,13 +47,9 @@ void Foam::sigQuit::sigHandler(int)
|
|||||||
<< abort(FatalError);
|
<< abort(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update jobInfo file
|
jobInfo.signalEnd(); // Update jobInfo file
|
||||||
jobInfo.signalEnd();
|
|
||||||
|
|
||||||
error::printStack(Perr);
|
error::printStack(Perr);
|
||||||
|
raise(SIGQUIT); // Throw signal (to old handler)
|
||||||
// Throw signal (to old handler)
|
|
||||||
raise(SIGQUIT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -75,7 +71,7 @@ Foam::sigQuit::~sigQuit()
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
void Foam::sigQuit::set(const bool verbose)
|
void Foam::sigQuit::set(bool)
|
||||||
{
|
{
|
||||||
if (!sigActive_)
|
if (!sigActive_)
|
||||||
{
|
{
|
||||||
@ -94,7 +90,7 @@ void Foam::sigQuit::set(const bool verbose)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::sigQuit::unset(const bool)
|
void Foam::sigQuit::unset(bool)
|
||||||
{
|
{
|
||||||
if (sigActive_)
|
if (sigActive_)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -87,10 +87,10 @@ public:
|
|||||||
// Member functions
|
// Member functions
|
||||||
|
|
||||||
//- Activate SIGQUIT signal handler
|
//- Activate SIGQUIT signal handler
|
||||||
static void set(const bool verbose);
|
static void set(bool verbose=false);
|
||||||
|
|
||||||
//- Deactivate SIGQUIT signal handler
|
//- Deactivate SIGQUIT signal handler
|
||||||
static void unset(const bool verbose);
|
static void unset(bool verbose=false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -47,13 +47,9 @@ void Foam::sigSegv::sigHandler(int)
|
|||||||
<< abort(FatalError);
|
<< abort(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update jobInfo file
|
jobInfo.signalEnd(); // Update jobInfo file
|
||||||
jobInfo.signalEnd();
|
|
||||||
|
|
||||||
error::printStack(Perr);
|
error::printStack(Perr);
|
||||||
|
raise(SIGSEGV); // Throw signal (to old handler)
|
||||||
// Throw signal (to old handler)
|
|
||||||
raise(SIGSEGV);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -75,7 +71,7 @@ Foam::sigSegv::~sigSegv()
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
void Foam::sigSegv::set(const bool)
|
void Foam::sigSegv::set(bool)
|
||||||
{
|
{
|
||||||
if (!sigActive_)
|
if (!sigActive_)
|
||||||
{
|
{
|
||||||
@ -94,7 +90,7 @@ void Foam::sigSegv::set(const bool)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::sigSegv::unset(const bool)
|
void Foam::sigSegv::unset(bool)
|
||||||
{
|
{
|
||||||
if (sigActive_)
|
if (sigActive_)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -87,10 +87,10 @@ public:
|
|||||||
// Member functions
|
// Member functions
|
||||||
|
|
||||||
//- Activate SIGSEGV signal handler
|
//- Activate SIGSEGV signal handler
|
||||||
static void set(const bool verbose);
|
static void set(bool verbose=false);
|
||||||
|
|
||||||
//- Deactivate SIGSEGV signal handler
|
//- Deactivate SIGSEGV signal handler
|
||||||
static void unset(const bool verbose);
|
static void unset(bool verbose=false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -31,15 +31,19 @@ License
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
|
||||||
{
|
|
||||||
|
|
||||||
// Signal number to catch
|
// Signal number to catch
|
||||||
int sigStopAtWriteNow::signal_
|
int Foam::sigStopAtWriteNow::signal_
|
||||||
(
|
(
|
||||||
debug::optimisationSwitch("stopAtWriteNowSignal", -1)
|
Foam::debug::optimisationSwitch("stopAtWriteNowSignal", -1)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Foam::Time const* Foam::sigStopAtWriteNow::runTimePtr_ = nullptr;
|
||||||
|
|
||||||
|
struct sigaction Foam::sigStopAtWriteNow::oldAction_;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
// Register re-reader
|
// Register re-reader
|
||||||
class addstopAtWriteNowSignalToOpt
|
class addstopAtWriteNowSignalToOpt
|
||||||
:
|
:
|
||||||
@ -53,8 +57,7 @@ public:
|
|||||||
::Foam::simpleRegIOobject(Foam::debug::addOptimisationObject, name)
|
::Foam::simpleRegIOobject(Foam::debug::addOptimisationObject, name)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
virtual ~addstopAtWriteNowSignalToOpt()
|
virtual ~addstopAtWriteNowSignalToOpt() = default;
|
||||||
{}
|
|
||||||
|
|
||||||
virtual void readData(Foam::Istream& is)
|
virtual void readData(Foam::Istream& is)
|
||||||
{
|
{
|
||||||
@ -73,12 +76,7 @@ addstopAtWriteNowSignalToOpt addstopAtWriteNowSignalToOpt_
|
|||||||
"stopAtWriteNowSignal"
|
"stopAtWriteNowSignal"
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
} // end of namespace Foam
|
||||||
|
|
||||||
|
|
||||||
Foam::Time const* Foam::sigStopAtWriteNow::runTimePtr_ = nullptr;
|
|
||||||
|
|
||||||
struct sigaction Foam::sigStopAtWriteNow::oldAction_;
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
@ -93,16 +91,15 @@ void Foam::sigStopAtWriteNow::sigHandler(int)
|
|||||||
<< abort(FatalError);
|
<< abort(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update jobInfo file
|
jobInfo.signalEnd(); // Update jobInfo file
|
||||||
jobInfo.signalEnd();
|
|
||||||
|
|
||||||
|
if (runTimePtr_)
|
||||||
|
{
|
||||||
Info<< "sigStopAtWriteNow :"
|
Info<< "sigStopAtWriteNow :"
|
||||||
<< " setting up write and stop at end of the next iteration"
|
<< " setting up write and stop at end of the next iteration"
|
||||||
<< nl << endl;
|
<< nl << endl;
|
||||||
runTimePtr_->stopAt(Time::saWriteNow);
|
runTimePtr_->stopAt(Time::saWriteNow);
|
||||||
|
}
|
||||||
//// Throw signal (to old handler)
|
|
||||||
//raise(signal_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -112,15 +109,9 @@ Foam::sigStopAtWriteNow::sigStopAtWriteNow()
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
Foam::sigStopAtWriteNow::sigStopAtWriteNow
|
Foam::sigStopAtWriteNow::sigStopAtWriteNow(const Time& runTime, bool verbose)
|
||||||
(
|
|
||||||
const bool verbose,
|
|
||||||
const Time& runTime
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
// Store runTime
|
runTimePtr_ = &runTime; // Store runTime
|
||||||
runTimePtr_ = &runTime;
|
|
||||||
|
|
||||||
set(verbose);
|
set(verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +135,7 @@ Foam::sigStopAtWriteNow::~sigStopAtWriteNow()
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
void Foam::sigStopAtWriteNow::set(const bool verbose)
|
void Foam::sigStopAtWriteNow::set(bool verbose)
|
||||||
{
|
{
|
||||||
if (signal_ > 0)
|
if (signal_ > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -83,7 +83,7 @@ public:
|
|||||||
sigStopAtWriteNow();
|
sigStopAtWriteNow();
|
||||||
|
|
||||||
//- Construct from components
|
//- Construct from components
|
||||||
sigStopAtWriteNow(const bool verbose, const Time& runTime);
|
sigStopAtWriteNow(const Time& runTime, bool verbose=false);
|
||||||
|
|
||||||
|
|
||||||
//- Destructor
|
//- Destructor
|
||||||
@ -93,7 +93,7 @@ public:
|
|||||||
// Member functions
|
// Member functions
|
||||||
|
|
||||||
//- (re)set signal catcher
|
//- (re)set signal catcher
|
||||||
static void set(const bool verbose);
|
static void set(bool verbose=false);
|
||||||
|
|
||||||
//- Is active?
|
//- Is active?
|
||||||
bool active() const;
|
bool active() const;
|
||||||
|
|||||||
@ -31,14 +31,19 @@ License
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
|
||||||
{
|
|
||||||
// Signal number to catch
|
// Signal number to catch
|
||||||
int sigWriteNow::signal_
|
int Foam::sigWriteNow::signal_
|
||||||
(
|
(
|
||||||
debug::optimisationSwitch("writeNowSignal", -1)
|
Foam::debug::optimisationSwitch("writeNowSignal", -1)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Foam::Time* Foam::sigWriteNow::runTimePtr_ = nullptr;
|
||||||
|
|
||||||
|
struct sigaction Foam::sigWriteNow::oldAction_;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
|
||||||
// Register re-reader
|
// Register re-reader
|
||||||
class addwriteNowSignalToOpt
|
class addwriteNowSignalToOpt
|
||||||
@ -53,8 +58,7 @@ public:
|
|||||||
::Foam::simpleRegIOobject(Foam::debug::addOptimisationObject, name)
|
::Foam::simpleRegIOobject(Foam::debug::addOptimisationObject, name)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
virtual ~addwriteNowSignalToOpt()
|
virtual ~addwriteNowSignalToOpt() = default;
|
||||||
{}
|
|
||||||
|
|
||||||
virtual void readData(Foam::Istream& is)
|
virtual void readData(Foam::Istream& is)
|
||||||
{
|
{
|
||||||
@ -70,24 +74,19 @@ public:
|
|||||||
|
|
||||||
addwriteNowSignalToOpt addwriteNowSignalToOpt_("writeNowSignal");
|
addwriteNowSignalToOpt addwriteNowSignalToOpt_("writeNowSignal");
|
||||||
|
|
||||||
}
|
} // end of namespace Foam
|
||||||
|
|
||||||
|
|
||||||
Foam::Time* Foam::sigWriteNow::runTimePtr_ = nullptr;
|
|
||||||
|
|
||||||
struct sigaction Foam::sigWriteNow::oldAction_;
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
void Foam::sigWriteNow::sigHandler(int)
|
void Foam::sigWriteNow::sigHandler(int)
|
||||||
{
|
{
|
||||||
|
if (runTimePtr_)
|
||||||
|
{
|
||||||
Info<< "sigWriteNow :"
|
Info<< "sigWriteNow :"
|
||||||
<< " setting up write at end of the next iteration" << nl << endl;
|
<< " setting up write at end of the next iteration" << nl << endl;
|
||||||
runTimePtr_->writeOnce();
|
runTimePtr_->writeOnce();
|
||||||
|
}
|
||||||
//// Throw signal (to old handler)
|
|
||||||
//raise(signal_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -97,11 +96,9 @@ Foam::sigWriteNow::sigWriteNow()
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
Foam::sigWriteNow::sigWriteNow(const bool verbose, Time& runTime)
|
Foam::sigWriteNow::sigWriteNow(Time& runTime, bool verbose)
|
||||||
{
|
{
|
||||||
// Store runTime
|
runTimePtr_ = &runTime; // Store runTime
|
||||||
runTimePtr_ = &runTime;
|
|
||||||
|
|
||||||
set(verbose);
|
set(verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +122,7 @@ Foam::sigWriteNow::~sigWriteNow()
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
void Foam::sigWriteNow::set(const bool verbose)
|
void Foam::sigWriteNow::set(bool verbose)
|
||||||
{
|
{
|
||||||
if (signal_ >= 0)
|
if (signal_ >= 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -83,7 +83,7 @@ public:
|
|||||||
sigWriteNow();
|
sigWriteNow();
|
||||||
|
|
||||||
//- Construct from components
|
//- Construct from components
|
||||||
sigWriteNow(const bool verbose, Time& runTime);
|
sigWriteNow(Time& runTime, bool verbose=false);
|
||||||
|
|
||||||
|
|
||||||
//- Destructor
|
//- Destructor
|
||||||
@ -92,11 +92,12 @@ public:
|
|||||||
|
|
||||||
// Member functions
|
// Member functions
|
||||||
|
|
||||||
//- (re)set signal catcher
|
|
||||||
static void set(const bool verbose);
|
|
||||||
|
|
||||||
//- Is active?
|
//- Is active?
|
||||||
bool active() const;
|
bool active() const;
|
||||||
|
|
||||||
|
//- (re)set signal catcher
|
||||||
|
static void set(bool verbose=false);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -437,8 +437,8 @@ Foam::Time::Time
|
|||||||
purgeWrite_(0),
|
purgeWrite_(0),
|
||||||
subCycling_(0),
|
subCycling_(0),
|
||||||
writeOnce_(false),
|
writeOnce_(false),
|
||||||
sigWriteNow_(true, *this),
|
sigWriteNow_(*this, true),
|
||||||
sigStopAtWriteNow_(true, *this),
|
sigStopAtWriteNow_(*this, true),
|
||||||
|
|
||||||
writeFormat_(IOstream::ASCII),
|
writeFormat_(IOstream::ASCII),
|
||||||
writeVersion_(IOstream::currentVersion),
|
writeVersion_(IOstream::currentVersion),
|
||||||
@ -506,8 +506,8 @@ Foam::Time::Time
|
|||||||
purgeWrite_(0),
|
purgeWrite_(0),
|
||||||
subCycling_(0),
|
subCycling_(0),
|
||||||
writeOnce_(false),
|
writeOnce_(false),
|
||||||
sigWriteNow_(true, *this),
|
sigWriteNow_(*this, true),
|
||||||
sigStopAtWriteNow_(true, *this),
|
sigStopAtWriteNow_(*this, true),
|
||||||
|
|
||||||
writeFormat_(IOstream::ASCII),
|
writeFormat_(IOstream::ASCII),
|
||||||
writeVersion_(IOstream::currentVersion),
|
writeVersion_(IOstream::currentVersion),
|
||||||
@ -585,8 +585,8 @@ Foam::Time::Time
|
|||||||
purgeWrite_(0),
|
purgeWrite_(0),
|
||||||
subCycling_(0),
|
subCycling_(0),
|
||||||
writeOnce_(false),
|
writeOnce_(false),
|
||||||
sigWriteNow_(true, *this),
|
sigWriteNow_(*this, true),
|
||||||
sigStopAtWriteNow_(true, *this),
|
sigStopAtWriteNow_(*this, true),
|
||||||
|
|
||||||
writeFormat_(IOstream::ASCII),
|
writeFormat_(IOstream::ASCII),
|
||||||
writeVersion_(IOstream::currentVersion),
|
writeVersion_(IOstream::currentVersion),
|
||||||
|
|||||||
@ -145,9 +145,13 @@ bool Foam::functionObjects::runTimePostProcessing::write()
|
|||||||
Info<< type() << " " << name() << " output:" << nl
|
Info<< type() << " " << name() << " output:" << nl
|
||||||
<< " Constructing scene" << endl;
|
<< " Constructing scene" << endl;
|
||||||
|
|
||||||
// Unset any floating point trapping (some low-level rendering functionality
|
// Unset any floating point trapping
|
||||||
// does not like it)
|
// (some low-level rendering functionality does not like it)
|
||||||
sigFpe::unset(false);
|
const bool oldFpe = sigFpe::active();
|
||||||
|
if (oldFpe)
|
||||||
|
{
|
||||||
|
sigFpe::unset();
|
||||||
|
}
|
||||||
|
|
||||||
// Initialise render window
|
// Initialise render window
|
||||||
auto renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
|
auto renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
|
||||||
@ -234,8 +238,11 @@ bool Foam::functionObjects::runTimePostProcessing::write()
|
|||||||
surfaces_[i].clear();
|
surfaces_[i].clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset any floating point trapping
|
// Restore floating point trapping
|
||||||
sigFpe::set(false);
|
if (oldFpe)
|
||||||
|
{
|
||||||
|
sigFpe::set();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user