Skip to content
Snippets Groups Projects
Commit a477f264 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

add support for trapping floating point exception as an optional compile time feature

we may make this a run time setting by connecting this code to a command.
parent b1b399d5
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,10 @@ ...@@ -18,6 +18,10 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#if defined(LAMMPS_TRAP_FPE) && defined(_GNU_SOURCE)
#include <fenv.h>
#endif
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
...@@ -28,6 +32,18 @@ int main(int argc, char **argv) ...@@ -28,6 +32,18 @@ int main(int argc, char **argv)
{ {
MPI_Init(&argc,&argv); MPI_Init(&argc,&argv);
// enable trapping selected floating point exceptions.
// this uses GNU extensions and is only tested on Linux
// therefore we make it depend on -D_GNU_SOURCE, too.
#if defined(LAMMPS_TRAP_FPE) && defined(_GNU_SOURCE)
fesetenv(FE_NOMASK_ENV);
fedisableexcept(FE_ALL_EXCEPT);
feenableexcept(FE_DIVBYZERO);
feenableexcept(FE_INVALID);
feenableexcept(FE_OVERFLOW);
#endif
#ifdef LAMMPS_EXCEPTIONS #ifdef LAMMPS_EXCEPTIONS
try { try {
LAMMPS *lammps = new LAMMPS(argc,argv,MPI_COMM_WORLD); LAMMPS *lammps = new LAMMPS(argc,argv,MPI_COMM_WORLD);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment