X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/347996b4a10c4e8579080692afa60e0afb88b60a..0992a06d7845b577ac03500bbc555b21e92d6c1a:/examples/smpi/replay_multiple/replay_multiple.c diff --git a/examples/smpi/replay_multiple/replay_multiple.c b/examples/smpi/replay_multiple/replay_multiple.c index 969fe9ac7a..d258fe5a56 100644 --- a/examples/smpi/replay_multiple/replay_multiple.c +++ b/examples/smpi/replay_multiple/replay_multiple.c @@ -1,56 +1,51 @@ -/* Copyright (c) 2009-2015. The SimGrid Team. +/* Copyright (c) 2009-2019. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include -#include "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */ -#include "xbt/sysdep.h" /* calloc, printf */ +#include "simgrid/msg.h" #include "mpi.h" -/* Create a log channel to have nice outputs. */ -#include "xbt/log.h" -#include "xbt/asserts.h" -#include "smpi/smpi.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, - "Messages specific for this msg example"); + +#include +#include + +XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example"); static int smpi_replay(int argc, char *argv[]) { - smpi_replay_run(&argc, &argv); + const char* instance_id = argv[1]; + int rank = xbt_str_parse_int(argv[2], "Cannot parse rank '%s'"); + const char* trace_filename = argv[3]; + double start_delay_flops = 0; + + if (argc > 4) { + start_delay_flops = xbt_str_parse_double(argv[4], "Cannot parse start_delay_flops"); + } + + smpi_replay_run(instance_id, rank, start_delay_flops, trace_filename); return 0; } int main(int argc, char *argv[]){ msg_error_t res; - const char *platform_file; - const char *application_file; - const char *description_file; MSG_init(&argc, argv); + SMPI_init(); - if (argc < 4) { - printf("Usage: %s description_file platform_file deployment_file\n", argv[0]); - printf("example: %s smpi_multiple_apps msg_platform.xml msg_deployment.xml\n", argv[0]); - exit(1); - } - description_file = argv[1]; - platform_file = argv[2]; - application_file = argv[3]; - + xbt_assert(argc > 3, "Usage: %s description_file platform_file deployment_file\n" + "\tExample: %s smpi_multiple_apps msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]); /* Simulation setting */ - MSG_create_environment(platform_file); + MSG_create_environment(argv[2]); /* Application deployment: read the description file in order to identify instances to launch */ - FILE* fp = fopen(description_file, "r"); + FILE* fp = fopen(argv[1], "r"); if (fp == NULL) - xbt_die("Cannot open %s", description_file); - ssize_t read; - char *line = NULL; - size_t n = 0; - int instance_size = 0; + xbt_die("Cannot open %s", argv[1]); + char line[2048]; const char* instance_id = NULL; - while ((read = xbt_getline(&line, &n, fp)) != -1 ){ + while (fgets(line, sizeof line, fp)) { + xbt_assert(1 + strlen(line) < sizeof line, "input buffer too short (read: %s)", line); xbt_dynar_t elems = xbt_str_split_quoted_in_place(line); if(xbt_dynar_length(elems)<3){ xbt_die ("Not enough elements in the line"); @@ -58,7 +53,7 @@ int main(int argc, char *argv[]){ const char** line_char= xbt_dynar_to_array(elems); instance_id = line_char[0]; - instance_size = xbt_str_parse_int(line_char[2], "Invalid size: %s"); + int instance_size = xbt_str_parse_int(line_char[2], "Invalid size: %s"); XBT_INFO("Initializing instance %s of size %d", instance_id, instance_size); SMPI_app_instance_register(instance_id, smpi_replay,instance_size); @@ -66,17 +61,14 @@ int main(int argc, char *argv[]){ xbt_free(line_char); } - MSG_launch_application(application_file); - SMPI_init(); + fclose(fp); + + MSG_launch_application(argv[3]); res = MSG_main(); XBT_INFO("Simulation time %g", MSG_get_clock()); SMPI_finalize(); - if (res == MSG_OK) - return 0; - else - return 1; - + return res != MSG_OK; }