From: Takishipp Date: Thu, 14 Sep 2017 15:37:11 +0000 (+0200) Subject: s4u-async-wait example X-Git-Tag: v3_17~48^2~3 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/649bd7b5c26e344eee9bd9a70625e644d302ba3d s4u-async-wait example --- diff --git a/examples/s4u/CMakeLists.txt b/examples/s4u/CMakeLists.txt index 5c74c9c346..d3ce9a6a11 100644 --- a/examples/s4u/CMakeLists.txt +++ b/examples/s4u/CMakeLists.txt @@ -1,7 +1,7 @@ foreach (example actions-comm actions-storage actor-create actor-daemon actor-kill actor-migration actor-suspend app-masterworker app-pingpong app-token-ring - async-waitany async-waitall + async-wait async-waitany async-waitall plugin-hostload io mutex) add_executable (s4u-${example} ${example}/s4u-${example}.cpp) target_link_libraries(s4u-${example} simgrid) @@ -33,6 +33,7 @@ set(examples_src ${examples_src} set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/app-bittorrent/s4u-app-bittorrent.tesh ${CMAKE_CURRENT_SOURCE_DIR}/dht-chord/s4u-dht-chord.tesh ${CMAKE_CURRENT_SOURCE_DIR}/dht-chord/s4u-dht-chord.tesh + ${CMAKE_CURRENT_SOURCE_DIR}/async-wait/s4u-async-wait.tesh ${CMAKE_CURRENT_SOURCE_DIR}/async-waitany/s4u-async-waitany.tesh ${CMAKE_CURRENT_SOURCE_DIR}/async-waitall/s4u-async-waitall.tesh PARENT_SCOPE) set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-actions-comm-split_d.xml @@ -43,6 +44,7 @@ set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-a ${CMAKE_CURRENT_SOURCE_DIR}/app-masterworker/s4u-app-masterworker_d.xml ${CMAKE_CURRENT_SOURCE_DIR}/async-waitany/s4u-async-waitany_d.xml ${CMAKE_CURRENT_SOURCE_DIR}/async-waitall/s4u-async-waitall_d.xml + ${CMAKE_CURRENT_SOURCE_DIR}/async-wait/s4u-async-wait_d.xml ${CMAKE_CURRENT_SOURCE_DIR}/dht-chord/s4u-dht-chord_d.xml PARENT_SCOPE) set(txt_files ${txt_files} ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-actions-comm-split-p0.txt ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-actions-comm-split-p1.txt @@ -53,7 +55,7 @@ set(txt_files ${txt_files} ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-a foreach(example actions-comm actions-storage actor-create actor-daemon actor-kill actor-migration actor-suspend app-bittorrent app-masterworker app-pingpong app-token-ring - async-waitall async-waitany + async-wait async-waitall async-waitany dht-chord plugin-hostload io mutex) ADD_TESH_FACTORIES(s4u-${example} "thread;ucontext;raw;boost" --setenv bindir=${CMAKE_CURRENT_BINARY_DIR}/${example} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --cd ${CMAKE_HOME_DIRECTORY}/examples/s4u/${example} s4u-${example}.tesh) endforeach() diff --git a/examples/s4u/async-wait/s4u-async-wait.cpp b/examples/s4u/async-wait/s4u-async-wait.cpp new file mode 100644 index 0000000000..86dd403676 --- /dev/null +++ b/examples/s4u/async-wait/s4u-async-wait.cpp @@ -0,0 +1,114 @@ +/* Copyright (c) 2010-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/s4u.hpp" + #include "xbt/str.h" + #include + #include + +XBT_LOG_NEW_DEFAULT_CATEGORY(msg_async_wait, "Messages specific for this s4u example"); + +/* Main function of the Sender process */ +class sender { + long messages_count; + long receivers_count; + double sleep_start_time; /* - start time */ + double sleep_test_time; /* - test time */ + double msg_size; + simgrid::s4u::MailboxPtr mbox; + +public: + explicit sender(std::vector args) +{ + xbt_assert(args.size() == 7, "The sender function expects 6 arguments from the XML deployment file"); + messages_count = std::stol(args[1]); /* - number of tasks */ + msg_size = std::stod(args[2]); /* - computational cost */ + double task_comm_size = std::stod(args[3]); /* - communication cost */ + receivers_count = std::stol(args[4]); /* - number of receivers */ + double sleep_start_time = std::stod(args[5]); /* - start time */ + double sleep_test_time = std::stod(args[6]); /* - test time */ + XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time, sleep_test_time); +} +void operator()() +{ + for (int i = 0; i < messages_count; i++) { + char mailbox[80]; + char taskname[80]; + + std::string mbox_name = std::string("receiver-") + std::to_string(i % receivers_count); + mbox = simgrid::s4u::Mailbox::byName(mbox_name); + snprintf(mailbox,79, "receiver-%ld", i % receivers_count); + snprintf(taskname,79, "Task_%d", i); + + /* Create a communication */ + simgrid::s4u::CommPtr comm = mbox->put_async((void*)mailbox, msg_size); + XBT_INFO("Send to receiver-%ld Task_%d", i % receivers_count, i); + } + + for (int i = 0; i < receivers_count; i++) { + char mailbox[80]; + char* payload = xbt_strdup("finalize"); + snprintf(mailbox, 79, "receiver-%d", i); + simgrid::s4u::CommPtr comm = mbox->put_async((void*)payload, 0); + XBT_INFO("Send to receiver-%d finalize", i); + } + + XBT_INFO("Goodbye now!"); + +} +}; + +/* Receiver process expects 3 arguments: */ +class receiver { + int id; + double sleep_test_time; + double sleep_start_time; + simgrid::s4u::MailboxPtr mbox; + +public: + explicit receiver(std::vector args) + { + xbt_assert(args.size() == 4, "The relay_runner function does not accept any parameter from the XML deployment file"); + id = std::stoi(args[1]); /* - unique id */ + sleep_start_time = std::stod(args[2]); /* - start time */ + sleep_test_time = std::stod(args[3]); /* - test time */ + XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time, sleep_test_time); + std::string mbox_name = std::string("receiver-") + std::to_string(id); + mbox = simgrid::s4u::Mailbox::byName(mbox_name); +} + +void operator()() +{ + char mailbox[80]; + snprintf(mailbox,79, "receiver-%d", id); + while (1) { + char* received = static_cast(mbox->get()); + XBT_INFO("Wait to receive a task"); + XBT_INFO("I got a '%s'.", received); + if (std::strcmp(received, "finalize") == 0) { /* If it's a finalize message, we're done */ + xbt_free(received); + break; + } + /* Otherwise receiving the message was all we were supposed to do */ + xbt_free(received); + } +} +}; + +int main(int argc, char *argv[]) +{ + simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + + xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]); + + e->registerFunction("sender"); + e->registerFunction("receiver"); + + e->loadPlatform(argv[1]); + e->loadDeployment(argv[2]); + e->run(); + + return 0; +} diff --git a/examples/s4u/async-wait/s4u-async-wait.tesh b/examples/s4u/async-wait/s4u-async-wait.tesh new file mode 100644 index 0000000000..3054ab09da --- /dev/null +++ b/examples/s4u/async-wait/s4u-async-wait.tesh @@ -0,0 +1,110 @@ +#! ./tesh + +p Test1 MSG_comm_test() with Sleep_sender > Sleep_receiver + +$ $SG_TEST_EXENV ${bindir:=.}/s4u-async-wait ${srcdir:=.}/small_platform_fatpipe.xml ${srcdir:=.}/../msg/async-wait/async-wait_d.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +> [ 0.000000] (1:sender@Tremblay) sleep_start_time : 5.000000 , sleep_test_time : 0.100000 +> [ 0.000000] (2:receiver@Ruby) sleep_start_time : 1.000000 , sleep_test_time : 0.100000 +> [ 1.000000] (2:receiver@Ruby) Wait to receive a task +> [ 5.000000] (1:sender@Tremblay) Send to receiver-0 Task_0 +> [ 5.100000] (2:receiver@Ruby) Received "Task_0" +> [ 5.100000] (2:receiver@Ruby) Processing "Task_0" +> [ 5.100000] (1:sender@Tremblay) Send to receiver-0 Task_1 +> [ 5.609710] (2:receiver@Ruby) "Task_0" done +> [ 5.609710] (2:receiver@Ruby) Wait to receive a task +> [ 5.700000] (1:sender@Tremblay) Send to receiver-0 Task_2 +> [ 5.709710] (2:receiver@Ruby) Received "Task_1" +> [ 5.709710] (2:receiver@Ruby) Processing "Task_1" +> [ 6.219420] (2:receiver@Ruby) "Task_1" done +> [ 6.219420] (2:receiver@Ruby) Wait to receive a task +> [ 6.300000] (1:sender@Tremblay) Send to receiver-0 finalize +> [ 6.319420] (2:receiver@Ruby) Received "Task_2" +> [ 6.319420] (2:receiver@Ruby) Processing "Task_2" +> [ 6.829130] (2:receiver@Ruby) "Task_2" done +> [ 6.829130] (2:receiver@Ruby) Wait to receive a task +> [ 6.900000] (1:sender@Tremblay) Goodbye now! +> [ 6.929130] (2:receiver@Ruby) Received "finalize" +> [ 6.929130] (2:receiver@Ruby) I'm done. See you! +> [ 6.929130] (0:maestro@) Simulation time 6.92913 + +p Test2 MSG_comm_test() with Sleep_sender < Sleep_receiver + +$ $SG_TEST_EXENV ${bindir:=.}/s4u-async-wait ${srcdir:=.}/small_platform_fatpipe.xml ${srcdir:=.}/../msg/async-wait/async-wait2_d.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +> [ 0.000000] (1:sender@Tremblay) sleep_start_time : 1.000000 , sleep_test_time : 0.100000 +> [ 0.000000] (2:receiver@Ruby) sleep_start_time : 5.000000 , sleep_test_time : 0.100000 +> [ 1.000000] (1:sender@Tremblay) Send to receiver-0 Task_0 +> [ 5.000000] (2:receiver@Ruby) Wait to receive a task +> [ 5.100000] (2:receiver@Ruby) Received "Task_0" +> [ 5.100000] (2:receiver@Ruby) Processing "Task_0" +> [ 5.100000] (1:sender@Tremblay) Send to receiver-0 Task_1 +> [ 5.609710] (2:receiver@Ruby) "Task_0" done +> [ 5.609710] (2:receiver@Ruby) Wait to receive a task +> [ 5.700000] (1:sender@Tremblay) Send to receiver-0 Task_2 +> [ 5.709710] (2:receiver@Ruby) Received "Task_1" +> [ 5.709710] (2:receiver@Ruby) Processing "Task_1" +> [ 6.219420] (2:receiver@Ruby) "Task_1" done +> [ 6.219420] (2:receiver@Ruby) Wait to receive a task +> [ 6.300000] (1:sender@Tremblay) Send to receiver-0 finalize +> [ 6.319420] (2:receiver@Ruby) Received "Task_2" +> [ 6.319420] (2:receiver@Ruby) Processing "Task_2" +> [ 6.829130] (2:receiver@Ruby) "Task_2" done +> [ 6.829130] (2:receiver@Ruby) Wait to receive a task +> [ 6.900000] (1:sender@Tremblay) Goodbye now! +> [ 6.929130] (2:receiver@Ruby) Received "finalize" +> [ 6.929130] (2:receiver@Ruby) I'm done. See you! +> [ 6.929130] (0:maestro@) Simulation time 6.92913 + +p Test1 MSG_comm_wait() with Sleep_sender > Sleep_receiver + +$ $SG_TEST_EXENV ${bindir:=.}/s4u-async-wait ${srcdir:=.}/small_platform_fatpipe.xml ${srcdir:=.}/../msg/async-wait/async-wait3_d.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +> [ 0.000000] (1:sender@Tremblay) sleep_start_time : 5.000000 , sleep_test_time : 0.000000 +> [ 0.000000] (2:receiver@Ruby) sleep_start_time : 1.000000 , sleep_test_time : 0.000000 +> [ 1.000000] (2:receiver@Ruby) Wait to receive a task +> [ 5.000000] (1:sender@Tremblay) Send to receiver-0 Task_0 +> [ 5.004022] (2:receiver@Ruby) Received "Task_0" +> [ 5.004022] (2:receiver@Ruby) Processing "Task_0" +> [ 5.004022] (1:sender@Tremblay) Send to receiver-0 Task_1 +> [ 5.513732] (2:receiver@Ruby) "Task_0" done +> [ 5.513732] (2:receiver@Ruby) Wait to receive a task +> [ 5.517753] (2:receiver@Ruby) Received "Task_1" +> [ 5.517753] (2:receiver@Ruby) Processing "Task_1" +> [ 5.517753] (1:sender@Tremblay) Send to receiver-0 Task_2 +> [ 6.027463] (2:receiver@Ruby) "Task_1" done +> [ 6.027463] (2:receiver@Ruby) Wait to receive a task +> [ 6.031485] (2:receiver@Ruby) Received "Task_2" +> [ 6.031485] (2:receiver@Ruby) Processing "Task_2" +> [ 6.031485] (1:sender@Tremblay) Send to receiver-0 finalize +> [ 6.541195] (2:receiver@Ruby) "Task_2" done +> [ 6.541195] (2:receiver@Ruby) Wait to receive a task +> [ 6.543146] (1:sender@Tremblay) Goodbye now! +> [ 6.543146] (2:receiver@Ruby) Received "finalize" +> [ 6.543146] (2:receiver@Ruby) I'm done. See you! +> [ 6.543146] (0:maestro@) Simulation time 6.54315 + + +p Test2 MSG_comm_wait() with Sleep_sender < Sleep_receiver + +$ $SG_TEST_EXENV ${bindir:=.}/s4u-async-wait ${srcdir:=.}/small_platform_fatpipe.xml ${srcdir:=.}/../msg/async-wait/async-wait4_d.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +> [ 0.000000] (1:sender@Tremblay) sleep_start_time : 1.000000 , sleep_test_time : 0.000000 +> [ 0.000000] (2:receiver@Ruby) sleep_start_time : 5.000000 , sleep_test_time : 0.000000 +> [ 1.000000] (1:sender@Tremblay) Send to receiver-0 Task_0 +> [ 5.000000] (2:receiver@Ruby) Wait to receive a task +> [ 5.004022] (2:receiver@Ruby) Received "Task_0" +> [ 5.004022] (2:receiver@Ruby) Processing "Task_0" +> [ 5.004022] (1:sender@Tremblay) Send to receiver-0 Task_1 +> [ 5.513732] (2:receiver@Ruby) "Task_0" done +> [ 5.513732] (2:receiver@Ruby) Wait to receive a task +> [ 5.517753] (2:receiver@Ruby) Received "Task_1" +> [ 5.517753] (2:receiver@Ruby) Processing "Task_1" +> [ 5.517753] (1:sender@Tremblay) Send to receiver-0 Task_2 +> [ 6.027463] (2:receiver@Ruby) "Task_1" done +> [ 6.027463] (2:receiver@Ruby) Wait to receive a task +> [ 6.031485] (2:receiver@Ruby) Received "Task_2" +> [ 6.031485] (2:receiver@Ruby) Processing "Task_2" +> [ 6.031485] (1:sender@Tremblay) Send to receiver-0 finalize +> [ 6.541195] (2:receiver@Ruby) "Task_2" done +> [ 6.541195] (2:receiver@Ruby) Wait to receive a task +> [ 6.543146] (1:sender@Tremblay) Goodbye now! +> [ 6.543146] (2:receiver@Ruby) Received "finalize" +> [ 6.543146] (2:receiver@Ruby) I'm done. See you! +> [ 6.543146] (0:maestro@) Simulation time 6.54315 diff --git a/examples/s4u/async-wait/s4u-async-wait2_d.xml b/examples/s4u/async-wait/s4u-async-wait2_d.xml new file mode 100644 index 0000000000..1e49112af9 --- /dev/null +++ b/examples/s4u/async-wait/s4u-async-wait2_d.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/examples/s4u/async-wait/s4u-async-wait3_d.xml b/examples/s4u/async-wait/s4u-async-wait3_d.xml new file mode 100644 index 0000000000..f1ef12d94e --- /dev/null +++ b/examples/s4u/async-wait/s4u-async-wait3_d.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/examples/s4u/async-wait/s4u-async-wait4_d.xml b/examples/s4u/async-wait/s4u-async-wait4_d.xml new file mode 100644 index 0000000000..84ca7e6a15 --- /dev/null +++ b/examples/s4u/async-wait/s4u-async-wait4_d.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/examples/s4u/async-wait/s4u-async-wait_d.xml b/examples/s4u/async-wait/s4u-async-wait_d.xml new file mode 100644 index 0000000000..e385572019 --- /dev/null +++ b/examples/s4u/async-wait/s4u-async-wait_d.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/examples/s4u/async-waitall/s4u-async-waitall.cpp b/examples/s4u/async-waitall/s4u-async-waitall.cpp index 4789120dcb..332ce0ab6d 100644 --- a/examples/s4u/async-waitall/s4u-async-waitall.cpp +++ b/examples/s4u/async-waitall/s4u-async-waitall.cpp @@ -17,7 +17,7 @@ #include #include -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_async_waitall, "Messages specific for this msg example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(msg_async_waitall, "Messages specific for this s4u example"); class sender { long messages_count;