Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / examples / smpi / replay_multiple / replay_multiple.cpp
1 /* Copyright (c) 2009-2022. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "mpi.h"
8 #include "simgrid/engine.h"
9 #include "simgrid/s4u/Actor.hpp"
10 #include "xbt/replay.hpp"
11 #include "xbt/str.h"
12
13 #include <fstream>
14 #include <sstream>
15 #include <string>
16
17 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
18
19 static void smpi_replay(int argc, char* argv[])
20 {
21   const char* instance_id = argv[1];
22   int rank                = static_cast<int>(xbt_str_parse_int(argv[2], "Cannot parse rank"));
23   const char* shared_trace =
24       simgrid::s4u::Actor::self()->get_property("tracefile"); // Cannot use properties because this can be nullptr
25   const char* private_trace = argv[3];
26   double start_delay_flops  = 0;
27
28   if (argc > 4) {
29     start_delay_flops = xbt_str_parse_double(argv[4], "Cannot parse start_delay_flops");
30   }
31
32   if (shared_trace != nullptr)
33     xbt_replay_set_tracefile(shared_trace);
34   smpi_replay_run(instance_id, rank, start_delay_flops, private_trace);
35 }
36
37 int main(int argc, char* argv[])
38 {
39   simgrid_init(&argc, argv);
40   SMPI_init();
41
42   xbt_assert(argc > 3,
43              "Usage: %s description_file platform_file deployment_file\n"
44              "\tExample: %s smpi_multiple_apps platform.xml deployment.xml\n",
45              argv[0], argv[0]);
46
47   /*  Simulation setting */
48   simgrid_load_platform(argv[2]);
49
50   /*   Application deployment: read the description file in order to identify instances to launch */
51   std::ifstream f(argv[1]);
52   xbt_assert(f.is_open(), "Cannot open file '%s'", argv[1]);
53
54   std::string line;
55   while (std::getline(f, line)) {
56     std::string instance_id;
57     std::string filename;
58     int instance_size;
59
60     std::istringstream is(line);
61     is >> instance_id >> filename >> instance_size;
62     xbt_assert(is, "Not enough elements in the line");
63
64     XBT_INFO("Initializing instance %s of size %d", instance_id.c_str(), instance_size);
65     SMPI_app_instance_register(instance_id.c_str(), smpi_replay, instance_size);
66   }
67
68   f.close();
69
70   simgrid_load_deployment(argv[3]);
71   simgrid_run();
72
73   XBT_INFO("Simulation time %g", simgrid_get_clock());
74
75   SMPI_finalize();
76   return 0;
77 }