CmPA / iPic3D

Particle-in-Cell code using the implicit moment method
72 stars 55 forks source link

Support -fno-exceptions #42

Open alecjohnson opened 11 years ago

alecjohnson commented 11 years ago

I want to check in code to eliminate the use of exceptions in iPic3D.

Allowing exceptions has performance penalties. In particular, while developing an array class for iPic3D, I observed that looping through array elements took three times as long if the body of the destructor of the array class was nonempty. This performance penalty disappeared when I compiled with the -fno-exceptions flag.

I see no reason to retain exception handling in iPic3D. This is not an event-driven application. All current use of exceptions is used to generate error messages, which can be handled adequately with simple calls to eprintf(). Therefore, I am going through the code and replacing each throwing of an exception such as

  PSK::OutputException e("make_dataset fails for " + tag, "HDF5OutputAdaptor::write(double* array)");
  throw e;

with printing of an error message such as

  eprintf("make_dataset fails for %s", tag.c_str());

Note that the eprintf() macro automatically prints file, line number, and method name, so there is no need to add any of that information to the call to eprintf().

In my initial implementation of this change I simply comment out all occurences of try and all catch blocks and all calls to throw, replacing each call to throw with a call to eprintf. I leave it for later to decide whether to completely eliminate the Exception and OutputException classes in the PSK namespace or whether for some reason to revert to supporting the possibility of exceptions via pre-processor branching directives.