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