Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add missing copyright notices.
[simgrid.git] / src / simix / smx_deployment.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 "simgrid/s4u/Host.hpp"
7 #include "smx_private.hpp"
8 #include "src/kernel/EngineImpl.hpp"
9 #include "src/surf/xml/platf_private.hpp" // FIXME: KILLME. There must be a better way than mimicking XML here
10 #include <simgrid/engine.h>
11 #include <simgrid/s4u/Engine.hpp>
12
13 #include <string>
14 #include <vector>
15
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_deployment, simix, "Logging specific to SIMIX (deployment)");
17
18 void SIMIX_init_application() // XBT_ATTRIB_DEPRECATED_v329
19 {
20   sg_platf_exit();
21   sg_platf_init();
22 }
23
24 void SIMIX_launch_application(const std::string& file) // XBT_ATTRIB_DEPRECATED_v329
25 {
26   simgrid_load_deployment(file.c_str());
27 }
28 void SIMIX_function_register(const std::string& name, xbt_main_func_t code) // XBT_ATTRIB_DEPRECATED_v329
29 {
30   simgrid::s4u::Engine::get_instance()->register_function(name, code);
31 }
32 void SIMIX_function_register(const std::string& name,
33                              void (*code)(std::vector<std::string>)) // XBT_ATTRIB_DEPRECATED_v329
34 {
35   simgrid::s4u::Engine::get_instance()->register_function(name, code);
36 }
37 void SIMIX_function_register_default(xbt_main_func_t code) // XBT_ATTRIB_DEPRECATED_v329
38 {
39   simgrid::s4u::Engine::get_instance()->register_default(code);
40 }
41
42 /** @brief Bypass the parser, get arguments, and set function to each process */
43 void SIMIX_process_set_function(const char* process_host, const char* process_function, xbt_dynar_t arguments,
44                                 double process_start_time, double process_kill_time) // XBT_ATTRIB_DEPRECATED_v329
45 {
46   simgrid::kernel::routing::ActorCreationArgs actor;
47
48   const simgrid::s4u::Host* host = sg_host_by_name(process_host);
49   if (not host)
50     throw std::invalid_argument(simgrid::xbt::string_printf("Host '%s' unknown", process_host));
51   actor.host = process_host;
52   actor.args.emplace_back(process_function);
53   /* add arguments */
54   unsigned int i;
55   char *arg;
56   xbt_dynar_foreach(arguments, i, arg) {
57     actor.args.emplace_back(arg);
58   }
59
60   // Check we know how to handle this function name:
61   const simgrid::kernel::actor::ActorCodeFactory& parse_code =
62       simgrid::kernel::EngineImpl::get_instance()->get_function(process_function);
63   xbt_assert(parse_code, "Function '%s' unknown", process_function);
64
65   actor.function           = process_function;
66   actor.kill_time          = process_kill_time;
67   actor.start_time         = process_start_time;
68   actor.restart_on_failure = false;
69   sg_platf_new_actor(&actor);
70 }