Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
dcc0ad4803e4c838c5cd3eaacba2527d30e16507
[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 "simgrid/msg.h"            /* Yeah! If you want to use msg, you need to include simgrid/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         smpi_replay_finalize();
24         return 0;
25 }
26
27 int main(int argc, char *argv[]){
28         msg_error_t res;
29         const char *platform_file;
30         const char *application_file;
31         const char *description_file;
32
33         MSG_init(&argc, argv);
34
35         if (argc < 4) {
36                 printf("Usage: %s description_file platform_file deployment_file\n", argv[0]);
37                 printf("example: %s smpi_multiple_apps msg_platform.xml msg_deployment.xml\n", argv[0]);
38                 exit(1);
39         }
40         description_file = argv[1];
41         platform_file = argv[2];
42         application_file = argv[3];
43
44
45         /*  Simulation setting */
46         MSG_create_environment(platform_file);
47
48         /*   Application deployment: read the description file in order to identify instances to launch */
49         FILE* fp = fopen(description_file, "r");
50         if (fp == NULL)
51                 xbt_die("Cannot open %s", description_file);
52         ssize_t read;
53         char     *line = NULL;
54         size_t n         = 0;
55         int instance_size = 0;
56         const char* instance_id = NULL;
57         while ((read = xbt_getline(&line, &n, fp)) != -1 ){
58                 xbt_dynar_t elems = xbt_str_split_quoted_in_place(line);
59                 if(xbt_dynar_length(elems)<3){
60                         xbt_die ("Not enough elements in the line");
61                 }
62
63                 const char** line_char= xbt_dynar_to_array(elems);
64                 instance_id = line_char[0];
65                 instance_size = atoi(line_char[2]);
66
67                 XBT_INFO("Initializing instance %s of size %d", instance_id, instance_size);
68                 SMPI_app_instance_register(instance_id, smpi_replay,instance_size);
69
70                 xbt_free(line_char);
71         }
72
73         MSG_launch_application(application_file);
74         SMPI_init();
75
76         res = MSG_main();
77
78         XBT_INFO("Simulation time %g", MSG_get_clock());
79
80         SMPI_finalize();
81         if (res == MSG_OK)
82                 return 0;
83         else
84                 return 1;
85
86 }