int main(int argc, char *argv[]){ msg_error_t res; MSG_init(&argc, argv); 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(argv[2]); /* Application deployment: read the description file in order to identify instances to launch */ FILE* fp = fopen(argv[1], "r"); if (fp == NULL) xbt_die("Cannot open %s", argv[1]); char *line = NULL; size_t n = 0; int instance_size = 0; const char* instance_id = NULL; while (xbt_getline(&line, &n, fp) != -1 ){ 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"); } 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"); XBT_INFO("Initializing instance %s of size %d", instance_id, instance_size); SMPI_app_instance_register(instance_id, smpi_replay,instance_size); xbt_free(line_char); } fclose(fp); MSG_launch_application(argv[3]); SMPI_init(); res = MSG_main(); XBT_INFO("Simulation time %g", MSG_get_clock()); SMPI_finalize(); return res != MSG_OK; }
xbt_dynar_t xbt_str_split_quoted(const char *s) { xbt_dynar_t res = xbt_dynar_new(sizeof(char *), &xbt_free_ref); xbt_dynar_t parsed; char *str_to_free; /* we have to copy the string before, to handle backslashes */ unsigned int cursor; char *p; if (s[0] == '\0') return res; str_to_free = xbt_strdup(s); parsed = xbt_str_split_quoted_in_place(str_to_free); xbt_dynar_foreach(parsed,cursor,p) { char *q=xbt_strdup(p); xbt_dynar_push(res,&q); }
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); 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]; { /* Simulation setting */ MSG_create_environment(platform_file); } { /* Application deployment */ //read the description file in order to identify instances to launch FILE* fp = fopen(description_file, "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; const char* instance_id = NULL; while ((read = xbt_getline(&line, &n, fp)) != -1 ){ 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"); } const char** line_char= xbt_dynar_to_array(elems); instance_id = line_char[0]; instance_size = atoi(line_char[2]); XBT_INFO("Initializing instance %s of size %d", instance_id, instance_size); SMPI_app_instance_register(instance_id, smpi_replay,instance_size); xbt_free(line_char); } MSG_launch_application(application_file); SMPI_init(); } res = MSG_main(); XBT_INFO("Simulation time %g", MSG_get_clock()); SMPI_finalize(); if (res == MSG_OK) return 0; else return 1; }