Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[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   SMPI_init();
25
26   xbt_assert(argc > 3, "Usage: %s description_file platform_file deployment_file\n"
27              "\tExample: %s smpi_multiple_apps msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
28
29   /*  Simulation setting */
30   MSG_create_environment(argv[2]);
31
32   /*   Application deployment: read the description file in order to identify instances to launch */
33   FILE* fp = fopen(argv[1], "r");
34   if (fp == NULL)
35     xbt_die("Cannot open %s", argv[1]);
36   char line[2048];
37   const char* instance_id = NULL;
38   while (fgets(line, sizeof line, fp)) {
39     xbt_assert(1 + strlen(line) < sizeof line, "input buffer too short (read: %s)", line);
40     xbt_dynar_t elems = xbt_str_split_quoted_in_place(line);
41     if(xbt_dynar_length(elems)<3){
42       xbt_die ("Not enough elements in the line");
43     }
44
45     const char** line_char= xbt_dynar_to_array(elems);
46     instance_id = line_char[0];
47     int instance_size     = xbt_str_parse_int(line_char[2], "Invalid size: %s");
48
49     XBT_INFO("Initializing instance %s of size %d", instance_id, instance_size);
50     SMPI_app_instance_register(instance_id, smpi_replay,instance_size);
51
52     xbt_free(line_char);
53   }
54
55   fclose(fp);
56
57   MSG_launch_application(argv[3]);
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 }