1 /* Master of a basic master/slave example in Java */
3 /* Copyright (c) 2006-2014. The SimGrid Team.
4 * All rights reserved. */
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. */
10 import org.simgrid.msg.Host;
11 import org.simgrid.msg.Msg;
12 import org.simgrid.msg.MsgException;
13 import org.simgrid.msg.Task;
14 import org.simgrid.msg.Process;;
16 public class Master extends Process {
17 public Master(Host host, String name, String[]args) {
18 super(host,name,args);
20 public void main(String[] args) throws MsgException {
21 if (args.length < 4) {
22 Msg.info("Master needs 4 arguments");
26 int tasksCount = Integer.valueOf(args[0]).intValue();
27 double taskComputeSize = Double.valueOf(args[1]).doubleValue();
28 double taskCommunicateSize = Double.valueOf(args[2]).doubleValue();
30 int slavesCount = Integer.valueOf(args[3]).intValue();
32 Msg.info("Hello! Got "+ slavesCount + " slaves and "+tasksCount+" tasks to process");
34 for (int i = 0; i < tasksCount; i++) {
35 Task task = new Task("Task_" + i, taskComputeSize, taskCommunicateSize);
36 //Msg.info("Sending \"" + task.getName()+ "\" to \"slave_" + i % slavesCount + "\"");
37 task.send("slave_"+(i%slavesCount));
40 Msg.info("All tasks have been dispatched. Let's tell everybody the computation is over.");
42 for (int i = 0; i < slavesCount; i++) {
43 FinalizeTask task = new FinalizeTask();
44 task.send("slave_"+(i%slavesCount));
47 Msg.info("Goodbye now!");