Skip to content

Commit f634198

Browse files
andrea-franceschiniAndrea Franceschinicastelletto1
authored
Creating a default set of floating point exceptions (#199)
* Setting a default set of fp exceptions * Avoid clang optimization in testFloatingPointExceptions * Updating LC hostconfig tpl location to 2020-09-18 Co-authored-by: Andrea Franceschini <[email protected]> Co-authored-by: Nicola Castelletto <[email protected]>
1 parent 160e94e commit f634198

File tree

6 files changed

+27
-17
lines changed

6 files changed

+27
-17
lines changed

host-configs/LLNL/[email protected]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ set(CONFIG_NAME "lassen-clang@upstream" CACHE PATH "")
22

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

77
set(ENABLE_UMPIRE ON CACHE BOOL "")
88
set(ENABLE_CHAI ON CACHE BOOL "")

host-configs/LLNL/[email protected]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set(CONFIG_NAME "[email protected]" CACHE PATH "")
33
# Set up the tpls
44
# These were probably built with clang (no guarantee that they would work)
55
set(GEOSX_TPL_ROOT_DIR /usr/gapps/GEOSX/thirdPartyLibs CACHE PATH "")
6-
set(GEOSX_TPL_DIR ${GEOSX_TPL_ROOT_DIR}/2020-08-05/install-${CONFIG_NAME}-release CACHE PATH "")
6+
set(GEOSX_TPL_DIR ${GEOSX_TPL_ROOT_DIR}/2020-09-18/install-${CONFIG_NAME}-release CACHE PATH "")
77

88
set(ENABLE_UMPIRE ON CACHE BOOL "")
99
set(ENABLE_CHAI ON CACHE BOOL "")

host-configs/LLNL/quartz-base.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ set(MPIEXEC /usr/bin/srun CACHE PATH "")
2323
set(MPIEXEC_NUMPROC_FLAG "-n" CACHE STRING "")
2424

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

2828
set(ENABLE_UMPIRE ON CACHE BOOL "")
2929
set(ENABLE_CHAI ON CACHE BOOL "")

src/system.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,11 @@ void resetSignalHandling()
506506
}
507507
}
508508

509+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
510+
int getDefaultFloatingPointExceptions()
511+
{
512+
return ( FE_DIVBYZERO | FE_OVERFLOW | FE_INVALID );
513+
}
509514

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

521524
if( fegetenv( &fenv ))
522525
{
523526
return -1;
524527
}
525-
oldExcepts = fenv.__control & FE_ALL_EXCEPT;
528+
// all previous masks
529+
int const oldExcepts = fenv.__control & FE_ALL_EXCEPT;
526530

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

550552
if( fegetenv( &fenv ))
551553
{
552554
return -1;
553555
}
554-
oldExcepts = fenv.__control & FE_ALL_EXCEPT;
556+
// all previous masks
557+
int const oldExcepts = ~( fenv.__control & FE_ALL_EXCEPT );
555558

556559
// mask
557560
fenv.__control |= newExcepts;
@@ -575,13 +578,9 @@ void setFPE()
575578
_MM_SET_DENORMALS_ZERO_MODE( _MM_DENORMALS_ZERO_ON );
576579
#endif
577580
#if defined(__x86_64__)
578-
enableFloatingPointExceptions( FE_DIVBYZERO | FE_OVERFLOW | FE_INVALID );
581+
enableFloatingPointExceptions( getDefaultFloatingPointExceptions() );
579582
#endif
580583
}
581584

582-
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
583-
int getAllExceptionsMask()
584-
{ return FE_ALL_EXCEPT; }
585-
586585
} // namespace system
587586
} // namespace LvArray

src/system.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,25 @@ void setSignalHandling( void (* handler)( int ) );
8282
*/
8383
void resetSignalHandling();
8484

85+
/**
86+
* @brief Get the default set of exceptions to check.
87+
* @return The default set of exceptions.
88+
*/
89+
int getDefaultFloatingPointExceptions();
90+
8591
/**
8692
* @brief A wrapper around @c feenableexcept that work on OSX.
8793
* @param exceptions The set of floating point exceptions to enable.
8894
* @return The old exception mask or -1 if there was an error.
8995
*/
90-
int enableFloatingPointExceptions( int const exceptions );
96+
int enableFloatingPointExceptions( int const exceptions = getDefaultFloatingPointExceptions() );
9197

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

99105
/**
100106
* @brief Sets the floating point environment.
@@ -114,7 +120,7 @@ class FloatingPointExceptionGuard
114120
* @brief Disable the floating point exceptions given by @p exceptions.
115121
* @param exceptions The floating point exceptions to disable.
116122
*/
117-
FloatingPointExceptionGuard( int const exceptions ):
123+
FloatingPointExceptionGuard( int const exceptions = getDefaultFloatingPointExceptions() ):
118124
m_previousExceptions( disableFloatingPointExceptions( exceptions ) )
119125
{}
120126

unitTests/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ blt_add_executable( NAME testFloatingPointExceptions
8787
OUTPUT_DIR ${TEST_OUTPUT_DIRECTORY}
8888
DEPENDS_ON gtest lvarray ${lvarray_dependencies} )
8989

90+
# Need to avoid optimization to catch invalid operations
91+
if( APPLE AND ${CMAKE_CXX_COMPILER} MATCHES "clang" )
92+
set_source_files_properties( testFloatingPointExceptionsHelpers.cpp PROPERTIES COMPILE_FLAGS "-O0" )
93+
endif()
94+
9095
target_include_directories( testFloatingPointExceptions PUBLIC ${CMAKE_CURRENT_LIST_DIR}/../src )
9196

9297
blt_add_test( NAME testFloatingPointExceptions

0 commit comments

Comments
 (0)