+ static bool already_cleaned_up = false;
+ if (already_cleaned_up)
+ return; // to avoid double cleaning by java and C
+ already_cleaned_up = true;
+ if (not EngineImpl::instance_) {
+ simix_global->destroy_maestro();
+ simix_global->destroy_context_factory();
+ return; // Nothing more to shutdown
+ }
+ XBT_DEBUG("EngineImpl::shutdown() called. Simulation's over.");
+
+ if (instance_->has_actors_to_run() && simgrid_get_clock() <= 0.0) {
+ XBT_CRITICAL(" ");
+ XBT_CRITICAL("The time is still 0, and you still have processes ready to run.");
+ XBT_CRITICAL("It seems that you forgot to run the simulation that you setup.");
+ xbt_die("Bailing out to avoid that stop-before-start madness. Please fix your code.");
+ }
+
+#if HAVE_SMPI
+ if (not instance_->actor_list_.empty()) {
+ if (smpi_process()->initialized()) {
+ xbt_die("Process exited without calling MPI_Finalize - Killing simulation");
+ } else {
+ XBT_WARN("Process called exit when leaving - Skipping cleanups");
+ return;
+ }
+ }
+#endif
+
+ /* Kill all actors (but maestro) */
+ simix_global->get_maestro()->kill_all();
+ instance_->run_all_actors();
+ instance_->empty_trash();
+
+ /* Let's free maestro now */
+ simix_global->destroy_maestro();
+
+ /* Finish context module and SURF */
+ simix_global->destroy_context_factory();