Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a cmake flag to not compile MSG at all
[simgrid.git] / examples / smpi / replay_multiple / replay_multiple.c
1 /* Copyright (c) 2009-2020. 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 "xbt/str.h"
10
11 #include <stdio.h>
12 #include <string.h>
13
14 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
15
16 static int smpi_replay(int argc, char *argv[]) {
17   const char* instance_id    = argv[1];
18   int rank                   = xbt_str_parse_int(argv[2], "Cannot parse rank '%s'");
19   const char* trace_filename = argv[3];
20   double start_delay_flops   = 0;
21
22   if (argc > 4) {
23     start_delay_flops = xbt_str_parse_double(argv[4], "Cannot parse start_delay_flops");
24   }
25
26   smpi_replay_run(instance_id, rank, start_delay_flops, trace_filename);
27   return 0;
28 }
29
30 int main(int argc, char *argv[]){
31   simgrid_init(&argc, argv);
32   SMPI_init();
33
34   xbt_assert(argc > 3, "Usage: %s description_file platform_file deployment_file\n"
35              "\tExample: %s smpi_multiple_apps msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
36
37   /*  Simulation setting */
38   simgrid_load_platform(argv[2]);
39
40   /*   Application deployment: read the description file in order to identify instances to launch */
41   FILE* fp = fopen(argv[1], "r");
42   if (fp == NULL)
43     xbt_die("Cannot open %s", argv[1]);
44   char line[2048];
45   const char* instance_id = NULL;
46   while (fgets(line, sizeof line, fp)) {
47     xbt_assert(1 + strlen(line) < sizeof line, "input buffer too short (read: %s)", line);
48     xbt_dynar_t elems = xbt_str_split_quoted_in_place(line);
49     if(xbt_dynar_length(elems)<3){
50       xbt_die ("Not enough elements in the line");
51     }
52
53     const char** line_char= xbt_dynar_to_array(elems);
54     instance_id = line_char[0];
55     int instance_size     = xbt_str_parse_int(line_char[2], "Invalid size: %s");
56
57     XBT_INFO("Initializing instance %s of size %d", instance_id, instance_size);
58     SMPI_app_instance_register(instance_id, smpi_replay,instance_size);
59
60     xbt_free(line_char);
61   }
62
63   fclose(fp);
64
65   simgrid_load_deployment(argv[3]);
66   simgrid_run();
67
68   XBT_INFO("Simulation time %g", simgrid_get_clock());
69
70   SMPI_finalize();
71   return 0;
72 }