Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
9193702e3286eee909ca808ed9db3325edb83cd7
[simgrid.git] / examples / java / commTime / Master.java
1 /* Master of a basic master/slave example in Java */
2
3 /* Copyright (c) 2006-2014. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 package commTime;
10
11 import org.simgrid.msg.Host;
12 import org.simgrid.msg.Msg;
13 import org.simgrid.msg.MsgException;
14 import org.simgrid.msg.Process;
15 import org.simgrid.msg.Task;
16
17 public class Master extends Process {
18         public Master(Host host, String name, String[]args) {
19                 super(host,name,args);
20         } 
21         public void main(String[] args) throws MsgException {
22       if (args.length < 4) {
23          Msg.info("Master needs 4 arguments");
24          System.exit(1);
25       }
26       
27       int tasksCount = Integer.valueOf(args[0]).intValue();             
28       double taskComputeSize = Double.valueOf(args[1]).doubleValue();           
29       double taskCommunicateSize = Double.valueOf(args[2]).doubleValue();
30       
31       int slavesCount = Integer.valueOf(args[3]).intValue();
32       
33       Msg.info("Hello! Got "+  slavesCount + " slaves and "+tasksCount+" tasks to process");
34       
35       for (int i = 0; i < tasksCount; i++) {
36          Task task = new Task("Task_" + i, taskComputeSize, taskCommunicateSize);
37          if (i%1000==0)
38            Msg.info("Sending \"" + task.getName()+ "\" to \"slave_" + i % slavesCount + "\"");
39          task.send("slave_"+(i%slavesCount));
40       }
41       
42       Msg.info("All tasks have been dispatched. Let's tell everybody the computation is over.");
43       
44       for (int i = 0; i < slavesCount; i++) {
45          FinalizeTask task = new FinalizeTask();
46          task.send("slave_"+(i%slavesCount));
47       }
48       
49       Msg.info("Goodbye now!");
50     }
51 }