Logo AND Algorithmique Numérique Distribuée

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