Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
37da76882b7d26dd5c949c463344bc9e8ca10e71
[simgrid.git] / examples / java / commTime / Master.java
1 /* Copyright (c) 2006-2014. 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 commTime;
8
9 import org.simgrid.msg.Host;
10 import org.simgrid.msg.Msg;
11 import org.simgrid.msg.MsgException;
12 import org.simgrid.msg.Process;
13 import org.simgrid.msg.Task;
14
15 public class Master extends Process {
16   public Master(Host host, String name, String[]args) {
17     super(host,name,args);
18   }
19
20   public void main(String[] args) throws MsgException {
21     if (args.length < 4) {
22       Msg.info("Master needs 4 arguments");
23       System.exit(1);
24     }
25
26     int tasksCount = Integer.valueOf(args[0]).intValue();    
27     double taskComputeSize = Double.valueOf(args[1]).doubleValue();    
28     double taskCommunicateSize = Double.valueOf(args[2]).doubleValue();
29
30     int slavesCount = Integer.valueOf(args[3]).intValue();
31
32     Msg.info("Hello! Got "+  slavesCount + " slaves and "+tasksCount+" tasks to process");
33
34     for (int i = 0; i < tasksCount; i++) {
35       Task task = new Task("Task_" + i, taskComputeSize, taskCommunicateSize);
36       if (i%1000==0)
37          Msg.info("Sending \"" + task.getName()+ "\" to \"slave_" + i % slavesCount + "\"");
38          task.send("slave_"+(i%slavesCount));
39        }
40
41     Msg.info("All tasks have been dispatched. Let's tell everybody the computation is over.");
42
43     for (int i = 0; i < slavesCount; i++) {
44       FinalizeTask task = new FinalizeTask();
45       task.send("slave_"+(i%slavesCount));
46     }
47     Msg.info("Goodbye now!");
48   }
49 }