ForestClaw / forestclaw

Quadtree/octree adaptive PDE solver based based on p4est.
http://www.forestclaw.org
BSD 2-Clause "Simplified" License
58 stars 21 forks source link

FPE proposal #201

Open donnaaboise opened 2 years ago

donnaaboise commented 2 years ago

This snippet tests a DYI approach to handling exceptions for the M1 :

Ideas for code taken from

https://developer.apple.com/forums/thread/689159 and https://stackoverflow.com/questions/69059981/how-to-trap-floating-point-exceptions-on-m1-macs

donnaaboise commented 2 years ago

Maybe the easiest thing to do is just include a file fclaw_exceptions.{c,h} but don't include it in the compiled code. If a user wants exception handling and doesn't have it on their system, we can suggest they include this in their example. That way, we aren't responsible for any build issues that might come up, or any dubious behavior this DYI exception handling might create.

Only drawback to this approach is that we do have option --trap-fpe which should then either be disabled, or only do something if "FCLAW_HAVE_FEENABLEEXCEPT` is true (is this easy to check in the build system)? If the user doesn't have this, we could virtualize an exception handler and then let the user define their own (e.g. the one proposed here).

My proposal is, then :

if (--trap_fpe)
{
#if FCLAW_HAVE_FEENABLEEXCEPT
   /* Call system version */
    feenableexcept(INVALID | OVERFLOW | UNDERFLOW | ...)
#else
   /* Call user-defined virtualized version (e.g. the one proposed here) */
   fclaw_vt->feenableexcept()
#endif
}

If the user hasn't overridden the virtual feenableexept(), alert them that they do not appear to have feenableexcept on their system and should consider our DYI option, at their own risk, of course.