Logo AND Algorithmique Numérique Distribuée

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