Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
94e00f5146f32c609a552fd4adf41d181876b251
[simgrid.git] / examples / java / masterslave / Master.java
1 /*
2  * Master of a basic master/slave example in Java
3  *
4  * Copyright (c) 2006-2013. The SimGrid Team.
5  * All rights reserved.
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. 
9  */
10
11 package masterslave;
12 import org.simgrid.msg.Host;
13 import org.simgrid.msg.Msg;
14 import org.simgrid.msg.MsgException;
15 import org.simgrid.msg.Task;
16 import org.simgrid.msg.Process;;
17
18 public class Master extends Process {
19         public Master(Host host, String name, String[]args) {
20                 super(host,name,args);
21         } 
22         public void main(String[] args) throws MsgException {
23                 if (args.length < 4) {
24                         Msg.info("Master needs 4 arguments");
25                         System.exit(1);
26                 }
27
28                 int tasksCount = Integer.valueOf(args[0]).intValue();           
29                 double taskComputeSize = Double.valueOf(args[1]).doubleValue();         
30                 double taskCommunicateSize = Double.valueOf(args[2]).doubleValue();
31
32                 int slavesCount = Integer.valueOf(args[3]).intValue();
33
34                 Msg.info("Hello! Got "+  slavesCount + " slaves and "+tasksCount+" tasks to process");
35
36                 for (int i = 0; i < tasksCount; i++) {
37                         Task task = new Task("Task_" + i, taskComputeSize, taskCommunicateSize); 
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 }