Tempus Version of the Day
Time Integration
Loading...
Searching...
No Matches
Tempus_UnitTestMainUtils.hpp
Go to the documentation of this file.
1//@HEADER
2// *****************************************************************************
3// Tempus: Time Integration and Sensitivity Analysis Package
4//
5// Copyright 2017 NTESS and the Tempus contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8//@HEADER
9
10#ifndef TEMPUS_UNIT_TEST_MAIN_UTILS_HPP
11#define TEMPUS_UNIT_TEST_MAIN_UTILS_HPP
12
13#if defined(__linux__) && defined(__GNUC__) && !defined(__INTEL_COMPILER)
14#include <fenv.h>
15#elif defined(__APPLE__) && defined(__GNUC__) && defined(__SSE__)
16#include <xmmintrin.h>
17#endif
18
19namespace Tempus_Test {
20
29{
30#if defined(__APPLE__) && defined(__GNUC__) && defined(__SSE__)
31 static int eMask = _MM_GET_EXCEPTION_MASK();
32#endif
33
34 if (enableFPE) {
35#if defined(__linux__) && defined(__GNUC__) && !defined(__INTEL_COMPILER)
36 feenableexcept(FE_DIVBYZERO | FE_OVERFLOW | FE_INVALID);
37#elif defined(__APPLE__) && defined(__GNUC__) && defined(__SSE__)
38 eMask = _MM_GET_EXCEPTION_MASK(); // Save current eMask so we can disable.
39 _MM_SET_EXCEPTION_MASK(eMask & ~_MM_MASK_DIV_ZERO & ~_MM_MASK_OVERFLOW &
40 ~_MM_MASK_INVALID);
41#endif
42 }
43 else {
44#if defined(__linux__) && defined(__GNUC__) && !defined(__INTEL_COMPILER)
45 fedisableexcept(FE_DIVBYZERO | FE_OVERFLOW | FE_INVALID);
46#elif defined(__APPLE__) && defined(__GNUC__) && defined(__SSE__)
47 _MM_SET_EXCEPTION_MASK(eMask);
48#endif
49 }
50}
51
52} // namespace Tempus_Test
53
54#endif // TEMPUS_UNIT_TEST_MAIN_UTILS_HPP
void enableFPE(bool enableFPE)
Enable Floating Point Exceptions.