mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: sigFpe: split off Nan handling
This commit is contained in:
@ -51,6 +51,31 @@ License
|
|||||||
struct sigaction Foam::sigFpe::oldAction_;
|
struct sigaction Foam::sigFpe::oldAction_;
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::sigFpe::fillSignallingNan(UList<scalar>& lst)
|
||||||
|
{
|
||||||
|
#ifdef LINUX
|
||||||
|
|
||||||
|
// initialize to signalling NaN
|
||||||
|
# ifdef WM_SP
|
||||||
|
|
||||||
|
const uint32_t sNAN = 0x7ff7fffflu;
|
||||||
|
uint32_t* dPtr = reinterpret_cast<uint32_t*>(lst.begin());
|
||||||
|
|
||||||
|
# else
|
||||||
|
|
||||||
|
const uint64_t sNAN = 0x7ff7ffffffffffffllu;
|
||||||
|
uint64_t* dPtr = reinterpret_cast<uint64_t*>(lst.begin());
|
||||||
|
|
||||||
|
# endif
|
||||||
|
|
||||||
|
forAll(lst, i)
|
||||||
|
{
|
||||||
|
*dPtr++ = sNAN;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef LINUX
|
#ifdef LINUX
|
||||||
|
|
||||||
void *(*Foam::sigFpe::oldMallocHook_)(size_t, const void *) = NULL;
|
void *(*Foam::sigFpe::oldMallocHook_)(size_t, const void *) = NULL;
|
||||||
@ -66,24 +91,8 @@ void* Foam::sigFpe::nanMallocHook_(size_t size, const void *caller)
|
|||||||
result = malloc(size);
|
result = malloc(size);
|
||||||
|
|
||||||
// initialize to signalling NaN
|
// initialize to signalling NaN
|
||||||
# ifdef WM_SP
|
UList<scalar> lst(reinterpret_cast<scalar*>(result), size/sizeof(scalar));
|
||||||
|
fillSignallingNan(lst);
|
||||||
const uint32_t sNAN = 0x7ff7fffflu;
|
|
||||||
uint32_t* dPtr = reinterpret_cast<uint32_t*>(result);
|
|
||||||
|
|
||||||
# else
|
|
||||||
|
|
||||||
const uint64_t sNAN = 0x7ff7ffffffffffffllu;
|
|
||||||
uint64_t* dPtr = reinterpret_cast<uint64_t*>(result);
|
|
||||||
|
|
||||||
# endif
|
|
||||||
|
|
||||||
const size_t nScalars = size/sizeof(scalar);
|
|
||||||
for (size_t i = 0; i < nScalars; ++i)
|
|
||||||
{
|
|
||||||
*dPtr++ = sNAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Restore our own hooks
|
// Restore our own hooks
|
||||||
__malloc_hook = nanMallocHook_;
|
__malloc_hook = nanMallocHook_;
|
||||||
|
|||||||
@ -2,7 +2,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 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -53,6 +53,8 @@ SourceFiles
|
|||||||
# define LINUX_GNUC
|
# define LINUX_GNUC
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "UList.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
@ -108,6 +110,10 @@ public:
|
|||||||
//- 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
|
||||||
void set(const bool verbose);
|
void set(const bool verbose);
|
||||||
|
|
||||||
|
//- Helper: fill block of data with NaN
|
||||||
|
static void fillSignallingNan(UList<scalar>&);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user