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
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -18,6 +18,10 @@
#include <stdio.h>
#include <stdlib.h>

#if defined(LAMMPS_TRAP_FPE) && defined(_GNU_SOURCE)
#include <fenv.h>
#endif

using namespace LAMMPS_NS;

/* ----------------------------------------------------------------------
@@ -28,6 +32,18 @@ int main(int argc, char **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
  try {
    LAMMPS *lammps = new LAMMPS(argc,argv,MPI_COMM_WORLD);