4 * Copyright 2006,2007 Martin Quinson, Malek Cherier
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 public class Master extends simgrid.msg.Process {
14 public void main(String[] args) throws JniException, NativeException {
20 Msg.info("argc="+args.length);
21 for (int i = 0; i<args.length; i++)
22 Msg.info("argv:"+args[i]);
24 if (args.length < 3) {
25 Msg.info("Master needs 3 arguments");
29 int numberOfTasks = Integer.valueOf(args[0]).intValue();
30 double taskComputeSize = Double.valueOf(args[1]).doubleValue();
31 double taskCommunicateSize = Double.valueOf(args[2]).doubleValue();
32 BasicTask[] todo = new BasicTask[numberOfTasks];
34 for (int i = 0; i < numberOfTasks; i++) {
35 todo[i] = new BasicTask("Task_" + i, taskComputeSize, taskCommunicateSize);
38 slaveCount = args.length - 3;
39 slaves = new Host[slaveCount];
41 for(int i = 3; i < args.length ; i++) {
43 slaves[i-3] = Host.getByName(args[i]);
45 catch(HostNotFoundException e) {
46 Msg.info("Unknown host " + args[i] + ". Stopping Now!");
52 Msg.info("Got "+ slaveCount + " slave(s) :");
54 for (int i = 0; i < slaveCount; i++)
55 Msg.info("\t"+slaves[i].getName());
57 Msg.info("Got "+ numberOfTasks + " task to process.");
59 Channel channel = new Channel(0);
61 for (int i = 0; i < numberOfTasks; i++) {
62 Msg.info("Sending \"" + todo[i].getName()+ "\" to \"" + slaves[i % slaveCount].getName() + "\"");
64 if((Host.currentHost()).equals(slaves[i % slaveCount]))
65 Msg.info("Hey ! It's me ! ");
67 channel.put(todo[i], slaves[i % slaveCount]);
70 Msg.info("Send completed");
72 Msg.info("All tasks have been dispatched. Let's tell everybody the computation is over.");
74 for (int i = 0; i < slaveCount; i++) {
75 channel.put(new FinalizeTask(),slaves[i]);
78 Msg.info("Goodbye now!");