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
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
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
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
${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
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
> [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
#include <string>
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<std::string, std::string>* hostprops = thehost->get_properties();
const char* noexist = "Unknown";
const char* exist = "Hdd";
XBT_INFO(" Zone property: '%s' -> '%s'", key.c_str(), zoneprops->at(key).c_str());
}
-static void alice(std::vector<std::string> /*args*/)
+static void alice()
{
/* Dump what we have on the current host */
test_host("host1");
}
-static void carole(std::vector<std::string> /*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<std::string> /*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<std::string> /*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<std::string, std::string>* props = simgrid::s4u::Actor::self()->get_properties();
+ const std::unordered_map<std::string, std::string>* props = sg4::Actor::self()->get_properties();
const char* noexist = "UnknownProcessProp";
XBT_ATTRIB_UNUSED const char* value;
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<simgrid::s4u::Host*> hosts = e.get_all_hosts();
- for (simgrid::s4u::Host const* host : hosts)
+ std::vector<sg4::Host*> 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;
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
+++ /dev/null
-<?xml version='1.0'?>
-<!DOCTYPE platform SYSTEM "https://simgrid.org/simgrid.dtd">
-<platform version="4.1">
- <actor host="host1" function="alice" />
- <actor host="host1" function="bob">
- <prop id="SomeProp" value="SomeValue"/>
- </actor>
- <actor host="host2" function="carole" />
- <actor host="host2" function="david" />
-</platform>
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)
# 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.
# 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__':
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()
#!/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)'
+++ /dev/null
-<?xml version='1.0'?>
-<!DOCTYPE platform SYSTEM "https://simgrid.org/simgrid.dtd">
-<platform version="4.1">
- <!-- The master actor (with some arguments) -->
- <actor host="Tremblay" function="sender">
- <argument value="3"/> <!-- Number of tasks -->
- <argument value="50000000"/> <!-- Computation size of tasks -->
- <argument value="1"/> <!-- Number of receivers -->
- </actor>
- <!-- The receiver actor -->
- <actor host="Ruby" function="receiver">
- <argument value="0"/> <!-- id -->
- </actor>
-</platform>
# 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.
# 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__':
# 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()
#!/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)'
+++ /dev/null
-<?xml version='1.0'?>
-<!DOCTYPE platform SYSTEM "https://simgrid.org/simgrid.dtd">
-<platform version="4.1">
- <!-- The master actor (with some arguments) -->
- <actor host="Tremblay" function="sender">
- <argument value="5"/> <!-- Number of messages -->
- <argument value="1000000"/> <!-- Size of messages -->
- <argument value="2"/> <!-- Number of receivers -->
- </actor>
- <!-- The receiver actors -->
- <actor host="Ruby" function="receiver">
- <argument value="0"/>
- </actor>
- <actor host="Perl" function="receiver">
- <argument value="1"/>
- </actor>
-</platform>
# 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.
# 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)
# 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()
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
+++ /dev/null
-<?xml version='1.0'?>
-<!DOCTYPE platform SYSTEM "https://simgrid.org/simgrid.dtd">
-<platform version="4.1">
- <!-- The master actor (with some arguments) -->
- <actor host="Tremblay" function="sender">
- <argument value="6"/> <!-- Number of messages -->
- <argument value="1000000"/> <!-- Size of messages -->
- <argument value="2"/> <!-- Number of receivers -->
- </actor>
- <!-- The receiver actors -->
- <actor host="Fafard" function="receiver">
- <argument value="0"/> <!-- My name -->
- </actor>
- <actor host="Jupiter" function="receiver">
- <argument value="1"/> <!-- My name -->
- </actor>
-</platform>
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