Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
f244276a0d50bd70bf7a5eb6a34d3b5bb2b98531
[simgrid.git] / examples / java / async / dsend / 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.dsend;
8
9 /** This example demonstrates the use of the Task.dsend() method.
10  * 
11  *  This way, the sender can be detached from the communication: it is not blocked as with Task.send() 
12  *  and has nothing to do at the end as with Task.isend() where it must do a Comm.wait().
13  */
14
15 import org.simgrid.msg.Msg;
16 import org.simgrid.msg.Host;
17 import org.simgrid.msg.NativeException;
18 import org.simgrid.msg.HostNotFoundException;
19
20 class Main {
21   private Main() {
22         /* This is just to ensure that nobody creates an instance of this singleton */
23     throw new IllegalAccessError("Utility class");
24   }
25
26   public static void main(String[] args) throws NativeException, HostNotFoundException {
27     Msg.init(args);
28
29     String platform = "../platforms/small_platform.xml";
30     if (args.length >= 1) {
31         platform = args[0]; // Override the default value if passed on the command line
32     }
33
34     /* construct the platform and deploy the application */
35     Msg.createEnvironment(platform);
36     Host[] hosts = Host.all();
37     new Sender(hosts[0],"Sender").start();
38     for (int i=1; i < hosts.length; i++){
39       new Receiver(hosts[i], "Receiver").start();
40     }
41     /*  execute the simulation. */
42     Msg.run();
43   }
44 }