From: Martin Quinson Date: Fri, 21 Jul 2023 18:09:21 +0000 (+0200) Subject: Complete the other activityset examples in python X-Git-Tag: v3.35~132 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/db476e34b555b2776874d4a977192ca907619395 Complete the other activityset examples in python --- diff --git a/examples/cpp/activityset-waitall/s4u-activityset-waitall.cpp b/examples/cpp/activityset-waitall/s4u-activityset-waitall.cpp index 176e50fcd6..efbc3a08ab 100644 --- a/examples/cpp/activityset-waitall/s4u-activityset-waitall.cpp +++ b/examples/cpp/activityset-waitall/s4u-activityset-waitall.cpp @@ -26,7 +26,7 @@ static void bob() boost::dynamic_pointer_cast(comm), boost::dynamic_pointer_cast(io)}); - XBT_INFO("Wait for asynchrounous activities to complete, all in one shot."); + XBT_INFO("Wait for asynchronous activities to complete, all in one shot."); pending_activities.wait_all(); XBT_INFO("All activities are completed."); diff --git a/examples/cpp/activityset-waitall/s4u-activityset-waitall.tesh b/examples/cpp/activityset-waitall/s4u-activityset-waitall.tesh index 6f0142951d..889b405865 100644 --- a/examples/cpp/activityset-waitall/s4u-activityset-waitall.tesh +++ b/examples/cpp/activityset-waitall/s4u-activityset-waitall.tesh @@ -3,5 +3,5 @@ $ ${bindir:=.}/s4u-activityset-waitall ${platfdir}/hosts_with_disks.xml "--log=root.fmt:[%7.6r]%e[%5a]%e%m%n" > [0.000000] [alice] Send 'Message' > [0.000000] [ bob] Create my asynchronous activities -> [0.000000] [ bob] Wait for asynchrounous activities to complete, all in one shot. +> [0.000000] [ bob] Wait for asynchronous activities to complete, all in one shot. > [5.197828] [ bob] All activities are completed. diff --git a/examples/cpp/activityset-waitallfor/s4u-activityset-waitallfor.cpp b/examples/cpp/activityset-waitallfor/s4u-activityset-waitallfor.cpp index b1d405d1ef..971d77441c 100644 --- a/examples/cpp/activityset-waitallfor/s4u-activityset-waitallfor.cpp +++ b/examples/cpp/activityset-waitallfor/s4u-activityset-waitallfor.cpp @@ -24,7 +24,7 @@ static void bob() sg4::ActivitySet pending_activities({exec, comm, io}); - XBT_INFO("Wait for asynchrounous activities to complete"); + XBT_INFO("Wait for asynchronous activities to complete"); while (not pending_activities.empty()) { try { pending_activities.wait_all_for(1); diff --git a/examples/cpp/activityset-waitallfor/s4u-activityset-waitallfor.tesh b/examples/cpp/activityset-waitallfor/s4u-activityset-waitallfor.tesh index d0c1016965..014c4f028e 100644 --- a/examples/cpp/activityset-waitallfor/s4u-activityset-waitallfor.tesh +++ b/examples/cpp/activityset-waitallfor/s4u-activityset-waitallfor.tesh @@ -3,7 +3,7 @@ $ ${bindir:=.}/s4u-activityset-waitallfor ${platfdir}/hosts_with_disks.xml "--log=root.fmt:[%7.6r]%e[%5a]%e%m%n" > [0.000000] [alice] Send 'Message' > [0.000000] [ bob] Create my asynchronous activities -> [0.000000] [ bob] Wait for asynchrounous activities to complete +> [0.000000] [ bob] Wait for asynchronous activities to complete > [1.000000] [ bob] Not all activities are terminated yet. > [2.000000] [ bob] Not all activities are terminated yet. > [3.000000] [ bob] Not all activities are terminated yet. diff --git a/examples/cpp/activityset-waitany/s4u-activityset-waitany.cpp b/examples/cpp/activityset-waitany/s4u-activityset-waitany.cpp index 1878a13043..6f081b3ca6 100644 --- a/examples/cpp/activityset-waitany/s4u-activityset-waitany.cpp +++ b/examples/cpp/activityset-waitany/s4u-activityset-waitany.cpp @@ -26,7 +26,7 @@ static void bob() boost::dynamic_pointer_cast(comm), boost::dynamic_pointer_cast(io)}); - XBT_INFO("Wait for asynchrounous activities to complete"); + XBT_INFO("Wait for asynchronous activities to complete"); while (not pending_activities.empty()) { auto completed_one = pending_activities.wait_any(); if (completed_one != nullptr) { diff --git a/examples/cpp/activityset-waitany/s4u-activityset-waitany.tesh b/examples/cpp/activityset-waitany/s4u-activityset-waitany.tesh index bc33cc46f1..b9ecf1eafa 100644 --- a/examples/cpp/activityset-waitany/s4u-activityset-waitany.tesh +++ b/examples/cpp/activityset-waitany/s4u-activityset-waitany.tesh @@ -3,7 +3,7 @@ $ ${bindir:=.}/s4u-activityset-waitany ${platfdir}/hosts_with_disks.xml "--log=root.fmt:[%7.6r]%e[%5a]%e%m%n" > [0.000000] [alice] Send 'Message' > [0.000000] [ bob] Create my asynchronous activities -> [0.000000] [ bob] Wait for asynchrounous activities to complete +> [0.000000] [ bob] Wait for asynchronous activities to complete > [3.000000] [ bob] Completed an I/O > [5.000000] [ bob] Completed an Exec > [5.197828] [ bob] Completed a Comm diff --git a/examples/python/CMakeLists.txt b/examples/python/CMakeLists.txt index e54901cc5e..265268b37f 100644 --- a/examples/python/CMakeLists.txt +++ b/examples/python/CMakeLists.txt @@ -1,5 +1,5 @@ foreach(example actor-create actor-daemon actor-join actor-kill actor-migrate actor-suspend actor-yield actor-lifetime - activityset-testany + activityset-testany activityset-waitall activityset-waitallfor activityset-waitany app-masterworkers comm-wait comm-waitall comm-waitallfor comm-waitany comm-failure comm-host2host comm-pingpong comm-ready comm-suspend comm-testany comm-throttling comm-waitallfor comm-waituntil diff --git a/examples/python/activityset-waitall/activityset-waitall.py b/examples/python/activityset-waitall/activityset-waitall.py new file mode 100644 index 0000000000..36b70b8569 --- /dev/null +++ b/examples/python/activityset-waitall/activityset-waitall.py @@ -0,0 +1,44 @@ +# Copyright (c) 2017-2023. 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. + +""" +Usage: activityset-waitall.py platform_file [other parameters] +""" + +import sys +from simgrid import Actor, ActivitySet, Engine, Comm, Exec, Io, Host, Mailbox, this_actor + +def bob(): + mbox = Mailbox.by_name("mbox") + disk = Host.current().get_disks()[0] + + this_actor.info("Create my asynchronous activities") + exec = this_actor.exec_async(5e9) + comm, payload = mbox.get_async() + io = disk.read_async(300000000) + + pending_activities = ActivitySet([exec, comm]) + pending_activities.push(io) # Activities can be pushed after creation, too + + this_actor.info("Wait for asynchronous activities to complete, all in one shot.") + pending_activities.wait_all() + + this_actor.info("All activities are completed.") + +def alice(): + this_actor.info("Send 'Message'") + Mailbox.by_name("mbox").put("Message", 600000000) + +if __name__ == '__main__': + e = Engine(sys.argv) + e.set_log_control("root.fmt:[%4.6r]%e[%5a]%e%m%n") + + # Load the platform description + e.load_platform(sys.argv[1]) + + Actor.create("bob", Host.by_name("bob"), bob) + Actor.create("alice", Host.by_name("alice"), alice) + + e.run() diff --git a/examples/python/activityset-waitall/activityset-waitall.tesh b/examples/python/activityset-waitall/activityset-waitall.tesh new file mode 100644 index 0000000000..ab4b17590a --- /dev/null +++ b/examples/python/activityset-waitall/activityset-waitall.tesh @@ -0,0 +1,7 @@ +#!/usr/bin/env tesh + +$ ${pythoncmd:=python3} ${PYTHON_TOOL_OPTIONS:=} ${srcdir:=.}/activityset-waitall.py ${platfdir}/hosts_with_disks.xml +> [0.000000] [alice] Send 'Message' +> [0.000000] [ bob] Create my asynchronous activities +> [0.000000] [ bob] Wait for asynchronous activities to complete, all in one shot. +> [5.197828] [ bob] All activities are completed. diff --git a/examples/python/activityset-waitallfor/activityset-waitallfor.py b/examples/python/activityset-waitallfor/activityset-waitallfor.py new file mode 100644 index 0000000000..4f2880935f --- /dev/null +++ b/examples/python/activityset-waitallfor/activityset-waitallfor.py @@ -0,0 +1,58 @@ +# Copyright (c) 2017-2023. 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. + +""" +Usage: activityset-waitallfor.py platform_file [other parameters] +""" + +import sys +from simgrid import Actor, ActivitySet, Engine, Comm, Exec, Io, Host, Mailbox, this_actor, TimeoutException + +def bob(): + mbox = Mailbox.by_name("mbox") + disk = Host.current().get_disks()[0] + + this_actor.info("Create my asynchronous activities") + exec = this_actor.exec_async(5e9) + comm, payload = mbox.get_async() + io = disk.read_async(300000000) + + pending_activities = ActivitySet([exec, comm]) + pending_activities.push(io) # Activities can be pushed after creation, too + + this_actor.info("Wait for asynchronous activities to complete") + while not pending_activities.empty(): + try: + pending_activities.wait_all_for(1) + except TimeoutException: + this_actor.info("Not all activities are terminated yet.") + + completed_one = pending_activities.test_any() + while completed_one != None: + if isinstance(completed_one, Comm): + this_actor.info("Completed a Comm") + elif isinstance(completed_one, Exec): + this_actor.info("Completed an Exec") + elif isinstance(completed_one, Io): + this_actor.info("Completed an I/O") + completed_one = pending_activities.test_any() + + this_actor.info("Last activity is complete") + +def alice(): + this_actor.info("Send 'Message'") + Mailbox.by_name("mbox").put("Message", 600000000) + +if __name__ == '__main__': + e = Engine(sys.argv) + e.set_log_control("root.fmt:[%4.6r]%e[%5a]%e%m%n") + + # Load the platform description + e.load_platform(sys.argv[1]) + + Actor.create("bob", Host.by_name("bob"), bob) + Actor.create("alice", Host.by_name("alice"), alice) + + e.run() diff --git a/examples/python/activityset-waitallfor/activityset-waitallfor.tesh b/examples/python/activityset-waitallfor/activityset-waitallfor.tesh new file mode 100644 index 0000000000..cf08947e37 --- /dev/null +++ b/examples/python/activityset-waitallfor/activityset-waitallfor.tesh @@ -0,0 +1,15 @@ +#!/usr/bin/env tesh + +$ ${pythoncmd:=python3} ${PYTHON_TOOL_OPTIONS:=} ${srcdir:=.}/activityset-waitallfor.py ${platfdir}/hosts_with_disks.xml +> [0.000000] [alice] Send 'Message' +> [0.000000] [ bob] Create my asynchronous activities +> [0.000000] [ bob] Wait for asynchronous activities to complete +> [1.000000] [ bob] Not all activities are terminated yet. +> [2.000000] [ bob] Not all activities are terminated yet. +> [3.000000] [ bob] Not all activities are terminated yet. +> [3.000000] [ bob] Completed an I/O +> [4.000000] [ bob] Not all activities are terminated yet. +> [5.000000] [ bob] Not all activities are terminated yet. +> [5.000000] [ bob] Completed an Exec +> [5.197828] [ bob] Completed a Comm +> [5.197828] [ bob] Last activity is complete diff --git a/examples/python/activityset-waitany/activityset-waitany.py b/examples/python/activityset-waitany/activityset-waitany.py new file mode 100644 index 0000000000..c2139a8cb8 --- /dev/null +++ b/examples/python/activityset-waitany/activityset-waitany.py @@ -0,0 +1,120 @@ +# Copyright (c) 2017-2023. 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. + +""" +Usage: activityset-waitany.py platform_file [other parameters] +""" + +import sys +from simgrid import Actor, ActivitySet, Engine, Comm, Exec, Io, Host, Mailbox, this_actor + +def bob(): + mbox = Mailbox.by_name("mbox") + disk = Host.current().get_disks()[0] + + this_actor.info("Create my asynchronous activities") + exec = this_actor.exec_async(5e9) + comm, payload = mbox.get_async() + io = disk.read_async(300000000) + + pending_activities = ActivitySet([exec, comm]) + pending_activities.push(io) # Activities can be pushed after creation, too + + this_actor.info("Wait for asynchronous activities to complete") + while not pending_activities.empty(): + completed_one = pending_activities.wait_any() + + if isinstance(completed_one, Comm): + this_actor.info("Completed a Comm") + elif isinstance(completed_one, Exec): + this_actor.info("Completed an Exec") + elif isinstance(completed_one, Io): + this_actor.info("Completed an I/O") + + this_actor.info("Last activity is complete") + +def alice(): + this_actor.info("Send 'Message'") + Mailbox.by_name("mbox").put("Message", 600000000) + +if __name__ == '__main__': + e = Engine(sys.argv) + e.set_log_control("root.fmt:[%4.6r]%e[%5a]%e%m%n") + + # Load the platform description + e.load_platform(sys.argv[1]) + + Actor.create("bob", Host.by_name("bob"), bob) + Actor.create("alice", Host.by_name("alice"), alice) + + e.run() + +""" + +/* Copyright (c) 2010-2023. 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 +#include +#include +namespace sg4 = simgrid::s4u; + +XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_activity_waittany, "Messages specific for this s4u example"); + +static void bob() +{ + sg4::Mailbox* mbox = sg4::Mailbox::by_name("mbox"); + const sg4::Disk* disk = sg4::Host::current()->get_disks().front(); + std::string* payload; + + XBT_INFO("Create my asynchronous activities"); + auto exec = sg4::this_actor::exec_async(5e9); + auto comm = mbox->get_async(&payload); + auto io = disk->read_async(3e8); + + sg4::ActivitySet pending_activities({boost::dynamic_pointer_cast(exec), + boost::dynamic_pointer_cast(comm), + boost::dynamic_pointer_cast(io)}); + + XBT_INFO("Wait for asynchronous activities to complete"); + while (not pending_activities.empty()) { + auto completed_one = pending_activities.wait_any(); + if (completed_one != nullptr) { + if (boost::dynamic_pointer_cast(completed_one)) + XBT_INFO("Completed a Comm"); + if (boost::dynamic_pointer_cast(completed_one)) + XBT_INFO("Completed an Exec"); + if (boost::dynamic_pointer_cast(completed_one)) + XBT_INFO("Completed an I/O"); + } + } + XBT_INFO("Last activity is complete"); + delete payload; +} + +static void alice() +{ + auto* payload = new std::string("Message"); + XBT_INFO("Send '%s'", payload->c_str()); + sg4::Mailbox::by_name("mbox")->put(payload, 6e8); +} + +int main(int argc, char* argv[]) +{ + sg4::Engine e(&argc, argv); + + e.load_platform(argv[1]); + + sg4::Actor::create("bob", e.host_by_name("bob"), bob); + sg4::Actor::create("alice", e.host_by_name("alice"), alice); + + e.run(); + + return 0; +} +""" \ No newline at end of file diff --git a/examples/python/activityset-waitany/activityset-waitany.tesh b/examples/python/activityset-waitany/activityset-waitany.tesh new file mode 100644 index 0000000000..70b707b41e --- /dev/null +++ b/examples/python/activityset-waitany/activityset-waitany.tesh @@ -0,0 +1,10 @@ +#!/usr/bin/env tesh + +$ ${pythoncmd:=python3} ${PYTHON_TOOL_OPTIONS:=} ${srcdir:=.}/activityset-waitany.py ${platfdir}/hosts_with_disks.xml +> [0.000000] [alice] Send 'Message' +> [0.000000] [ bob] Create my asynchronous activities +> [0.000000] [ bob] Wait for asynchronous activities to complete +> [3.000000] [ bob] Completed an I/O +> [5.000000] [ bob] Completed an Exec +> [5.197828] [ bob] Completed a Comm +> [5.197828] [ bob] Last activity is complete