Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
97ee446941b9ed549b3c0b7f47d2779a5438ecca
[simgrid.git] / examples / java / async / waitAll / Main.java
1 /* Copyright (c) 2006-2014, 2016. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 package async.waitAll;
8
9 /** This example demonstrates the use of the asynchrounous communications
10  * 
11  *  Task.isend() and Task.irecv() are used to start the communications in non-blocking mode.
12  *  
13  *  The sends are then blocked onto with Comm.waitCompletion(), that locks until the given 
14  *  communication terminates.
15  *  
16  *  The receives are packed into an array, and the sender blocks until all of them terminate 
17  *  with Comm.waitAll().
18  */
19
20
21 import org.simgrid.msg.Msg;
22 import org.simgrid.msg.Host;
23 import org.simgrid.msg.NativeException;
24 import org.simgrid.msg.HostNotFoundException;
25
26 class Main {
27   private Main() {
28     throw new IllegalAccessError("Utility class");
29   }
30
31   public static void main(String[] args) throws NativeException, HostNotFoundException {
32     Msg.init(args);
33
34     String platform = "../platforms/small_platform.xml";
35     if (args.length >= 1) {
36         platform = args[0]; // Override the default value if passed on the command line
37     }
38
39     /* construct the platform and deploy the application */
40     Msg.createEnvironment(platform);
41     Host[] hosts = Host.all();
42     new Sender(hosts[0],"Sender").start();
43     for (int i=1; i < hosts.length; i++){
44       new Receiver(hosts[i], "Receiver").start();
45     }
46     /*  execute the simulation. */
47     Msg.run();
48   }
49 }