Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add an example that shows how to replay multiple applications at the same time
[simgrid.git] / examples / smpi / replay_multiple / replay_multiple.c
1 /* Copyright (c) 2009-2014. 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 <stdio.h>
8 #include "msg/msg.h"            /* Yeah! If you want to use msg, you need to include msg/msg.h */
9 #include "xbt/sysdep.h"         /* calloc, printf */
10 #include "mpi.h"
11 /* Create a log channel to have nice outputs. */
12 #include "xbt/log.h"
13 #include "xbt/asserts.h"
14 #include "smpi/smpi.h"
15 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
16                              "Messages specific for this msg example");
17                              
18 int smpi_replay(int argc, char *argv[]);
19
20 int smpi_replay(int argc, char *argv[])
21 {
22   smpi_replay_init(&argc, &argv);
23
24   /* Actually do the simulation using smpi_action_trace_run */
25   smpi_action_trace_run(NULL);
26   smpi_replay_finalize();
27
28   return 0;
29 }
30
31 int main(int argc, char *argv[]){
32  msg_error_t res;
33   const char *platform_file;
34   const char *application_file;
35   const char *description_file;
36
37   MSG_init(&argc, argv);
38
39   if (argc < 4) {
40     printf("Usage: %s description_file platform_file deployment_file\n", argv[0]);
41     printf("example: %s smpi_multiple_apps msg_platform.xml msg_deployment.xml\n", argv[0]);
42     exit(1);
43   }
44   description_file = argv[1];
45   platform_file = argv[2];
46   application_file = argv[3];
47
48
49   {                             /*  Simulation setting */
50     MSG_create_environment(platform_file);
51   }
52   {                             /*   Application deployment */
53     //read the description file in order to identify instances to launch
54     FILE* fp = fopen(description_file, "r");
55     if (fp == NULL)
56       xbt_die("Cannot open %s", description_file);
57     ssize_t read;
58     char *line = NULL;
59     size_t n = 0;
60     int instance_size = 0;
61     const char* instance_id = NULL;
62     while ((read = xbt_getline(&line, &n, fp)) != -1 ){
63       xbt_dynar_t elems = xbt_str_split_quoted_in_place(line);
64       if(xbt_dynar_length(elems)<3){
65         xbt_die ("Not enough elements in the line");
66       }
67       
68       const char** line_char= xbt_dynar_to_array(elems); 
69       instance_id = line_char[0];
70       instance_size = atoi(line_char[2]);
71       
72       XBT_INFO("Initializing instance %s of size %d", instance_id, instance_size);
73       SMPI_app_instance_register(instance_id, smpi_replay,instance_size);
74
75       xbt_free(line_char);
76     }
77
78     MSG_launch_application(application_file);
79     SMPI_init();
80   }
81   res = MSG_main();
82
83   XBT_INFO("Simulation time %g", MSG_get_clock());
84
85
86   SMPI_finalize();
87   if (res == MSG_OK)
88     return 0;
89   else
90     return 1;
91
92 }