examples/java/app/pingpong/java_app_pingpong_compiled
examples/java/app/tokenring/java_app_tokenring_compiled
examples/java/async/dsend/java_async_dsend_compiled
+examples/java/async/waitAll/java_async_waitAll_compiled
examples/java/dht/chord/java_dht_chord_compiled
examples/java/dht/kademlia/java_dht_kademlia_compiled
examples/java/cloud/masterworker/java_cloud_masterworker_compiled
Java:
* New function: msg.Comm.waitAll()
* ex/app_tokenring: new example, very similar to the MSG Token Ring
+ * ex/async_waitAll: new example, on asynchronous communications
-- $date Da SimGrid team <simgrid-devel@lists.gforge.inria.fr>
set (srcdir ${CMAKE_CURRENT_SOURCE_DIR}/app/tokenring)
set(app_tokenring_sources ${srcdir}/Main.java ${srcdir}/RelayRunner.java)
+set (srcdir ${CMAKE_CURRENT_SOURCE_DIR}/async/waitAll)
+set(async_waitAll_sources ${srcdir}/Main.java ${srcdir}/Receiver.java ${srcdir}/Sender.java)
+
set (srcdir ${CMAKE_CURRENT_SOURCE_DIR}/async/dsend)
set(async_dsend_sources ${srcdir}/Main.java ${srcdir}/Receiver.java ${srcdir}/Sender.java)
set (srcdir ${CMAKE_CURRENT_SOURCE_DIR}/task/priority)
set(task_priority_sources ${srcdir}/Main.java ${srcdir}/Test.java)
-foreach (example app_bittorrent app_centralizedmutex app_masterworker app_pingpong app_tokenring async_dsend
+foreach (example app_bittorrent app_centralizedmutex app_masterworker app_pingpong app_tokenring async_waitAll async_dsend
cloud_migration cloud_masterworker dht_chord dht_kademlia energy_consumption energy_vm io_file io_storage
process_kill process_migration process_startkilltime process_suspend task_priority trace_pingpong)
string (REPLACE "_" "/" example_dir ${example})
${CMAKE_CURRENT_SOURCE_DIR}/task/priority/priority.xml PARENT_SCOPE)
if(enable_java)
- foreach (example app_bittorrent app_centralizedmutex app_masterworker app_pingpong app_tokenring async_dsend
+ foreach (example app_bittorrent app_centralizedmutex app_masterworker app_pingpong app_tokenring async_waitAll async_dsend
cloud_migration cloud_masterworker dht_chord dht_kademlia energy_consumption energy_vm io_file io_storage
process_kill process_migration process_startkilltime process_suspend task_priority trace_pingpong)
string (REPLACE "_" "/" example_dir ${example})
--- /dev/null
+/* Copyright (c) 2006-2014, 2016. 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. */
+
+package async.waitAll;
+
+/** This example demonstrates the use of the asynchrounous communications
+ *
+ * Task.isend() and Task.irecv() are used to start the communications in non-blocking mode.
+ *
+ * The sends are then blocked onto with Comm.waitCompletion(), that locks until the given
+ * communication terminates.
+ *
+ * The receives are packed into an array, and the sender blocks until all of them terminate
+ * with Comm.waitAll().
+ */
+
+
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.Host;
+import org.simgrid.msg.NativeException;
+import org.simgrid.msg.HostNotFoundException;
+
+class Main {
+ private Main() {
+ throw new IllegalAccessError("Utility class");
+ }
+
+ public static void main(String[] args) throws NativeException, HostNotFoundException {
+ Msg.init(args);
+
+ String platform = "../platforms/small_platform.xml";
+ if (args.length >= 1) {
+ platform = args[0]; // Override the default value if passed on the command line
+ }
+
+ /* construct the platform and deploy the application */
+ Msg.createEnvironment(platform);
+ Host[] hosts = Host.all();
+ new Sender(hosts[0],"Sender").start();
+ for (int i=1; i < hosts.length; i++){
+ new Receiver(hosts[i], "Receiver").start();
+ }
+ /* execute the simulation. */
+ Msg.run();
+ }
+}
--- /dev/null
+/* Copyright (c) 2006-2007, 2010, 2013-2014, 2016. 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. */
+
+package async.waitAll;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.Comm;
+import org.simgrid.msg.Host;
+import org.simgrid.msg.Task;
+import org.simgrid.msg.Process;
+import org.simgrid.msg.HostFailureException;
+import org.simgrid.msg.TimeoutException;
+import org.simgrid.msg.TransferFailureException;
+
+public class Receiver extends Process {
+ public Receiver (Host host, String name) {
+ super(host,name);
+ }
+
+ public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
+ Comm comm = Task.irecv(getHost().getName());
+ Msg.info("I started receiving on '"+ getHost().getName() +". Wait 0.1 second, and block on the communication.");
+ waitFor(0.1);
+ try {
+ comm.waitCompletion();
+ } catch (TimeoutException e) {
+ Msg.info("Timeout while waiting for my task");
+ return; // Stop this process
+ }
+ Msg.info("I got my task, good bye.");
+ }
+}
\ No newline at end of file
--- /dev/null
+/* Copyright (c) 2006-2014, 2016. 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. */
+
+package async.waitAll;
+
+import org.simgrid.msg.Comm;
+import org.simgrid.msg.Host;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.MsgException;
+import org.simgrid.msg.Process;
+import org.simgrid.msg.Task;
+
+public class Sender extends Process {
+ public Sender (Host host, String name){
+ super(host,name);
+ }
+
+ public void main(String[] args) throws MsgException {
+ double taskComputeSize =0;
+ double taskCommunicateSize = 5000000;
+ Host[] hosts = Host.all();
+ int receiverCount = hosts.length - 1;
+
+ Msg.info("I have "+ receiverCount + " receivers to contact");
+
+ Comm[] communicators = new Comm[receiverCount];
+ for (int i = 1; i <= receiverCount; i++) {
+ Task task = new Task("Task_" + i, taskComputeSize, taskCommunicateSize);
+ Msg.info("Start the Sending '" + task.getName()+ "' to '" + hosts[i].getName() + "'");
+ communicators[i-1] = task.isend(hosts[i].getName());
+ }
+
+ Msg.info("All tasks have been (asynchronously) dispatched. Let's wait for their completion.");
+ Comm.waitAll(communicators);
+
+ Msg.info("Goodbye now!");
+ }
+}
--- /dev/null
+#! tesh
+
+$ java -classpath ${classpath:=.} async/waitAll/Main ${srcdir:=.}/../platforms/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [ 0.000000] (0:maestro@) Using regular java threads.
+> [ 0.000000] (1:Sender@Jacquelin) I have 6 receivers to contact
+> [ 0.000000] (1:Sender@Jacquelin) Start the Sending 'Task_1' to 'Fafard'
+> [ 0.000000] (1:Sender@Jacquelin) Start the Sending 'Task_2' to 'Tremblay'
+> [ 0.000000] (2:Receiver@Fafard) I started receiving on 'Fafard. Wait 0.1 second, and block on the communication.
+> [ 0.000000] (3:Receiver@Tremblay) I started receiving on 'Tremblay. Wait 0.1 second, and block on the communication.
+> [ 0.000000] (4:Receiver@Bourassa) I started receiving on 'Bourassa. Wait 0.1 second, and block on the communication.
+> [ 0.000000] (5:Receiver@Jupiter) I started receiving on 'Jupiter. Wait 0.1 second, and block on the communication.
+> [ 0.000000] (6:Receiver@Boivin) I started receiving on 'Boivin. Wait 0.1 second, and block on the communication.
+> [ 0.000000] (7:Receiver@Ginette) I started receiving on 'Ginette. Wait 0.1 second, and block on the communication.
+> [ 0.000000] (1:Sender@Jacquelin) Start the Sending 'Task_3' to 'Bourassa'
+> [ 0.000000] (1:Sender@Jacquelin) Start the Sending 'Task_4' to 'Jupiter'
+> [ 0.000000] (1:Sender@Jacquelin) Start the Sending 'Task_5' to 'Boivin'
+> [ 0.000000] (1:Sender@Jacquelin) Start the Sending 'Task_6' to 'Ginette'
+> [ 0.000000] (1:Sender@Jacquelin) All tasks have been (asynchronously) dispatched. Let's wait for their completion.
+> [ 6.801793] (4:Receiver@Bourassa) I got my task, good bye.
+> [ 6.801793] (5:Receiver@Jupiter) I got my task, good bye.
+> [ 6.801793] (7:Receiver@Ginette) I got my task, good bye.
+> [ 11.931226] (3:Receiver@Tremblay) I got my task, good bye.
+> [ 12.364875] (2:Receiver@Fafard) I got my task, good bye.
+> [ 12.575806] (6:Receiver@Boivin) I got my task, good bye.
+> [ 12.575806] (1:Sender@Jacquelin) Goodbye now!
+> [ 12.575806] (0:maestro@) MSG_main finished; Cleaning up the simulation...