Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Convert enum class SmpiPrivStrategies tu upper case.
[simgrid.git] / src / simix / smx_global.cpp
1 /* Copyright (c) 2007-2018. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "mc/mc.h"
7 #include "simgrid/s4u/Engine.hpp"
8 #include "simgrid/s4u/Host.hpp"
9 #include "simgrid/sg_config.hpp"
10 #include "smx_private.hpp"
11 #include "src/kernel/activity/SleepImpl.hpp"
12 #include "src/kernel/activity/SynchroIo.hpp"
13 #include "src/kernel/activity/SynchroRaw.hpp"
14 #include "src/mc/mc_record.hpp"
15 #include "src/mc/mc_replay.hpp"
16 #include "src/simix/smx_host_private.hpp"
17 #include "src/smpi/include/smpi_process.hpp"
18 #include "src/surf/StorageImpl.hpp"
19 #include "src/surf/xml/platf.hpp"
20
21 #if SIMGRID_HAVE_MC
22 #include "src/mc/mc_private.hpp"
23 #include "src/mc/remote/Client.hpp"
24 #include "src/mc/remote/mc_protocol.h"
25 #endif
26
27 #if HAVE_SMPI
28 #include "src/smpi/include/private.hpp"
29 #endif
30
31 #include <boost/heap/fibonacci_heap.hpp>
32 #include <csignal>
33
34 XBT_LOG_NEW_CATEGORY(simix, "All SIMIX categories");
35 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_kernel, simix, "Logging specific to SIMIX (kernel)");
36
37 std::unique_ptr<simgrid::simix::Global> simix_global;
38
39 namespace {
40 typedef std::pair<double, smx_timer_t> TimerQelt;
41 boost::heap::fibonacci_heap<TimerQelt, boost::heap::compare<simgrid::xbt::HeapComparator<TimerQelt>>> simix_timers;
42 }
43
44 /** @brief Timer datatype */
45 class s_smx_timer_t {
46   double date = 0.0;
47
48 public:
49   decltype(simix_timers)::handle_type handle_;
50   simgrid::xbt::Task<void()> callback;
51   double getDate() { return date; }
52   s_smx_timer_t(double date, simgrid::xbt::Task<void()> callback) : date(date), callback(std::move(callback)) {}
53 };
54
55 void (*SMPI_switch_data_segment)(simgrid::s4u::ActorPtr) = nullptr;
56
57 bool _sg_do_verbose_exit = true;
58 static void inthandler(int)
59 {
60   if ( _sg_do_verbose_exit ) {
61      XBT_INFO("CTRL-C pressed. The current status will be displayed before exit (disable that behavior with option 'verbose-exit').");
62      SIMIX_display_process_status();
63   }
64   else {
65      XBT_INFO("CTRL-C pressed, exiting. Hiding the current process status since 'verbose-exit' is set to false.");
66   }
67   exit(1);
68 }
69
70 #ifndef _WIN32
71 static void segvhandler(int signum, siginfo_t* siginfo, void* /*context*/)
72 {
73   if (siginfo->si_signo == SIGSEGV && siginfo->si_code == SEGV_ACCERR) {
74     fprintf(stderr, "Access violation detected.\n"
75                     "This probably comes from a programming error in your code, or from a stack\n"
76                     "overflow. If you are certain of your code, try increasing the stack size\n"
77                     "   --cfg=contexts/stack-size=XXX (current size is %u KiB).\n"
78                     "\n"
79                     "If it does not help, this may have one of the following causes:\n"
80                     "a bug in SimGrid, a bug in the OS or a bug in a third-party libraries.\n"
81                     "Failing hardware can sometimes generate such errors too.\n"
82                     "\n"
83                     "If you think you've found a bug in SimGrid, please report it along with a\n"
84                     "Minimal Working Example (MWE) reproducing your problem and a full backtrace\n"
85                     "of the fault captured with gdb or valgrind.\n",
86             smx_context_stack_size / 1024);
87   } else  if (siginfo->si_signo == SIGSEGV) {
88     fprintf(stderr, "Segmentation fault.\n");
89 #if HAVE_SMPI
90     if (smpi_enabled() && smpi_privatize_global_variables == SmpiPrivStrategies::NONE) {
91 #if HAVE_PRIVATIZATION
92       fprintf(stderr, "Try to enable SMPI variable privatization with --cfg=smpi/privatization:yes.\n");
93 #else
94       fprintf(stderr, "Sadly, your system does not support --cfg=smpi/privatization:yes (yet).\n");
95 #endif /* HAVE_PRIVATIZATION */
96     }
97 #endif /* HAVE_SMPI */
98   }
99   std::raise(signum);
100 }
101
102 char sigsegv_stack[SIGSTKSZ];   /* alternate stack for SIGSEGV handler */
103
104 /**
105  * Install signal handler for SIGSEGV.  Check that nobody has already installed
106  * its own handler.  For example, the Java VM does this.
107  */
108 static void install_segvhandler()
109 {
110   stack_t stack;
111   stack_t old_stack;
112   stack.ss_sp = sigsegv_stack;
113   stack.ss_size = sizeof sigsegv_stack;
114   stack.ss_flags = 0;
115
116   if (sigaltstack(&stack, &old_stack) == -1) {
117     XBT_WARN("Failed to register alternate signal stack: %s", strerror(errno));
118     return;
119   }
120   if (not(old_stack.ss_flags & SS_DISABLE)) {
121     XBT_DEBUG("An alternate stack was already installed (sp=%p, size=%zu, flags=%x). Restore it.", old_stack.ss_sp,
122               old_stack.ss_size, (unsigned)old_stack.ss_flags);
123     sigaltstack(&old_stack, nullptr);
124   }
125
126   struct sigaction action;
127   struct sigaction old_action;
128   action.sa_sigaction = &segvhandler;
129   action.sa_flags = SA_ONSTACK | SA_RESETHAND | SA_SIGINFO;
130   sigemptyset(&action.sa_mask);
131
132   if (sigaction(SIGSEGV, &action, &old_action) == -1) {
133     XBT_WARN("Failed to register signal handler for SIGSEGV: %s", strerror(errno));
134     return;
135   }
136   if ((old_action.sa_flags & SA_SIGINFO) || old_action.sa_handler != SIG_DFL) {
137     XBT_DEBUG("A signal handler was already installed for SIGSEGV (%p). Restore it.",
138              (old_action.sa_flags & SA_SIGINFO) ? (void*)old_action.sa_sigaction : (void*)old_action.sa_handler);
139     sigaction(SIGSEGV, &old_action, nullptr);
140   }
141 }
142
143 #endif /* _WIN32 */
144
145 /********************************* SIMIX **************************************/
146 double SIMIX_timer_next()
147 {
148   return simix_timers.empty() ? -1.0 : simix_timers.top().first;
149 }
150
151 static void kill_process(smx_actor_t process)
152 {
153   SIMIX_process_kill(process, nullptr);
154 }
155
156
157 namespace simgrid {
158 namespace simix {
159
160 simgrid::xbt::signal<void()> onDeadlock;
161
162 simgrid::config::Flag<double> breakpoint{"simix/breakpoint",
163                                          "When non-negative, raise a SIGTRAP after given (simulated) time", -1.0};
164 }
165 }
166
167 static std::function<void()> maestro_code;
168 void SIMIX_set_maestro(void (*code)(void*), void* data)
169 {
170 #ifdef _WIN32
171   XBT_INFO("WARNING, SIMIX_set_maestro is believed to not work on windows. Please help us investigating this issue if you need that feature");
172 #endif
173   maestro_code = std::bind(code, data);
174 }
175
176 /**
177  * \ingroup SIMIX_API
178  * \brief Initialize SIMIX internal data.
179  */
180 void SIMIX_global_init(int *argc, char **argv)
181 {
182 #if SIMGRID_HAVE_MC
183   // The communication initialization is done ASAP.
184   // We need to communicate  initialization of the different layers to the model-checker.
185   simgrid::mc::Client::initialize();
186 #endif
187
188   if (not simix_global) {
189     simix_global = std::unique_ptr<simgrid::simix::Global>(new simgrid::simix::Global());
190     simix_global->maestro_process = nullptr;
191     simix_global->create_process_function = &SIMIX_process_create;
192     simix_global->kill_process_function = &kill_process;
193     simix_global->cleanup_process_function = &SIMIX_process_cleanup;
194     simix_global->mutex = xbt_os_mutex_init();
195
196     surf_init(argc, argv);      /* Initialize SURF structures */
197     SIMIX_context_mod_init();
198
199     // Either create a new context with maestro or create
200     // a context object with the current context mestro):
201     simgrid::kernel::actor::create_maestro(maestro_code);
202
203     /* Prepare to display some more info when dying on Ctrl-C pressing */
204     std::signal(SIGINT, inthandler);
205
206 #ifndef _WIN32
207     install_segvhandler();
208 #endif
209     /* register a function to be called by SURF after the environment creation */
210     sg_platf_init();
211     simgrid::s4u::on_platform_created.connect(SIMIX_post_create_environment);
212     simgrid::s4u::Host::on_creation.connect([](simgrid::s4u::Host& host) {
213       if (host.extension<simgrid::simix::Host>() == nullptr) // another callback to the same signal may have created it
214         host.extension_set<simgrid::simix::Host>(new simgrid::simix::Host());
215     });
216
217     simgrid::s4u::Storage::on_creation.connect([](simgrid::s4u::Storage& storage) {
218       sg_storage_t s = simgrid::s4u::Storage::byName(storage.get_cname());
219       xbt_assert(s != nullptr, "Storage not found for name %s", storage.get_cname());
220     });
221   }
222
223   if (simgrid::config::get_value<bool>("clean-atexit"))
224     atexit(SIMIX_clean);
225
226   if (_sg_cfg_exit_asap)
227     exit(0);
228 }
229
230 int smx_cleaned = 0;
231 /**
232  * \ingroup SIMIX_API
233  * \brief Clean the SIMIX simulation
234  *
235  * This functions remove the memory used by SIMIX
236  */
237 void SIMIX_clean()
238 {
239   if (smx_cleaned)
240     return; // to avoid double cleaning by java and C
241
242   smx_cleaned = 1;
243   XBT_DEBUG("SIMIX_clean called. Simulation's over.");
244   if (not simix_global->process_to_run.empty() && SIMIX_get_clock() <= 0.0) {
245     XBT_CRITICAL("   ");
246     XBT_CRITICAL("The time is still 0, and you still have processes ready to run.");
247     XBT_CRITICAL("It seems that you forgot to run the simulation that you setup.");
248     xbt_die("Bailing out to avoid that stop-before-start madness. Please fix your code.");
249   }
250
251 #if HAVE_SMPI
252   if (SIMIX_process_count()>0){
253     if(smpi_process()->initialized()){
254       xbt_die("Process exited without calling MPI_Finalize - Killing simulation");
255     }else{
256       XBT_WARN("Process called exit when leaving - Skipping cleanups");
257       return;
258     }
259   }
260 #endif
261
262   /* Kill all processes (but maestro) */
263   SIMIX_process_killall(simix_global->maestro_process);
264   SIMIX_context_runall();
265   SIMIX_process_empty_trash();
266
267   /* Exit the SIMIX network module */
268   SIMIX_mailbox_exit();
269
270   while (not simix_timers.empty()) {
271     delete simix_timers.top().second;
272     simix_timers.pop();
273   }
274   /* Free the remaining data structures */
275   simix_global->process_to_run.clear();
276   simix_global->process_that_ran.clear();
277   simix_global->process_to_destroy.clear();
278   simix_global->process_list.clear();
279
280   xbt_os_mutex_destroy(simix_global->mutex);
281   simix_global->mutex = nullptr;
282 #if SIMGRID_HAVE_MC
283   xbt_dynar_free(&simix_global->actors_vector);
284   xbt_dynar_free(&simix_global->dead_actors_vector);
285 #endif
286
287   /* Let's free maestro now */
288   delete simix_global->maestro_process->context;
289   simix_global->maestro_process->context = nullptr;
290   delete simix_global->maestro_process;
291   simix_global->maestro_process = nullptr;
292
293   /* Finish context module and SURF */
294   SIMIX_context_mod_exit();
295
296   surf_exit();
297
298   simix_global = nullptr;
299 }
300
301
302 /**
303  * \ingroup SIMIX_API
304  * \brief A clock (in second).
305  *
306  * \return Return the clock.
307  */
308 double SIMIX_get_clock()
309 {
310   if(MC_is_active() || MC_record_replay_is_active()){
311     return MC_process_clock_get(SIMIX_process_self());
312   }else{
313     return surf_get_clock();
314   }
315 }
316
317 /** Wake up all processes waiting for a Surf action to finish */
318 static void SIMIX_wake_processes()
319 {
320   for (auto const& model : *all_existing_models) {
321     simgrid::kernel::resource::Action* action;
322
323     XBT_DEBUG("Handling the processes whose action failed (if any)");
324     while ((action = surf_model_extract_failed_action_set(model))) {
325       XBT_DEBUG("   Handling Action %p",action);
326       SIMIX_simcall_exit(static_cast<simgrid::kernel::activity::ActivityImpl*>(action->get_data()));
327     }
328     XBT_DEBUG("Handling the processes whose action terminated normally (if any)");
329     while ((action = surf_model_extract_done_action_set(model))) {
330       XBT_DEBUG("   Handling Action %p",action);
331       if (action->get_data() == nullptr)
332         XBT_DEBUG("probably vcpu's action %p, skip", action);
333       else
334         SIMIX_simcall_exit(static_cast<simgrid::kernel::activity::ActivityImpl*>(action->get_data()));
335     }
336   }
337 }
338
339 /** Handle any pending timer */
340 static bool SIMIX_execute_timers()
341 {
342   bool result = false;
343   while (not simix_timers.empty() && SIMIX_get_clock() >= simix_timers.top().first) {
344     result = true;
345     // FIXME: make the timers being real callbacks
346     // (i.e. provide dispatchers that read and expand the args)
347     smx_timer_t timer = simix_timers.top().second;
348     simix_timers.pop();
349     try {
350       timer->callback();
351     } catch (...) {
352       xbt_die("Exception thrown ouf of timer callback");
353     }
354     delete timer;
355   }
356   return result;
357 }
358
359 /** Execute all the tasks that are queued
360  *
361  *  e.g. `.then()` callbacks of futures.
362  **/
363 static bool SIMIX_execute_tasks()
364 {
365   xbt_assert(simix_global->tasksTemp.empty());
366
367   if (simix_global->tasks.empty())
368     return false;
369
370   using std::swap;
371   do {
372     // We don't want the callbacks to modify the vector we are iterating over:
373     swap(simix_global->tasks, simix_global->tasksTemp);
374
375     // Execute all the queued tasks:
376     for (auto& task : simix_global->tasksTemp)
377       task();
378
379     simix_global->tasksTemp.clear();
380   } while (not simix_global->tasks.empty());
381
382   return true;
383 }
384
385 /**
386  * \ingroup SIMIX_API
387  * \brief Run the main simulation loop.
388  */
389 void SIMIX_run()
390 {
391   if (not MC_record_path.empty()) {
392     simgrid::mc::replay(MC_record_path);
393     return;
394   }
395
396   double time = 0;
397
398   do {
399     XBT_DEBUG("New Schedule Round; size(queue)=%zu", simix_global->process_to_run.size());
400
401     if (simgrid::simix::breakpoint >= 0.0 && time >= simgrid::simix::breakpoint) {
402       XBT_DEBUG("Breakpoint reached (%g)", simgrid::simix::breakpoint.get());
403       simgrid::simix::breakpoint = -1.0;
404 #ifdef SIGTRAP
405       std::raise(SIGTRAP);
406 #else
407       std::raise(SIGABRT);
408 #endif
409     }
410
411     SIMIX_execute_tasks();
412
413     while (not simix_global->process_to_run.empty()) {
414       XBT_DEBUG("New Sub-Schedule Round; size(queue)=%zu", simix_global->process_to_run.size());
415
416       /* Run all processes that are ready to run, possibly in parallel */
417       SIMIX_process_runall();
418
419       /* answer sequentially and in a fixed arbitrary order all the simcalls that were issued during that sub-round */
420
421       /* WARNING, the order *must* be fixed or you'll jeopardize the simulation reproducibility (see RR-7653) */
422
423       /* Here, the order is ok because:
424        *
425        *   Short proof: only maestro adds stuff to the process_to_run array, so the execution order of user contexts do
426        *   not impact its order.
427        *
428        *   Long proof: processes remain sorted through an arbitrary (implicit, complex but fixed) order in all cases.
429        *
430        *   - if there is no kill during the simulation, processes remain sorted according by their PID.
431        *     Rationale: This can be proved inductively.
432        *        Assume that process_to_run is sorted at a beginning of one round (it is at round 0: the deployment file
433        *        is parsed linearly).
434        *        Let's show that it is still so at the end of this round.
435        *        - if a process is added when being created, that's from maestro. It can be either at startup
436        *          time (and then in PID order), or in response to a process_create simcall. Since simcalls are handled
437        *          in arbitrary order (inductive hypothesis), we are fine.
438        *        - If a process is added because it's getting killed, its subsequent actions shouldn't matter
439        *        - If a process gets added to process_to_run because one of their blocking action constituting the meat
440        *          of a simcall terminates, we're still good. Proof:
441        *          - You are added from SIMIX_simcall_answer() only. When this function is called depends on the resource
442        *            kind (network, cpu, disk, whatever), but the same arguments hold. Let's take communications as an
443        *            example.
444        *          - For communications, this function is called from SIMIX_comm_finish().
445        *            This function itself don't mess with the order since simcalls are handled in FIFO order.
446        *            The function is called:
447        *            - before the comm starts (invalid parameters, or resource already dead or whatever).
448        *              The order then trivial holds since maestro didn't interrupt its handling of the simcall yet
449        *            - because the communication failed or were canceled after startup. In this case, it's called from
450        *              the function we are in, by the chunk:
451        *                       set = model->states.failed_action_set;
452        *                       while ((synchro = extract(set)))
453        *                          SIMIX_simcall_post((smx_synchro_t) synchro->data);
454        *              This order is also fixed because it depends of the order in which the surf actions were
455        *              added to the system, and only maestro can add stuff this way, through simcalls.
456        *              We thus use the inductive hypothesis once again to conclude that the order in which synchros are
457        *              poped out of the set does not depend on the user code's execution order.
458        *            - because the communication terminated. In this case, synchros are served in the order given by
459        *                       set = model->states.done_action_set;
460        *                       while ((synchro = extract(set)))
461        *                          SIMIX_simcall_post((smx_synchro_t) synchro->data);
462        *              and the argument is very similar to the previous one.
463        *            So, in any case, the orders of calls to SIMIX_comm_finish() do not depend on the order in which user
464        *            processes are executed.
465        *          So, in any cases, the orders of processes within process_to_run do not depend on the order in which
466        *          user processes were executed previously.
467        *     So, if there is no killing in the simulation, the simulation reproducibility is not jeopardized.
468        *   - If there is some process killings, the order is changed by this decision that comes from user-land
469        *     But this decision may not have been motivated by a situation that were different because the simulation is
470        *     not reproducible.
471        *     So, even the order change induced by the process killing is perfectly reproducible.
472        *
473        *   So science works, bitches [http://xkcd.com/54/].
474        *
475        *   We could sort the process_that_ran array completely so that we can describe the order in which simcalls are
476        *   handled (like "according to the PID of issuer"), but it's not mandatory (order is fixed already even if
477        *   unfriendly).
478        *   That would thus be a pure waste of time.
479        */
480
481       for (smx_actor_t const& process : simix_global->process_that_ran) {
482         if (process->simcall.call != SIMCALL_NONE) {
483           SIMIX_simcall_handle(&process->simcall, 0);
484         }
485       }
486
487       SIMIX_execute_tasks();
488       do {
489         SIMIX_wake_processes();
490       } while (SIMIX_execute_tasks());
491
492       /* If only daemon processes remain, cancel their actions, mark them to die and reschedule them */
493       if (simix_global->process_list.size() == simix_global->daemons.size())
494         for (auto const& dmon : simix_global->daemons) {
495           XBT_DEBUG("Kill %s", dmon->get_cname());
496           SIMIX_process_kill(dmon, simix_global->maestro_process);
497         }
498     }
499
500     time = SIMIX_timer_next();
501     if (time > -1.0 || not simix_global->process_list.empty()) {
502       XBT_DEBUG("Calling surf_solve");
503       time = surf_solve(time);
504       XBT_DEBUG("Moving time ahead : %g", time);
505     }
506
507     /* Notify all the hosts that have failed */
508     /* FIXME: iterate through the list of failed host and mark each of them */
509     /* as failed. On each host, signal all the running processes with host_fail */
510
511     // Execute timers and tasks until there isn't anything to be done:
512     bool again = false;
513     do {
514       again = SIMIX_execute_timers();
515       if (SIMIX_execute_tasks())
516         again = true;
517       SIMIX_wake_processes();
518     } while (again);
519
520     /* Autorestart all process */
521     for (auto const& host : host_that_restart) {
522       XBT_INFO("Restart processes on host %s", host->get_cname());
523       SIMIX_host_autorestart(host);
524     }
525     host_that_restart.clear();
526
527     /* Clean processes to destroy */
528     SIMIX_process_empty_trash();
529
530     XBT_DEBUG("### time %f, #processes %zu, #to_run %zu", time, simix_global->process_list.size(),
531               simix_global->process_to_run.size());
532
533     if (simix_global->process_to_run.empty() && not simix_global->process_list.empty())
534       simgrid::simix::onDeadlock();
535
536   } while (time > -1.0 || not simix_global->process_to_run.empty());
537
538   if (not simix_global->process_list.empty()) {
539
540     if (simix_global->process_list.size() <= simix_global->daemons.size()) {
541       XBT_CRITICAL("Oops! Daemon actors cannot do any blocking activity (communications, synchronization, etc) "
542                    "once the simulation is over. Please fix your on_exit() functions.");
543     } else {
544       XBT_CRITICAL("Oops! Deadlock or code not perfectly clean.");
545     }
546     SIMIX_display_process_status();
547     simgrid::s4u::on_deadlock();
548     xbt_abort();
549   }
550   simgrid::s4u::on_simulation_end();
551 }
552
553 /**
554  *   \brief Set the date to execute a function
555  *
556  * Set the date to execute the function on the surf.
557  *   \param date Date to execute function
558  *   \param callback Function to be executed
559  *   \param arg Parameters of the function
560  *
561  */
562 smx_timer_t SIMIX_timer_set(double date, void (*callback)(void*), void *arg)
563 {
564   smx_timer_t timer = new s_smx_timer_t(date, simgrid::xbt::makeTask([callback, arg]() { callback(arg); }));
565   timer->handle_    = simix_timers.emplace(std::make_pair(date, timer));
566   return timer;
567 }
568
569 smx_timer_t SIMIX_timer_set(double date, simgrid::xbt::Task<void()> callback)
570 {
571   smx_timer_t timer = new s_smx_timer_t(date, std::move(callback));
572   timer->handle_    = simix_timers.emplace(std::make_pair(date, timer));
573   return timer;
574 }
575
576 /** @brief cancels a timer that was added earlier */
577 void SIMIX_timer_remove(smx_timer_t timer) {
578   simix_timers.erase(timer->handle_);
579   delete timer;
580 }
581
582 /** @brief Returns the date at which the timer will trigger (or 0 if nullptr timer) */
583 double SIMIX_timer_get_date(smx_timer_t timer) {
584   return timer ? timer->getDate() : 0;
585 }
586
587 /**
588  * \brief Registers a function to create a process.
589  *
590  * This function registers a function to be called
591  * when a new process is created. The function has
592  * to call SIMIX_process_create().
593  * \param function create process function
594  */
595 void SIMIX_function_register_process_create(smx_creation_func_t function)
596 {
597   simix_global->create_process_function = function;
598 }
599
600 /**
601  * \brief Registers a function to kill a process.
602  *
603  * This function registers a function to be called when a process is killed. The function has to call the
604  * SIMIX_process_kill().
605  *
606  * \param function Kill process function
607  */
608 void SIMIX_function_register_process_kill(void_pfn_smxprocess_t function)
609 {
610   simix_global->kill_process_function = function;
611 }
612
613 /**
614  * \brief Registers a function to cleanup a process.
615  *
616  * This function registers a user function to be called when a process ends properly.
617  *
618  * \param function cleanup process function
619  */
620 void SIMIX_function_register_process_cleanup(void_pfn_smxprocess_t function)
621 {
622   simix_global->cleanup_process_function = function;
623 }
624
625
626 void SIMIX_display_process_status()
627 {
628   int nbprocess = simix_global->process_list.size();
629
630   XBT_INFO("%d processes are still running, waiting for something.", nbprocess);
631   /*  List the process and their state */
632   XBT_INFO("Legend of the following listing: \"Process <pid> (<name>@<host>): <status>\"");
633   for (auto const& kv : simix_global->process_list) {
634     smx_actor_t process = kv.second;
635
636     if (process->waiting_synchro) {
637
638       const char* synchro_description = "unknown";
639
640       if (boost::dynamic_pointer_cast<simgrid::kernel::activity::ExecImpl>(process->waiting_synchro) != nullptr)
641         synchro_description = "execution";
642
643       if (boost::dynamic_pointer_cast<simgrid::kernel::activity::CommImpl>(process->waiting_synchro) != nullptr)
644         synchro_description = "communication";
645
646       if (boost::dynamic_pointer_cast<simgrid::kernel::activity::SleepImpl>(process->waiting_synchro) != nullptr)
647         synchro_description = "sleeping";
648
649       if (boost::dynamic_pointer_cast<simgrid::kernel::activity::RawImpl>(process->waiting_synchro) != nullptr)
650         synchro_description = "synchronization";
651
652       if (boost::dynamic_pointer_cast<simgrid::kernel::activity::IoImpl>(process->waiting_synchro) != nullptr)
653         synchro_description = "I/O";
654
655       XBT_INFO("Process %ld (%s@%s): waiting for %s synchro %p (%s) in state %d to finish", process->pid,
656                process->get_cname(), process->host->get_cname(), synchro_description, process->waiting_synchro.get(),
657                process->waiting_synchro->name_.c_str(), (int)process->waiting_synchro->state_);
658     }
659     else {
660       XBT_INFO("Process %ld (%s@%s)", process->pid, process->get_cname(), process->host->get_cname());
661     }
662   }
663 }
664
665 int SIMIX_is_maestro()
666 {
667   smx_actor_t self = SIMIX_process_self();
668   return simix_global == nullptr /*SimDag*/ || self == nullptr || self == simix_global->maestro_process;
669 }