Do Stan programs have an "exit point"?

Is there some way to call C++ code after sampling is completed, just prior to a Stan program’s exit? I’m writing some “glue” C++ code so that I can use a Fortran library in Stan, with the library having a few “cleanup” subroutines that it’d prefer I call before program completion.

One thought was to wrap the Fortran functionality into a C++ class that calls the cleanup code in its destructor, but I’m not sure if maybe there’s another way of going about this.

There’s always this: https://en.cppreference.com/w/cpp/utility/program/atexit

1 Like

Cool, wasn’t aware of this! Thanks!