Logo AND Algorithmique Numérique Distribuée

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