Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
further cleanups to please sonar
[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.MsgException;
24
25 class Main {
26   private Main() {
27     throw new IllegalAccessError("Utility class");
28   }
29
30   public static void main(String[] args) throws MsgException {
31     Msg.init(args);
32
33     String platform = "../platforms/small_platform.xml";
34     if (args.length >= 1) {
35         platform = args[0]; // Override the default value if passed on the command line
36     }
37
38     /* construct the platform and deploy the application */
39     Msg.createEnvironment(platform);
40     Host[] hosts = Host.all();
41     new Sender(hosts[0],"Sender").start();
42     for (int i=1; i < hosts.length; i++){
43       new Receiver(hosts[i], "Receiver").start();
44     }
45     /*  execute the simulation. */
46     Msg.run();
47   }
48 }