Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ebb03f3d7f179b883768e0a6d5b3a81168422ec3
[simgrid.git] / examples / smpi / replay_multiple / replay_multiple.c
1 /* Copyright (c) 2009-2017. 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   smpi_replay_run(&argc, &argv);
17   return 0;
18 }
19
20 int main(int argc, char *argv[]){
21   msg_error_t res;
22
23   MSG_init(&argc, argv);
24
25   xbt_assert(argc > 3, "Usage: %s description_file platform_file deployment_file\n"
26              "\tExample: %s smpi_multiple_apps msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
27
28   /*  Simulation setting */
29   MSG_create_environment(argv[2]);
30
31   /*   Application deployment: read the description file in order to identify instances to launch */
32   FILE* fp = fopen(argv[1], "r");
33   if (fp == NULL)
34     xbt_die("Cannot open %s", argv[1]);
35   char line[2048];
36   const char* instance_id = NULL;
37   while (fgets(line, sizeof line, fp)) {
38     xbt_assert(1 + strlen(line) < sizeof line, "input buffer too short (read: %s)", line);
39     xbt_dynar_t elems = xbt_str_split_quoted_in_place(line);
40     if(xbt_dynar_length(elems)<3){
41       xbt_die ("Not enough elements in the line");
42     }
43
44     const char** line_char= xbt_dynar_to_array(elems);
45     instance_id = line_char[0];
46     int instance_size     = xbt_str_parse_int(line_char[2], "Invalid size: %s");
47
48     XBT_INFO("Initializing instance %s of size %d", instance_id, instance_size);
49     SMPI_app_instance_register(instance_id, smpi_replay,instance_size);
50
51     xbt_free(line_char);
52   }
53
54   fclose(fp);
55
56   MSG_launch_application(argv[3]);
57   SMPI_init();
58
59   res = MSG_main();
60
61   XBT_INFO("Simulation time %g", MSG_get_clock());
62
63   SMPI_finalize();
64   return res != MSG_OK;
65 }