From 87bd1a3bfa6b002a404c373fca560f267f10fe71 Mon Sep 17 00:00:00 2001 From: SUTER Frederic Date: Thu, 20 Jan 2022 11:16:49 +0100 Subject: [PATCH] more XML cleanup --- MANIFEST.in | 6 +- examples/cpp/CMakeLists.txt | 2 - examples/cpp/energy-boot/s4u-energy-boot.tesh | 4 +- .../s4u-platform-properties.cpp | 40 +++--- .../s4u-platform-properties.tesh | 2 +- .../s4u-platform-properties_d.xml | 10 -- .../energy_boot.xml} | 0 examples/python/CMakeLists.txt | 5 +- examples/python/comm-wait/comm-wait.py | 91 ++++++------- examples/python/comm-wait/comm-wait.tesh | 2 +- examples/python/comm-wait/comm-wait_d.xml | 14 -- examples/python/comm-waitall/comm-waitall.py | 87 +++++------- .../python/comm-waitall/comm-waitall.tesh | 2 +- .../python/comm-waitall/comm-waitall_d.xml | 17 --- examples/python/comm-waitany/comm-waitany.py | 125 ++++++++---------- .../python/comm-waitany/comm-waitany.tesh | 2 +- .../python/comm-waitany/comm-waitany_d.xml | 17 --- tools/cmake/DefinePackages.cmake | 1 + 18 files changed, 157 insertions(+), 270 deletions(-) delete mode 100644 examples/cpp/platform-properties/s4u-platform-properties_d.xml rename examples/{cpp/energy-boot/platform_boot.xml => platforms/energy_boot.xml} (100%) delete mode 100644 examples/python/comm-wait/comm-wait_d.xml delete mode 100644 examples/python/comm-waitall/comm-waitall_d.xml delete mode 100644 examples/python/comm-waitany/comm-waitany_d.xml diff --git a/MANIFEST.in b/MANIFEST.in index efd55f6db4..410129f4eb 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -233,7 +233,6 @@ include examples/cpp/dht-kademlia/s4u-dht-kademlia.cpp include examples/cpp/dht-kademlia/s4u-dht-kademlia.hpp include examples/cpp/dht-kademlia/s4u-dht-kademlia.tesh include examples/cpp/dht-kademlia/s4u-dht-kademlia_d.xml -include examples/cpp/energy-boot/platform_boot.xml include examples/cpp/energy-boot/s4u-energy-boot.cpp include examples/cpp/energy-boot/s4u-energy-boot.tesh include examples/cpp/energy-exec-ptask/s4u-energy-exec-ptask.cpp @@ -337,7 +336,6 @@ include examples/cpp/platform-profile/s4u-platform-profile.cpp include examples/cpp/platform-profile/s4u-platform-profile.tesh include examples/cpp/platform-properties/s4u-platform-properties.cpp include examples/cpp/platform-properties/s4u-platform-properties.tesh -include examples/cpp/platform-properties/s4u-platform-properties_d.xml include examples/cpp/plugin-host-load/s4u-plugin-host-load.cpp include examples/cpp/plugin-host-load/s4u-plugin-host-load.tesh include examples/cpp/plugin-link-load/s4u-plugin-link-load.cpp @@ -1969,6 +1967,7 @@ include examples/platforms/config_tracing.xml include examples/platforms/crosstraffic.xml include examples/platforms/data_center.xml include examples/platforms/dogbone.xml +include examples/platforms/energy_boot.xml include examples/platforms/energy_cluster.xml include examples/platforms/energy_platform.xml include examples/platforms/faulty_host.xml @@ -2028,9 +2027,6 @@ include examples/platforms/wifi_ns3.xml include examples/python/CMakeLists.txt include examples/python/actor-create/actor-create_d.xml include examples/python/actor-lifetime/actor-lifetime_d.xml -include examples/python/comm-wait/comm-wait_d.xml -include examples/python/comm-waitall/comm-waitall_d.xml -include examples/python/comm-waitany/comm-waitany_d.xml include examples/smpi/CMakeLists.txt include examples/smpi/NAS/CMakeLists.txt include examples/smpi/comm_dynamic_costs/CMakeLists.txt diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt index beff957147..8cf74e5b67 100644 --- a/examples/cpp/CMakeLists.txt +++ b/examples/cpp/CMakeLists.txt @@ -231,9 +231,7 @@ set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/actor-create/s4u-a ${CMAKE_CURRENT_SOURCE_DIR}/dag-scheduling/Montage_25.xml ${CMAKE_CURRENT_SOURCE_DIR}/dht-chord/s4u-dht-chord_d.xml ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/s4u-dht-kademlia_d.xml - ${CMAKE_CURRENT_SOURCE_DIR}/energy-boot/platform_boot.xml ${CMAKE_CURRENT_SOURCE_DIR}/io-file-remote/s4u-io-file-remote_d.xml - ${CMAKE_CURRENT_SOURCE_DIR}/platform-properties/s4u-platform-properties_d.xml ${CMAKE_CURRENT_SOURCE_DIR}/platform-failures/s4u-platform-failures_d.xml ${CMAKE_CURRENT_SOURCE_DIR}/replay-comm/s4u-replay-comm-split_d.xml ${CMAKE_CURRENT_SOURCE_DIR}/replay-comm/s4u-replay-comm_d.xml diff --git a/examples/cpp/energy-boot/s4u-energy-boot.tesh b/examples/cpp/energy-boot/s4u-energy-boot.tesh index 43b18b8bbb..c09b50591c 100644 --- a/examples/cpp/energy-boot/s4u-energy-boot.tesh +++ b/examples/cpp/energy-boot/s4u-energy-boot.tesh @@ -2,7 +2,7 @@ p Modeling the host energy consumption during boot and shutdown -$ ${bindir:=.}/s4u-energy-boot ${srcdir:=.}/platform_boot.xml "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" +$ ${bindir:=.}/s4u-energy-boot ${platfdir:=.}/energy_boot.xml "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" > [ 0.000000] (1:Boot Monitor@MyHost2) Initial pstate: 0; Energy dissipated so far:0E+00 J > [ 0.000000] (1:Boot Monitor@MyHost2) Sleep for 10 seconds > [ 10.000000] (1:Boot Monitor@MyHost2) Done sleeping. Current pstate: 0; Energy dissipated so far: 950.00 J @@ -23,7 +23,7 @@ $ ${bindir:=.}/s4u-energy-boot ${srcdir:=.}/platform_boot.xml "--log=root.fmt:[% > [177.000000] (0:maestro@) Energy consumption of host MyHost1: 19820.000000 Joules > [177.000000] (0:maestro@) Energy consumption of host MyHost2: 17700.000000 Joules -$ ${bindir:=.}/s4u-energy-boot ${srcdir:=.}/platform_boot.xml "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" --cfg=host/model:ptask_L07 +$ ${bindir:=.}/s4u-energy-boot ${platfdir:=.}/energy_boot.xml "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" --cfg=host/model:ptask_L07 > [ 0.000000] (0:maestro@) Configuration change: Set 'host/model' to 'ptask_L07' > [ 0.000000] (0:maestro@) Switching to the L07 model to handle parallel tasks. > [ 0.000000] (1:Boot Monitor@MyHost2) Initial pstate: 0; Energy dissipated so far:0E+00 J diff --git a/examples/cpp/platform-properties/s4u-platform-properties.cpp b/examples/cpp/platform-properties/s4u-platform-properties.cpp index 777f61a35e..14e166f63f 100644 --- a/examples/cpp/platform-properties/s4u-platform-properties.cpp +++ b/examples/cpp/platform-properties/s4u-platform-properties.cpp @@ -10,10 +10,11 @@ #include XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Property test"); +namespace sg4 = simgrid::s4u; static void test_host(const std::string& hostname) { - simgrid::s4u::Host* thehost = simgrid::s4u::Host::by_name(hostname); + sg4::Host* thehost = sg4::Host::by_name(hostname); const std::unordered_map* hostprops = thehost->get_properties(); const char* noexist = "Unknown"; const char* exist = "Hdd"; @@ -62,37 +63,37 @@ static void test_host(const std::string& hostname) XBT_INFO(" Zone property: '%s' -> '%s'", key.c_str(), zoneprops->at(key).c_str()); } -static void alice(std::vector /*args*/) +static void alice() { /* Dump what we have on the current host */ test_host("host1"); } -static void carole(std::vector /*args*/) +static void carole() { /* Dump what we have on a remote host */ - simgrid::s4u::this_actor::sleep_for(1); // Wait for alice to be done with its experiment + sg4::this_actor::sleep_for(1); // Wait for alice to be done with its experiment test_host("host1"); } -static void david(std::vector /*args*/) +static void david() { /* Dump what we have on a remote host */ - simgrid::s4u::this_actor::sleep_for(2); // Wait for alice and carole to be done with its experiment + sg4::this_actor::sleep_for(2); // Wait for alice and carole to be done with its experiment test_host("node-0.simgrid.org"); } -static void bob(std::vector /*args*/) +static void bob() { /* this host also tests the properties of the AS*/ - const simgrid::s4u::NetZone* root = simgrid::s4u::Engine::get_instance()->get_netzone_root(); + const sg4::NetZone* root = sg4::Engine::get_instance()->get_netzone_root(); XBT_INFO("== Print the properties of the root zone"); XBT_INFO(" Zone property: filename -> %s", root->get_property("filename")); XBT_INFO(" Zone property: date -> %s", root->get_property("date")); XBT_INFO(" Zone property: author -> %s", root->get_property("author")); /* Get the property list of current bob actor */ - const std::unordered_map* props = simgrid::s4u::Actor::self()->get_properties(); + const std::unordered_map* props = sg4::Actor::self()->get_properties(); const char* noexist = "UnknownProcessProp"; XBT_ATTRIB_UNUSED const char* value; @@ -102,28 +103,29 @@ static void bob(std::vector /*args*/) XBT_INFO("== Try to get an actor property that does not exist"); - value = simgrid::s4u::Actor::self()->get_property(noexist); + value = sg4::Actor::self()->get_property(noexist); xbt_assert(not value, "The property is defined (it should not)"); } int main(int argc, char* argv[]) { - simgrid::s4u::Engine e(&argc, argv); + sg4::Engine e(&argc, argv); e.load_platform(argv[1]); - - e.register_function("alice", alice); - e.register_function("bob", bob); - e.register_function("carole", carole); - e.register_function("david", david); + auto* host1 = e.host_by_name("host1"); + auto* host2 = e.host_by_name("host2"); size_t totalHosts = e.get_host_count(); XBT_INFO("There are %zu hosts in the environment", totalHosts); - std::vector hosts = e.get_all_hosts(); - for (simgrid::s4u::Host const* host : hosts) + std::vector hosts = e.get_all_hosts(); + for (sg4::Host const* host : hosts) XBT_INFO("Host '%s' runs at %.0f flops/s", host->get_cname(), host->get_speed()); - e.load_deployment(argv[2]); + sg4::Actor::create("alice", host1, alice); + sg4::Actor::create("bob", host1, bob)->set_property("SomeProp", "SomeValue"); + sg4::Actor::create("carole", host2, carole); + sg4::Actor::create("david", host2, david); + e.run(); return 0; diff --git a/examples/cpp/platform-properties/s4u-platform-properties.tesh b/examples/cpp/platform-properties/s4u-platform-properties.tesh index 71e4fecb4c..29b9baa0f6 100644 --- a/examples/cpp/platform-properties/s4u-platform-properties.tesh +++ b/examples/cpp/platform-properties/s4u-platform-properties.tesh @@ -3,7 +3,7 @@ p Testing a S4U application with properties in the XML for Hosts, Links and Actors ! output sort 19 -$ ${bindir:=.}/s4u-platform-properties ${platfdir}/prop.xml s4u-platform-properties_d.xml "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" +$ ${bindir:=.}/s4u-platform-properties ${platfdir}/prop.xml "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" > [ 0.000000] (0:maestro@) There are 7 hosts in the environment > [ 0.000000] (0:maestro@) Host 'host1' runs at 1000000000 flops/s > [ 0.000000] (0:maestro@) Host 'host2' runs at 1000000000 flops/s diff --git a/examples/cpp/platform-properties/s4u-platform-properties_d.xml b/examples/cpp/platform-properties/s4u-platform-properties_d.xml deleted file mode 100644 index 3f4bc5a3eb..0000000000 --- a/examples/cpp/platform-properties/s4u-platform-properties_d.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/examples/cpp/energy-boot/platform_boot.xml b/examples/platforms/energy_boot.xml similarity index 100% rename from examples/cpp/energy-boot/platform_boot.xml rename to examples/platforms/energy_boot.xml diff --git a/examples/python/CMakeLists.txt b/examples/python/CMakeLists.txt index 845874ff7e..7a96e1887e 100644 --- a/examples/python/CMakeLists.txt +++ b/examples/python/CMakeLists.txt @@ -19,7 +19,4 @@ endforeach() set(examples_src ${examples_src} PARENT_SCOPE) set(tesh_files ${tesh_files} examples/python/actor-create/actor-create_d.xml - examples/python/actor-lifetime/actor-lifetime_d.xml - examples/python/comm-wait/comm-wait_d.xml - examples/python/comm-waitall/comm-waitall_d.xml - examples/python/comm-waitany/comm-waitany_d.xml PARENT_SCOPE) + examples/python/actor-lifetime/actor-lifetime_d.xml PARENT_SCOPE) diff --git a/examples/python/comm-wait/comm-wait.py b/examples/python/comm-wait/comm-wait.py index 6bd6a908d5..8f4f728e77 100644 --- a/examples/python/comm-wait/comm-wait.py +++ b/examples/python/comm-wait/comm-wait.py @@ -1,9 +1,10 @@ # Copyright (c) 2010-2022. 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. -from simgrid import Engine, Mailbox, this_actor +from simgrid import Actor, Engine, Host, Mailbox, this_actor import sys # This example shows how to use simgrid::s4u::this_actor::wait() to wait for a given communication. @@ -14,61 +15,46 @@ import sys # The sender then loops until there is no ongoing communication. -class Sender: - def __init__(self, *args): - if len(args) != 3: - raise AssertionError( - "Actor sender requires 3 parameters, but got {:d}".format(len(args))) - self.messages_count = int(args[0]) # number of tasks - self.msg_size = int(args[1]) # communication cost (in bytes) - self.receivers_count = int(args[2]) # number of receivers - - def __call__(self): - # List in which we store all ongoing communications - pending_comms = [] - - # Vector of the used mailboxes - mboxes = [Mailbox.by_name("receiver-{:d}".format(i)) for i in range(0, self.receivers_count)] +def sender(messages_count, msg_size, receivers_count): + # List in which we store all ongoing communications + pending_comms = [] - # Start dispatching all messages to receivers, in a round robin fashion - for i in range(0, self.messages_count): - content = "Message {:d}".format(i) - mbox = mboxes[i % self.receivers_count] + # Vector of the used mailboxes + mboxes = [Mailbox.by_name("receiver-{:d}".format(i)) for i in range(0, receivers_count)] - this_actor.info("Send '{:s}' to '{:s}'".format(content, str(mbox))) + # Start dispatching all messages to receivers, in a round robin fashion + for i in range(0, messages_count): + content = "Message {:d}".format(i) + mbox = mboxes[i % receivers_count] - # Create a communication representing the ongoing communication, and store it in pending_comms - comm = mbox.put_async(content, self.msg_size) - pending_comms.append(comm) + this_actor.info("Send '{:s}' to '{:s}'".format(content, str(mbox))) - # Start sending messages to let the workers know that they should stop - for i in range(0, self.receivers_count): - mbox = mboxes[i] - this_actor.info("Send 'finalize' to '{:s}'".format(str(mbox))) - comm = mbox.put_async("finalize", 0) - pending_comms.append(comm) + # Create a communication representing the ongoing communication, and store it in pending_comms + comm = mbox.put_async(content, msg_size) + pending_comms.append(comm) - this_actor.info("Done dispatching all messages") + # Start sending messages to let the workers know that they should stop + for i in range(0, receivers_count): + mbox = mboxes[i] + this_actor.info("Send 'finalize' to '{:s}'".format(str(mbox))) + comm = mbox.put_async("finalize", 0) + pending_comms.append(comm) - # Now that all message exchanges were initiated, wait for their completion, in order of creation. - for comm in pending_comms: - comm.wait() - this_actor.info("Goodbye now!") + this_actor.info("Done dispatching all messages") + # Now that all message exchanges were initiated, wait for their completion, in order of creation. + for comm in pending_comms: + comm.wait() + this_actor.info("Goodbye now!") -class Receiver: - def __init__(self, *args): - if len(args) != 1: # Receiver actor expects 1 argument: its ID - raise AssertionError("Actor receiver requires 1 parameter, but got {:d}".format(len(args))) - self.mbox = Mailbox.by_name("receiver-{:s}".format(args[0])) - - def __call__(self): - this_actor.info("Wait for my first message") - while True: - received = self.mbox.get() - this_actor.info("I got a '{:s}'.".format(received)) - if received == "finalize": - break # If it's a finalize message, we're done. +def receiver(id): + mbox = Mailbox.by_name("receiver-{:d}".format(id)) + this_actor.info("Wait for my first message") + while True: + received = mbox.get() + this_actor.info("I got a '{:s}'.".format(received)) + if received == "finalize": + break # If it's a finalize message, we're done. if __name__ == '__main__': @@ -76,10 +62,7 @@ if __name__ == '__main__': e.load_platform(sys.argv[1]) # Load the platform description - # Register the classes representing the actors - e.register_actor("sender", Sender) - e.register_actor("receiver", Receiver) - - e.load_deployment(sys.argv[2]) - + Actor.create("sender", Host.by_name("Tremblay"), sender, 3, 50000000, 1) + Actor.create("receiver", Host.by_name("Ruby"), receiver, 0) + e.run() diff --git a/examples/python/comm-wait/comm-wait.tesh b/examples/python/comm-wait/comm-wait.tesh index 77c789a3e3..614008d8d6 100644 --- a/examples/python/comm-wait/comm-wait.tesh +++ b/examples/python/comm-wait/comm-wait.tesh @@ -1,6 +1,6 @@ #!/usr/bin/env tesh -$ ${pythoncmd:=python3} ${PYTHON_TOOL_OPTIONS:=} ${bindir:=.}/comm-wait.py ${platfdir}/small_platform_fatpipe.xml comm-wait_d.xml "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" +$ ${pythoncmd:=python3} ${PYTHON_TOOL_OPTIONS:=} ${bindir:=.}/comm-wait.py ${platfdir}/small_platform_fatpipe.xml "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" > [ 0.000000] (1:sender@Tremblay) Send 'Message 0' to 'Mailbox(receiver-0)' > [ 0.000000] (2:receiver@Ruby) Wait for my first message > [ 0.000000] (1:sender@Tremblay) Send 'Message 1' to 'Mailbox(receiver-0)' diff --git a/examples/python/comm-wait/comm-wait_d.xml b/examples/python/comm-wait/comm-wait_d.xml deleted file mode 100644 index 0d0d4738e3..0000000000 --- a/examples/python/comm-wait/comm-wait_d.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/examples/python/comm-waitall/comm-waitall.py b/examples/python/comm-waitall/comm-waitall.py index 0db96ab04f..38a34f148d 100644 --- a/examples/python/comm-waitall/comm-waitall.py +++ b/examples/python/comm-waitall/comm-waitall.py @@ -3,7 +3,7 @@ # 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. -from simgrid import Comm, Engine, Mailbox, this_actor +from simgrid import Actor,Comm, Engine, Host, Mailbox, this_actor import sys # This example shows how to block on the completion of a set of communications. @@ -14,62 +14,49 @@ import sys # The sender then blocks until all ongoing communication terminate, using simgrid.Comm.wait_all() -class Sender: - def __init__(self, *args): - if len(args) != 3: - raise AssertionError("Actor sender requires 3 parameters, but got {:d}".format(len(args))) - self.messages_count = int(args[0]) # number of tasks - self.msg_size = int(args[1]) # communication cost (in bytes) - self.receivers_count = int(args[2]) # number of receivers +def sender(messages_count, msg_size, receivers_count): + # List in which we store all ongoing communications + pending_comms = [] - def __call__(self): - # List in which we store all ongoing communications - pending_comms = [] + # Vector of the used mailboxes + mboxes = [Mailbox.by_name("receiver-{:d}".format(i)) + for i in range(0, receivers_count)] - # Vector of the used mailboxes - mboxes = [Mailbox.by_name("receiver-{:d}".format(i)) - for i in range(0, self.receivers_count)] + # Start dispatching all messages to receivers, in a round robin fashion + for i in range(0, messages_count): + content = "Message {:d}".format(i) + mbox = mboxes[i % receivers_count] - # Start dispatching all messages to receivers, in a round robin fashion - for i in range(0, self.messages_count): - content = "Message {:d}".format(i) - mbox = mboxes[i % self.receivers_count] + this_actor.info("Send '{:s}' to '{:s}'".format(content, str(mbox))) - this_actor.info("Send '{:s}' to '{:s}'".format(content, str(mbox))) + # Create a communication representing the ongoing communication, and store it in pending_comms + comm = mbox.put_async(content, msg_size) + pending_comms.append(comm) - # Create a communication representing the ongoing communication, and store it in pending_comms - comm = mbox.put_async(content, self.msg_size) - pending_comms.append(comm) + # Start sending messages to let the workers know that they should stop + for i in range(0, receivers_count): + mbox = mboxes[i] + this_actor.info("Send 'finalize' to '{:s}'".format(str(mbox))) + comm = mbox.put_async("finalize", 0) + pending_comms.append(comm) - # Start sending messages to let the workers know that they should stop - for i in range(0, self.receivers_count): - mbox = mboxes[i] - this_actor.info("Send 'finalize' to '{:s}'".format(str(mbox))) - comm = mbox.put_async("finalize", 0) - pending_comms.append(comm) + this_actor.info("Done dispatching all messages") - this_actor.info("Done dispatching all messages") + # Now that all message exchanges were initiated, wait for their completion in one single call + Comm.wait_all(pending_comms) - # Now that all message exchanges were initiated, wait for their completion in one single call - Comm.wait_all(pending_comms) + this_actor.info("Goodbye now!") - this_actor.info("Goodbye now!") +def receiver(id): + mbox = Mailbox.by_name("receiver-{:d}".format(id)) -class Receiver: - def __init__(self, *args): - if len(args) != 1: # Receiver actor expects 1 argument: its ID - raise AssertionError( - "Actor receiver requires 1 parameter, but got {:d}".format(len(args))) - self.mbox = Mailbox.by_name("receiver-{:s}".format(args[0])) - - def __call__(self): - this_actor.info("Wait for my first message") - while True: - received = self.mbox.get() - this_actor.info("I got a '{:s}'.".format(received)) - if received == "finalize": - break # If it's a finalize message, we're done. + this_actor.info("Wait for my first message") + while True: + received = mbox.get() + this_actor.info("I got a '{:s}'.".format(received)) + if received == "finalize": + break # If it's a finalize message, we're done. if __name__ == '__main__': @@ -78,10 +65,8 @@ if __name__ == '__main__': # Load the platform description e.load_platform(sys.argv[1]) - # Register the classes representing the actors - e.register_actor("sender", Sender) - e.register_actor("receiver", Receiver) - - e.load_deployment(sys.argv[2]) + Actor.create("sender", Host.by_name("Tremblay"), sender, 5, 1000000, 2) + Actor.create("receiver", Host.by_name("Ruby"), receiver, 0) + Actor.create("receiver", Host.by_name("Perl"), receiver, 1) e.run() diff --git a/examples/python/comm-waitall/comm-waitall.tesh b/examples/python/comm-waitall/comm-waitall.tesh index 12ee89a3d9..32ca46ce01 100644 --- a/examples/python/comm-waitall/comm-waitall.tesh +++ b/examples/python/comm-waitall/comm-waitall.tesh @@ -1,6 +1,6 @@ #!/usr/bin/env tesh -$ ${pythoncmd:=python3} ${PYTHON_TOOL_OPTIONS:=} ${bindir:=.}/comm-waitall.py ${platfdir}/small_platform_fatpipe.xml comm-waitall_d.xml "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" +$ ${pythoncmd:=python3} ${PYTHON_TOOL_OPTIONS:=} ${bindir:=.}/comm-waitall.py ${platfdir}/small_platform_fatpipe.xml "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" > [ 0.000000] (2:receiver@Ruby) Wait for my first message > [ 0.000000] (3:receiver@Perl) Wait for my first message > [ 0.000000] (1:sender@Tremblay) Send 'Message 0' to 'Mailbox(receiver-0)' diff --git a/examples/python/comm-waitall/comm-waitall_d.xml b/examples/python/comm-waitall/comm-waitall_d.xml deleted file mode 100644 index c04e11eeac..0000000000 --- a/examples/python/comm-waitall/comm-waitall_d.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/examples/python/comm-waitany/comm-waitany.py b/examples/python/comm-waitany/comm-waitany.py index 58a0bc14d5..c59ccd0098 100644 --- a/examples/python/comm-waitany/comm-waitany.py +++ b/examples/python/comm-waitany/comm-waitany.py @@ -3,7 +3,7 @@ # 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. -from simgrid import Comm, Engine, Mailbox, this_actor +from simgrid import Actor, Comm, Engine, Host, Mailbox, this_actor import sys # This example shows how to block on the completion of a set of communications. @@ -19,72 +19,57 @@ import sys # processed before 'Message 5' that is sent to worker 0. -class Sender: - def __init__(self, *args): - if len(args) != 3: - raise AssertionError("Actor sender requires 3 parameters, but got {:d}".format(len(args))) - self.messages_count = int(args[0]) # number of tasks - self.msg_size = int(args[1]) # communication cost (in bytes) - self.receivers_count = int(args[2]) # number of receivers - - def __call__(self): - # List in which we store all ongoing communications - pending_comms = [] - - # Vector of the used mailboxes - mboxes = [Mailbox.by_name("receiver-{:d}".format(i)) - for i in range(0, self.receivers_count)] - - # Start dispatching all messages to receivers, in a round robin fashion - for i in range(0, self.messages_count): - content = "Message {:d}".format(i) - mbox = mboxes[i % self.receivers_count] - - this_actor.info("Send '{:s}' to '{:s}'".format(content, str(mbox))) - - # Create a communication representing the ongoing communication, and store it in pending_comms - comm = mbox.put_async(content, self.msg_size) - pending_comms.append(comm) - - # Start sending messages to let the workers know that they should stop - for i in range(0, self.receivers_count): - mbox = mboxes[i] - this_actor.info("Send 'finalize' to '{:s}'".format(str(mbox))) - comm = mbox.put_async("finalize", 0) - pending_comms.append(comm) - - this_actor.info("Done dispatching all messages") - - # Now that all message exchanges were initiated, wait for their completion, in order of completion. - # - # This loop waits for first terminating message with wait_any() and remove it with del, until all comms are - # terminated. - # Even in this simple example, the pending comms do not terminate in the exact same order of creation. - while pending_comms: - changed_pos = Comm.wait_any(pending_comms) - del pending_comms[changed_pos] - if (changed_pos != 0): - this_actor.info( - "Remove the {:d}th pending comm: it terminated earlier than another comm that was initiated first.".format(changed_pos)) - - this_actor.info("Goodbye now!") - - -class Receiver: - def __init__(self, *args): - if len(args) != 1: # Receiver actor expects 1 argument: its ID - raise AssertionError( - "Actor receiver requires 1 parameter, but got {:d}".format(len(args))) - self.mbox = Mailbox.by_name("receiver-{:s}".format(args[0])) - - def __call__(self): - this_actor.info("Wait for my first message") - while True: - received = self.mbox.get() - this_actor.info("I got a '{:s}'.".format(received)) - if received == "finalize": - break # If it's a finalize message, we're done. +def sender(messages_count, msg_size, receivers_count): + # List in which we store all ongoing communications + pending_comms = [] + # Vector of the used mailboxes + mboxes = [Mailbox.by_name("receiver-{:d}".format(i)) + for i in range(0, receivers_count)] + + # Start dispatching all messages to receivers, in a round robin fashion + for i in range(0, messages_count): + content = "Message {:d}".format(i) + mbox = mboxes[i % receivers_count] + + this_actor.info("Send '{:s}' to '{:s}'".format(content, str(mbox))) + + # Create a communication representing the ongoing communication, and store it in pending_comms + comm = mbox.put_async(content, msg_size) + pending_comms.append(comm) + + # Start sending messages to let the workers know that they should stop + for i in range(0, receivers_count): + mbox = mboxes[i] + this_actor.info("Send 'finalize' to '{:s}'".format(str(mbox))) + comm = mbox.put_async("finalize", 0) + pending_comms.append(comm) + + this_actor.info("Done dispatching all messages") + + # Now that all message exchanges were initiated, wait for their completion, in order of completion. + # + # This loop waits for first terminating message with wait_any() and remove it with del, until all comms are + # terminated. + # Even in this simple example, the pending comms do not terminate in the exact same order of creation. + while pending_comms: + changed_pos = Comm.wait_any(pending_comms) + del pending_comms[changed_pos] + if (changed_pos != 0): + this_actor.info( + "Remove the {:d}th pending comm: it terminated earlier than another comm that was initiated first.".format(changed_pos)) + + this_actor.info("Goodbye now!") + + +def receiver(id): + mbox = Mailbox.by_name("receiver-{:d}".format(id)) + this_actor.info("Wait for my first message") + while True: + received = mbox.get() + this_actor.info("I got a '{:s}'.".format(received)) + if received == "finalize": + break # If it's a finalize message, we're done. if __name__ == '__main__': e = Engine(sys.argv) @@ -92,10 +77,8 @@ if __name__ == '__main__': # Load the platform description e.load_platform(sys.argv[1]) - # Register the classes representing the actors - e.register_actor("sender", Sender) - e.register_actor("receiver", Receiver) - - e.load_deployment(sys.argv[2]) + Actor.create("sender", Host.by_name("Tremblay"), sender, 6, 1000000, 2) + Actor.create("receiver", Host.by_name("Fafard"), receiver, 0) + Actor.create("receiver", Host.by_name("Jupiter"), receiver, 1) e.run() diff --git a/examples/python/comm-waitany/comm-waitany.tesh b/examples/python/comm-waitany/comm-waitany.tesh index 3acb8f3931..d4593c1ac0 100644 --- a/examples/python/comm-waitany/comm-waitany.tesh +++ b/examples/python/comm-waitany/comm-waitany.tesh @@ -3,7 +3,7 @@ p Testing Comm.wait_any() ! output sort 19 -$ ${pythoncmd:=python3} ${PYTHON_TOOL_OPTIONS:=} ${bindir:=.}/comm-waitany.py ${platfdir}/small_platform.xml comm-waitany_d.xml "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" +$ ${pythoncmd:=python3} ${PYTHON_TOOL_OPTIONS:=} ${bindir:=.}/comm-waitany.py ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" > [ 0.000000] (1:sender@Tremblay) Send 'Message 0' to 'Mailbox(receiver-0)' > [ 0.000000] (2:receiver@Fafard) Wait for my first message > [ 0.000000] (3:receiver@Jupiter) Wait for my first message diff --git a/examples/python/comm-waitany/comm-waitany_d.xml b/examples/python/comm-waitany/comm-waitany_d.xml deleted file mode 100644 index bbaccfc041..0000000000 --- a/examples/python/comm-waitany/comm-waitany_d.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 4f385d9b7d..bdfa923fe3 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -1147,6 +1147,7 @@ set(PLATFORMS_EXAMPLES examples/platforms/profiles/trace_B.txt examples/platforms/data_center.xml examples/platforms/dogbone.xml + examples/platforms/energy_boot.xml examples/platforms/energy_platform.xml examples/platforms/energy_cluster.xml examples/platforms/faulty_host.xml -- 2.20.1