X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/a34aa584ccd2bdb81659d0e5df22864cf999c0f4..a57d5bbf9f18a3ee8887dbc06befd8b9cdd0e5ea:/examples/msg/masterslave/masterslave_arg.c diff --git a/examples/msg/masterslave/masterslave_arg.c b/examples/msg/masterslave/masterslave_arg.c index ad3d593640..b859965ed1 100644 --- a/examples/msg/masterslave/masterslave_arg.c +++ b/examples/msg/masterslave/masterslave_arg.c @@ -1,21 +1,12 @@ -/* Copyright (c) 2010. The SimGrid Team. +/* Copyright (c) 2010-2015. 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 "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */ -#include "xbt/sysdep.h" /* calloc, printf */ +#include "simgrid/msg.h" -/* Create a log channel to have nice outputs. */ -#include "xbt/log.h" -#include "xbt/asserts.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, - "Messages specific for this msg example"); - -int master(int argc, char *argv[]); -int slave(int argc, char *argv[]); +XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example"); #define task_comp_size 50000000 #define task_comm_size 1000000 @@ -28,8 +19,7 @@ static long my_random(long n) return n * (rand() / ((double)RAND_MAX + 1)); } -/** Emitter function */ -int master(int argc, char *argv[]) +static int master(int argc, char *argv[]) { int i; @@ -40,17 +30,13 @@ int master(int argc, char *argv[]) sprintf(mailbox, "slave-%ld", i % number_of_slaves); sprintf(sprintf_buffer, "Task_%d", i); - task = - MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, - NULL); - XBT_DEBUG("Sending \"%s\" (of %ld) to mailbox \"%s\"", task->name, - number_of_jobs, mailbox); + task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL); + XBT_DEBUG("Sending \"%s\" (of %ld) to mailbox \"%s\"", task->name, number_of_jobs, mailbox); MSG_task_send(task, mailbox); } - XBT_DEBUG - ("All tasks have been dispatched. Let's tell everybody the computation is over."); + XBT_DEBUG("All tasks have been dispatched. Let's tell everybody the computation is over."); for (i = 0; i < number_of_slaves; i++) { char mailbox[80]; @@ -61,13 +47,12 @@ int master(int argc, char *argv[]) XBT_DEBUG("Goodbye now!"); return 0; -} /* end_of_master */ +} -/** Receiver function */ -int slave(int argc, char *argv[]) +static int slave(int argc, char *argv[]) { msg_task_t task = NULL; - _XBT_GNUC_UNUSED int res; + XBT_ATTRIB_UNUSED int res; XBT_DEBUG("mailbox: %s",MSG_process_get_name(MSG_process_self())); while (1) { @@ -85,51 +70,36 @@ int slave(int argc, char *argv[]) MSG_task_destroy(task); task = NULL; } - XBT_DEBUG("I'm done. See you!"); return 0; -} /* end_of_slave */ /* end_of_test_all */ +} -/** Main function */ int main(int argc, char *argv[]) { msg_error_t res = MSG_OK; long i; MSG_init(&argc, argv); - if (argc < 4) { - printf("Usage: %s platform_file number_of_jobs number_of_slaves\n", argv[0]); - printf("example: %s msg_platform.xml 10 5\n", argv[0]); - exit(1); - } + xbt_assert(argc > 3, "Usage: %s platform_file number_of_jobs number_of_slaves\n" + "\tExample: %s msg_platform.xml 10 5\n", argv[0], argv[0]); MSG_function_register("master", master); MSG_function_register("slave", slave); MSG_create_environment(argv[1]); - number_of_jobs = atol(argv[2]); - number_of_slaves = atol(argv[3]); + number_of_jobs = xbt_str_parse_int(argv[2], "Invalid amount of jobs: %s"); + number_of_slaves = xbt_str_parse_int(argv[3], "Invalid amount of slaves: %s"); xbt_dynar_t host_dynar = MSG_hosts_as_dynar(); long number_max = xbt_dynar_length(host_dynar); XBT_INFO("Got %ld slaves, %ld tasks to process, and %ld hosts", number_of_slaves, number_of_jobs,number_max); msg_host_t *host_table = xbt_dynar_to_array(host_dynar); - //xbt_dynar_free(&host_dynar); - MSG_process_create( "master", - master, - NULL, - host_table[my_random(number_max)] - ); + MSG_process_create("master", master, NULL, host_table[my_random(number_max)]); - for(i = 0 ; i