X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/365e954b81e6b41967504bde0d64844402e8c87c..6429c9aaf190c9917068af80611adff5b451e732:/examples/msg/app-pingpong/app-pingpong.c diff --git a/examples/msg/app-pingpong/app-pingpong.c b/examples/msg/app-pingpong/app-pingpong.c index 3b6a9cbcca..3e12e81fe8 100644 --- a/examples/msg/app-pingpong/app-pingpong.c +++ b/examples/msg/app-pingpong/app-pingpong.c @@ -1,32 +1,26 @@ -/* Copyright (c) 2007-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2017. 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 "simgrid/msg.h" -/** @addtogroup MSG_examples - * - * - Ping-pong example: app-pingpong/app-pingpong.c . It's hard to think of a simpler example. The tesh file - * laying in the directory is instructive concerning the way to pass options to the simulators (see \ref options). - */ - -XBT_LOG_NEW_DEFAULT_CATEGORY(pingpong,"Messages specific for this msg example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(msg_app_pingpong, "Messages specific for this msg example"); static int pinger(int argc, char *argv[]) { + xbt_assert(argc==2, "The pinger function one argument from the XML deployment file"); XBT_INFO("Ping -> %s", argv[1]); xbt_assert(MSG_host_by_name(argv[1]) != NULL, "Unknown host %s. Stopping Now! ", argv[1]); - /** - Do the ping with a 1-Byte task (latency bound) ... */ - double time = MSG_get_clock(); + /* - Do the ping with a 1-Byte task (latency bound) ... */ + double now = MSG_get_clock(); msg_task_t ping_task = MSG_task_create("small communication (latency bound)", 0.0, 1, NULL); ping_task->data = xbt_new(double, 1); - *(double *) ping_task->data = time; + *(double *) ping_task->data = now; MSG_task_send(ping_task, argv[1]); - /** - ... then wait for the (large) pong */ + /* - ... then wait for the (large) pong */ msg_task_t pong_task = NULL; int a = MSG_task_receive(&pong_task,MSG_host_get_name(MSG_host_self())); xbt_assert(a == MSG_OK, "Unexpected behavior"); @@ -36,17 +30,18 @@ static int pinger(int argc, char *argv[]) XBT_INFO("Task received : %s", pong_task->name); xbt_free(pong_task->data); MSG_task_destroy(pong_task); - XBT_INFO("Pong time (bandwidth bound): %e", communication_time); + XBT_INFO("Pong time (bandwidth bound): %.3f", communication_time); return 0; } static int ponger(int argc, char *argv[]) { + xbt_assert(argc==2, "The ponger function one argument from the XML deployment file"); XBT_INFO("Pong -> %s", argv[1]); xbt_assert(MSG_host_by_name(argv[1]) != NULL, "Unknown host %s. Stopping Now! ", argv[1]); - /** - Receive the (small) ping first ....*/ + /* - Receive the (small) ping first ....*/ msg_task_t ping_task = NULL; int a = MSG_task_receive(&ping_task, MSG_host_get_name(MSG_host_self())); xbt_assert(a == MSG_OK, "Unexpected behavior"); @@ -56,14 +51,14 @@ static int ponger(int argc, char *argv[]) XBT_INFO("Task received : %s", ping_task->name); xbt_free(ping_task->data); MSG_task_destroy(ping_task); - XBT_INFO(" Ping time (latency bound) %e", communication_time); + XBT_INFO(" Ping time (latency bound) %f", communication_time); - /** - ... Then send a 1GB pong back (bandwidth bound) */ - double time = MSG_get_clock(); + /* - ... Then send a 1GB pong back (bandwidth bound) */ + double now = MSG_get_clock(); msg_task_t pong_task = MSG_task_create("large communication (bandwidth bound)", 0.0, 1e9, NULL); pong_task->data = xbt_new(double, 1); - *(double *) pong_task->data = time; - XBT_INFO("task_bw->data = %e", *((double *) pong_task->data)); + *(double *) pong_task->data = now; + XBT_INFO("task_bw->data = %.3f", *((double*)pong_task->data)); MSG_task_send(pong_task, argv[1]); return 0; @@ -71,22 +66,20 @@ static int ponger(int argc, char *argv[]) int main(int argc, char *argv[]) { - msg_error_t res = MSG_OK; - MSG_init(&argc, argv); xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n" - "\tExample: %s ../../platform/small_platform.xml app-pingpong_d.xml\n", argv[0], argv[0]); + "\tExample: %s ../../platforms/small_platform.xml app-pingpong_d.xml\n", argv[0], argv[0]); - MSG_create_environment(argv[1]); /** - Load the platform description */ + MSG_create_environment(argv[1]); /* - Load the platform description */ - MSG_function_register("pinger", pinger); /** - Register the function to be executed by the processes */ + MSG_function_register("pinger", pinger); /* - Register the functions to be executed by the processes */ MSG_function_register("ponger", ponger); - MSG_launch_application(argv[2]); /** - Deploy the application */ + MSG_launch_application(argv[2]); /* - Deploy the application */ - res = MSG_main(); /** - Run the simulation */ + msg_error_t res = MSG_main(); /* - Run the simulation */ - XBT_INFO("Total simulation time: %e", MSG_get_clock()); + XBT_INFO("Total simulation time: %.3f", MSG_get_clock()); return res!=MSG_OK; }