Allow runAsMainSingleModule to be called more than once
[alexxy/gromacs.git] / src / gromacs / commandline / cmdlineinit.cpp
index aef6121bc39f3c44937840598a601c1df3812674..003ad846c901535989875ef5900e9af1d69eeafd 100644 (file)
  * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \ingroup module_commandline
  */
-#include "gromacs/commandline/cmdlineinit.h"
+#include "gmxpre.h"
+
+#include "cmdlineinit.h"
+
+#include "config.h"
 
 #include <cstring>
 
 #include <boost/scoped_ptr.hpp>
 
-#include "gromacs/legacyheaders/network.h"
-#include "gromacs/legacyheaders/smalloc.h"
-#include "gromacs/legacyheaders/types/commrec.h"
-
 #include "gromacs/commandline/cmdlinemodulemanager.h"
 #include "gromacs/commandline/cmdlineprogramcontext.h"
+#include "gromacs/legacyheaders/network.h"
+#include "gromacs/legacyheaders/types/commrec.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/init.h"
 #include "gromacs/utility/programcontext.h"
+#include "gromacs/utility/smalloc.h"
 
 namespace gmx
 {
@@ -137,6 +140,13 @@ void finalizeForCommandLine()
     g_commandLineContext.reset();
 }
 
+int processExceptionAtExitForCommandLine(const std::exception &ex)
+{
+    int rc = processExceptionAtExit(ex); //Currently this aborts for GMX_LIB_MPI
+    finalizeForCommandLine();            //thus this MPI_Finalize doesn't matter
+    return rc;
+}
+
 int runCommandLineModule(int argc, char *argv[],
                          CommandLineModuleInterface *module)
 {