Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / examples / java / async / dsend / Sender.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 import java.util.ArrayList;
9
10 import org.simgrid.msg.Msg;
11 import org.simgrid.msg.Comm;
12 import org.simgrid.msg.Host;
13 import org.simgrid.msg.Task;
14 import org.simgrid.msg.Process;
15 import org.simgrid.msg.MsgException;
16
17 public class Sender extends Process {
18   public Sender (Host host, String name){
19     super(host,name);
20   }
21
22   public void main(String[] args) throws MsgException {
23     double taskComputeSize =0;
24     double taskCommunicateSize = 5000000;
25     Host[] hosts = Host.all();
26     int receiverCount = hosts.length - 1;
27
28     Msg.info("Hello! Got "+ receiverCount + " receivers to contact");
29
30     for (int i = 1; i <= receiverCount; i++) {
31       Task task = new Task("Task_" + i, taskComputeSize, taskCommunicateSize); 
32       Msg.info("Sending \"" + task.getName()+ "\" to \"" + hosts[i].getName() + "\"");
33       task.dsend(hosts[i].getName());
34     }
35
36     Msg.info("All tasks have been (asynchronously) dispatched."+
37              " Let's sleep for 10s so that nobody gets a message from a terminated process.");
38
39     waitFor(20);
40
41     Msg.info("Goodbye now!");
42   }
43 }