Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion host-configs/LLNL/lassen-clang@upstream.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ set(CONFIG_NAME "lassen-clang@upstream" CACHE PATH "")

# Set up the tpls
set(GEOSX_TPL_ROOT_DIR /usr/gapps/GEOSX/thirdPartyLibs CACHE PATH "")
set(GEOSX_TPL_DIR ${GEOSX_TPL_ROOT_DIR}/2020-08-05/install-${CONFIG_NAME}-release CACHE PATH "")
set(GEOSX_TPL_DIR ${GEOSX_TPL_ROOT_DIR}/2020-09-18/install-${CONFIG_NAME}-release CACHE PATH "")

set(ENABLE_UMPIRE ON CACHE BOOL "")
set(ENABLE_CHAI ON CACHE BOOL "")
Expand Down
2 changes: 1 addition & 1 deletion host-configs/LLNL/lassen-gcc@8.3.1.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(CONFIG_NAME "lassen-gcc@8.3.1" CACHE PATH "")
# Set up the tpls
# These were probably built with clang (no guarantee that they would work)
set(GEOSX_TPL_ROOT_DIR /usr/gapps/GEOSX/thirdPartyLibs CACHE PATH "")
set(GEOSX_TPL_DIR ${GEOSX_TPL_ROOT_DIR}/2020-08-05/install-${CONFIG_NAME}-release CACHE PATH "")
set(GEOSX_TPL_DIR ${GEOSX_TPL_ROOT_DIR}/2020-09-18/install-${CONFIG_NAME}-release CACHE PATH "")

set(ENABLE_UMPIRE ON CACHE BOOL "")
set(ENABLE_CHAI ON CACHE BOOL "")
Expand Down
2 changes: 1 addition & 1 deletion host-configs/LLNL/quartz-base.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ set(MPIEXEC /usr/bin/srun CACHE PATH "")
set(MPIEXEC_NUMPROC_FLAG "-n" CACHE STRING "")

set(GEOSX_TPL_ROOT_DIR /usr/gapps/GEOSX/thirdPartyLibs CACHE PATH "")
set(GEOSX_TPL_DIR ${GEOSX_TPL_ROOT_DIR}/2020-08-05/install-${CONFIG_NAME}-release CACHE PATH "")
set(GEOSX_TPL_DIR ${GEOSX_TPL_ROOT_DIR}/2020-09-18/install-${CONFIG_NAME}-release CACHE PATH "")

set(ENABLE_UMPIRE ON CACHE BOOL "")
set(ENABLE_CHAI ON CACHE BOOL "")
Expand Down
21 changes: 10 additions & 11 deletions src/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,11 @@ void resetSignalHandling()
}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int getDefaultFloatingPointExceptions()
{
return ( FE_DIVBYZERO | FE_OVERFLOW | FE_INVALID );
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int enableFloatingPointExceptions( int const exceptions )
Expand All @@ -515,14 +520,13 @@ int enableFloatingPointExceptions( int const exceptions )
// http://www-personal.umich.edu/~williams/archive/computation/fe-handling-example.c
static fenv_t fenv;
int const newExcepts = exceptions & FE_ALL_EXCEPT;
// previous masks
int oldExcepts;

if( fegetenv( &fenv ))
{
return -1;
}
oldExcepts = fenv.__control & FE_ALL_EXCEPT;
// all previous masks
int const oldExcepts = fenv.__control & FE_ALL_EXCEPT;

// unmask
fenv.__control &= ~newExcepts;
Expand All @@ -544,14 +548,13 @@ int disableFloatingPointExceptions( int const exceptions )
// http://www-personal.umich.edu/~williams/archive/computation/fe-handling-example.c
static fenv_t fenv;
int const newExcepts = exceptions & FE_ALL_EXCEPT;
// all previous masks
int oldExcepts;

if( fegetenv( &fenv ))
{
return -1;
}
oldExcepts = fenv.__control & FE_ALL_EXCEPT;
// all previous masks
int const oldExcepts = ~( fenv.__control & FE_ALL_EXCEPT );

// mask
fenv.__control |= newExcepts;
Expand All @@ -575,13 +578,9 @@ void setFPE()
_MM_SET_DENORMALS_ZERO_MODE( _MM_DENORMALS_ZERO_ON );
#endif
#if defined(__x86_64__)
enableFloatingPointExceptions( FE_DIVBYZERO | FE_OVERFLOW | FE_INVALID );
enableFloatingPointExceptions( getDefaultFloatingPointExceptions() );
#endif
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int getAllExceptionsMask()
{ return FE_ALL_EXCEPT; }

} // namespace system
} // namespace LvArray
12 changes: 9 additions & 3 deletions src/system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,25 @@ void setSignalHandling( void (* handler)( int ) );
*/
void resetSignalHandling();

/**
* @brief Get the default set of exceptions to check.
* @return The default set of exceptions.
*/
int getDefaultFloatingPointExceptions();

/**
* @brief A wrapper around @c feenableexcept that work on OSX.
* @param exceptions The set of floating point exceptions to enable.
* @return The old exception mask or -1 if there was an error.
*/
int enableFloatingPointExceptions( int const exceptions );
int enableFloatingPointExceptions( int const exceptions = getDefaultFloatingPointExceptions() );

/**
* @brief A wrapper around @c fedisableexcept that work on OSX.
* @param exceptions The set of floating point exceptions to disable.
* @return The old exception mask or -1 if there was an error.
*/
int disableFloatingPointExceptions( int const exceptions );
int disableFloatingPointExceptions( int const exceptions = getDefaultFloatingPointExceptions() );

/**
* @brief Sets the floating point environment.
Expand All @@ -114,7 +120,7 @@ class FloatingPointExceptionGuard
* @brief Disable the floating point exceptions given by @p exceptions.
* @param exceptions The floating point exceptions to disable.
*/
FloatingPointExceptionGuard( int const exceptions ):
FloatingPointExceptionGuard( int const exceptions = getDefaultFloatingPointExceptions() ):
m_previousExceptions( disableFloatingPointExceptions( exceptions ) )
{}

Expand Down
5 changes: 5 additions & 0 deletions unitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ blt_add_executable( NAME testFloatingPointExceptions
OUTPUT_DIR ${TEST_OUTPUT_DIRECTORY}
DEPENDS_ON gtest lvarray ${lvarray_dependencies} )

# Need to avoid optimization to catch invalid operations
if( APPLE AND ${CMAKE_CXX_COMPILER} MATCHES "clang" )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh is this because APPLE + "clang" doesn't respect the no-inline attribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so ... I am not a Mac expect!

set_source_files_properties( testFloatingPointExceptionsHelpers.cpp PROPERTIES COMPILE_FLAGS "-O0" )
endif()

target_include_directories( testFloatingPointExceptions PUBLIC ${CMAKE_CURRENT_LIST_DIR}/../src )

blt_add_test( NAME testFloatingPointExceptions
Expand Down