From: Martin Quinson Date: Tue, 31 Jul 2018 00:35:36 +0000 (+0200) Subject: simplify this example X-Git-Tag: v3_21~353 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/5aa09f39883b004b682420c1357bd3810d14c7fb?hp=71c2809622d2780c40083e9f3895da13953a57d8 simplify this example --- diff --git a/examples/s4u/app-pingpong/s4u-app-pingpong.cpp b/examples/s4u/app-pingpong/s4u-app-pingpong.cpp index 3d7d79e99b..e33ce15a47 100644 --- a/examples/s4u/app-pingpong/s4u-app-pingpong.cpp +++ b/examples/s4u/app-pingpong/s4u-app-pingpong.cpp @@ -3,25 +3,21 @@ /* 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/s4u.hpp" +#include XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_pingpong, "Messages specific for this s4u example"); -static void pinger(std::vector args) +static void pinger(simgrid::s4u::MailboxPtr mailbox_in, simgrid::s4u::MailboxPtr mailbox_out) { - xbt_assert(args.size() == 1, "The pinger function one argument from the XML deployment file"); - XBT_INFO("Ping -> %s", args[0].c_str()); - xbt_assert(simgrid::s4u::Host::by_name_or_null(args[0]) != nullptr, "Unknown host %s. Stopping Now! ", - args[0].c_str()); + XBT_INFO("Ping from mailbox %s to mailbox %s", mailbox_in->get_name().c_str(), mailbox_out->get_name().c_str()); /* - Do the ping with a 1-Byte task (latency bound) ... */ double* payload = new double(); *payload = simgrid::s4u::Engine::get_clock(); - simgrid::s4u::Mailbox::by_name(args[0])->put(payload, 1); + mailbox_out->put(payload, 1); /* - ... then wait for the (large) pong */ - double* sender_time = - static_cast(simgrid::s4u::Mailbox::by_name(simgrid::s4u::this_actor::get_host()->get_name())->get()); + double* sender_time = static_cast(mailbox_in->get()); double communication_time = simgrid::s4u::Engine::get_clock() - *sender_time; XBT_INFO("Task received : large communication (bandwidth bound)"); @@ -29,16 +25,12 @@ static void pinger(std::vector args) delete sender_time; } -static void ponger(std::vector args) +static void ponger(simgrid::s4u::MailboxPtr mailbox_in, simgrid::s4u::MailboxPtr mailbox_out) { - xbt_assert(args.size() == 1, "The ponger function one argument from the XML deployment file"); - XBT_INFO("Pong -> %s", args[0].c_str()); - xbt_assert(simgrid::s4u::Host::by_name_or_null(args[0]) != nullptr, "Unknown host %s. Stopping Now! ", - args[0].c_str()); + XBT_INFO("Pong from mailbox %s to mailbox %s", mailbox_in->get_name().c_str(), mailbox_out->get_name().c_str()); /* - Receive the (small) ping first ....*/ - double* sender_time = - static_cast(simgrid::s4u::Mailbox::by_name(simgrid::s4u::this_actor::get_host()->get_name())->get()); + double* sender_time = static_cast(mailbox_in->get()); double communication_time = simgrid::s4u::Engine::get_clock() - *sender_time; XBT_INFO("Task received : small communication (latency bound)"); XBT_INFO(" Ping time (latency bound) %f", communication_time); @@ -49,22 +41,19 @@ static void ponger(std::vector args) *payload = simgrid::s4u::Engine::get_clock(); XBT_INFO("task_bw->data = %.3f", *payload); - simgrid::s4u::Mailbox::by_name(args[0])->put(payload, 1e9); + mailbox_out->put(payload, 1e9); } int main(int argc, char* argv[]) { simgrid::s4u::Engine e(&argc, argv); - e.load_platform(argv[1]); - std::vector args; - args.push_back("Jupiter"); - simgrid::s4u::Actor::create("pinger", simgrid::s4u::Host::by_name("Tremblay"), pinger, args); - args.pop_back(); - args.push_back("Tremblay"); + simgrid::s4u::MailboxPtr mb1 = simgrid::s4u::Mailbox::by_name("Mailbox 1"); + simgrid::s4u::MailboxPtr mb2 = simgrid::s4u::Mailbox::by_name("Mailbox 2"); - simgrid::s4u::Actor::create("ponger", simgrid::s4u::Host::by_name("Jupiter"), ponger, args); + simgrid::s4u::Actor::create("pinger", simgrid::s4u::Host::by_name("Tremblay"), pinger, mb1, mb2); + simgrid::s4u::Actor::create("ponger", simgrid::s4u::Host::by_name("Jupiter"), ponger, mb2, mb1); e.run(); diff --git a/examples/s4u/app-pingpong/s4u-app-pingpong.tesh b/examples/s4u/app-pingpong/s4u-app-pingpong.tesh index 30f59caff8..8140c6929c 100644 --- a/examples/s4u/app-pingpong/s4u-app-pingpong.tesh +++ b/examples/s4u/app-pingpong/s4u-app-pingpong.tesh @@ -3,8 +3,8 @@ p Testing with default compound $ $SG_TEST_EXENV ${bindir:=.}/s4u-app-pingpong$EXEEXT ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" -> [ 0.000000] (1:pinger@Tremblay) Ping -> Jupiter -> [ 0.000000] (2:ponger@Jupiter) Pong -> Tremblay +> [ 0.000000] (1:pinger@Tremblay) Ping from mailbox Mailbox 1 to mailbox Mailbox 2 +> [ 0.000000] (2:ponger@Jupiter) Pong from mailbox Mailbox 2 to mailbox Mailbox 1 > [ 0.019014] (2:ponger@Jupiter) Task received : small communication (latency bound) > [ 0.019014] (2:ponger@Jupiter) Ping time (latency bound) 0.019014 > [ 0.019014] (2:ponger@Jupiter) task_bw->data = 0.019 @@ -16,8 +16,8 @@ p Testing with default compound Full network optimization $ $SG_TEST_EXENV ${bindir:=.}/s4u-app-pingpong$EXEEXT ${platfdir}/small_platform.xml "--cfg=network/optim:Full" "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" > [ 0.000000] (0:maestro@) Configuration change: Set 'network/optim' to 'Full' -> [ 0.000000] (1:pinger@Tremblay) Ping -> Jupiter -> [ 0.000000] (2:ponger@Jupiter) Pong -> Tremblay +> [ 0.000000] (1:pinger@Tremblay) Ping from mailbox Mailbox 1 to mailbox Mailbox 2 +> [ 0.000000] (2:ponger@Jupiter) Pong from mailbox Mailbox 2 to mailbox Mailbox 1 > [ 0.019014] (2:ponger@Jupiter) Task received : small communication (latency bound) > [ 0.019014] (2:ponger@Jupiter) Ping time (latency bound) 0.019014 > [ 0.019014] (2:ponger@Jupiter) task_bw->data = 0.019 @@ -30,8 +30,8 @@ p Testing the deprecated CM02 network model $ $SG_TEST_EXENV ${bindir:=.}/s4u-app-pingpong$EXEEXT ${platfdir}/small_platform.xml --cfg=cpu/model:Cas01 --cfg=network/model:CM02 "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" > [ 0.000000] (0:maestro@) Configuration change: Set 'cpu/model' to 'Cas01' > [ 0.000000] (0:maestro@) Configuration change: Set 'network/model' to 'CM02' -> [ 0.000000] (1:pinger@Tremblay) Ping -> Jupiter -> [ 0.000000] (2:ponger@Jupiter) Pong -> Tremblay +> [ 0.000000] (1:pinger@Tremblay) Ping from mailbox Mailbox 1 to mailbox Mailbox 2 +> [ 0.000000] (2:ponger@Jupiter) Pong from mailbox Mailbox 2 to mailbox Mailbox 1 > [ 0.001462] (2:ponger@Jupiter) Task received : small communication (latency bound) > [ 0.001462] (2:ponger@Jupiter) Ping time (latency bound) 0.001462 > [ 0.001462] (2:ponger@Jupiter) task_bw->data = 0.001 @@ -45,8 +45,8 @@ $ $SG_TEST_EXENV ${bindir:=.}/s4u-app-pingpong$EXEEXT ${platfdir}/small_platform > [ 0.000000] (0:maestro@) Configuration change: Set 'host/model' to 'compound' > [ 0.000000] (0:maestro@) Configuration change: Set 'cpu/model' to 'Cas01' > [ 0.000000] (0:maestro@) Configuration change: Set 'network/model' to 'Reno' -> [ 0.000000] (1:pinger@Tremblay) Ping -> Jupiter -> [ 0.000000] (2:ponger@Jupiter) Pong -> Tremblay +> [ 0.000000] (1:pinger@Tremblay) Ping from mailbox Mailbox 1 to mailbox Mailbox 2 +> [ 0.000000] (2:ponger@Jupiter) Pong from mailbox Mailbox 2 to mailbox Mailbox 1 > [ 0.019014] (2:ponger@Jupiter) Task received : small communication (latency bound) > [ 0.019014] (2:ponger@Jupiter) Ping time (latency bound) 0.019014 > [ 0.019014] (2:ponger@Jupiter) task_bw->data = 0.019 @@ -60,8 +60,8 @@ $ $SG_TEST_EXENV ${bindir:=.}/s4u-app-pingpong$EXEEXT ${platfdir}/small_platform > [ 0.000000] (0:maestro@) Configuration change: Set 'host/model' to 'compound' > [ 0.000000] (0:maestro@) Configuration change: Set 'cpu/model' to 'Cas01' > [ 0.000000] (0:maestro@) Configuration change: Set 'network/model' to 'Reno2' -> [ 0.000000] (1:pinger@Tremblay) Ping -> Jupiter -> [ 0.000000] (2:ponger@Jupiter) Pong -> Tremblay +> [ 0.000000] (1:pinger@Tremblay) Ping from mailbox Mailbox 1 to mailbox Mailbox 2 +> [ 0.000000] (2:ponger@Jupiter) Pong from mailbox Mailbox 2 to mailbox Mailbox 1 > [ 0.019014] (2:ponger@Jupiter) Task received : small communication (latency bound) > [ 0.019014] (2:ponger@Jupiter) Ping time (latency bound) 0.019014 > [ 0.019014] (2:ponger@Jupiter) task_bw->data = 0.019 @@ -75,8 +75,8 @@ $ $SG_TEST_EXENV ${bindir:=.}/s4u-app-pingpong$EXEEXT ${platfdir}/small_platform > [ 0.000000] (0:maestro@) Configuration change: Set 'host/model' to 'compound' > [ 0.000000] (0:maestro@) Configuration change: Set 'cpu/model' to 'Cas01' > [ 0.000000] (0:maestro@) Configuration change: Set 'network/model' to 'Vegas' -> [ 0.000000] (1:pinger@Tremblay) Ping -> Jupiter -> [ 0.000000] (2:ponger@Jupiter) Pong -> Tremblay +> [ 0.000000] (1:pinger@Tremblay) Ping from mailbox Mailbox 1 to mailbox Mailbox 2 +> [ 0.000000] (2:ponger@Jupiter) Pong from mailbox Mailbox 2 to mailbox Mailbox 1 > [ 0.019014] (2:ponger@Jupiter) Task received : small communication (latency bound) > [ 0.019014] (2:ponger@Jupiter) Ping time (latency bound) 0.019014 > [ 0.019014] (2:ponger@Jupiter) task_bw->data = 0.019 @@ -90,8 +90,8 @@ $ $SG_TEST_EXENV ${bindir:=.}/s4u-app-pingpong$EXEEXT ${platfdir}/small_platform > [ 0.000000] (0:maestro@) Configuration change: Set 'host/model' to 'compound' > [ 0.000000] (0:maestro@) Configuration change: Set 'cpu/model' to 'Cas01' > [ 0.000000] (0:maestro@) Configuration change: Set 'network/model' to 'Constant' -> [ 0.000000] (1:pinger@Tremblay) Ping -> Jupiter -> [ 0.000000] (2:ponger@Jupiter) Pong -> Tremblay +> [ 0.000000] (1:pinger@Tremblay) Ping from mailbox Mailbox 1 to mailbox Mailbox 2 +> [ 0.000000] (2:ponger@Jupiter) Pong from mailbox Mailbox 2 to mailbox Mailbox 1 > [ 13.010000] (2:ponger@Jupiter) Task received : small communication (latency bound) > [ 13.010000] (2:ponger@Jupiter) Ping time (latency bound) 13.010000 > [ 13.010000] (2:ponger@Jupiter) task_bw->data = 13.010