Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
1904af4f66f8ff2db78616659922d2228b56d94c
[simgrid.git] / src / simix / smx_global.cpp
1 /* Copyright (c) 2007-2021. 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/kernel/Timer.hpp"
8 #include "simgrid/s4u/Engine.hpp"
9 #include "simgrid/s4u/Host.hpp"
10 #include "src/smpi/include/smpi_actor.hpp"
11
12 #include "simgrid/sg_config.hpp"
13 #include "src/kernel/EngineImpl.hpp"
14 #include "src/mc/mc_record.hpp"
15 #include "src/mc/mc_replay.hpp"
16 #include "src/surf/xml/platf.hpp"
17
18 #include "simgrid/kernel/resource/Model.hpp"
19
20 #include <memory>
21
22 XBT_LOG_NEW_CATEGORY(simix, "All SIMIX categories");
23 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_kernel, simix, "Logging specific to SIMIX (kernel)");
24
25 namespace simgrid {
26 namespace simix {
27
28 xbt_dynar_t simix_global_get_actors_addr()
29 {
30 #if SIMGRID_HAVE_MC
31   return kernel::EngineImpl::get_instance()->get_actors_vector();
32 #else
33   xbt_die("This function is intended to be used when compiling with MC");
34 #endif
35 }
36 xbt_dynar_t simix_global_get_dead_actors_addr()
37 {
38 #if SIMGRID_HAVE_MC
39   return kernel::EngineImpl::get_instance()->get_dead_actors_vector();
40 #else
41   xbt_die("This function is intended to be used when compiling with MC");
42 #endif
43 }
44
45 } // namespace simix
46 } // namespace simgrid
47
48
49 static simgrid::kernel::actor::ActorCode maestro_code;
50 void SIMIX_set_maestro(void (*code)(void*), void* data)
51 {
52 #ifdef _WIN32
53   XBT_INFO("WARNING, SIMIX_set_maestro is believed to not work on windows. Please help us investigating this issue if "
54            "you need that feature");
55 #endif
56   maestro_code = std::bind(code, data);
57 }
58
59 void SIMIX_global_init(int* argc, char** argv)
60 {
61
62   // Either create a new context with maestro or create
63   // a context object with the current context maestro):
64   simgrid::kernel::actor::create_maestro(maestro_code);
65 }
66
67 /**
68  * @ingroup SIMIX_API
69  * @brief A clock (in second).
70  *
71  * @return Return the clock.
72  */
73 double SIMIX_get_clock() // XBT_ATTRIB_DEPRECATED_v332
74 {
75   return simgrid::s4u::Engine::get_clock();
76 }
77
78 void SIMIX_run() // XBT_ATTRIB_DEPRECATED_v332
79 {
80   simgrid::kernel::EngineImpl::get_instance()->run();
81 }
82
83 int SIMIX_is_maestro()
84 {
85   const simgrid::kernel::actor::ActorImpl* self = SIMIX_process_self();
86   return self == nullptr || simgrid::kernel::EngineImpl::get_instance()->is_maestro(self);
87 }