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 {
15 public void main(String[] args) throws JniException, NativeException {
17 Msg.info("Hello i'm the master");
19 int numberoftasks = Integer.valueOf(args[0]).intValue();
20 double taskComputeSize = Double.valueOf(args[1]).doubleValue();
21 double taskCommunicateSize = Double.valueOf(args[2]).doubleValue();
23 int slavecount = args.length - 3;
24 Host[] slaves = new Host[slavecount] ;
26 for (int i = 3; i < args.length; i++) {
28 slaves[i-3] = Host.getByName(args[i]);
29 } catch(HostNotFoundException e) {
30 Msg.info(e.toString());
31 Msg.info("Unknown host " + args[i] +". Stopping Now! " );
36 Msg.info("Got " + slavecount + " slave(s):");
37 for (int i = 0; i < slavecount; i++)
38 Msg.info("\t " + slaves[i].getName());
40 Msg.info("Got "+numberoftasks+" task(s) to process.");
42 Channel channel = new Channel(0);
44 for (int i = 0; i < numberoftasks; i++) {
45 CommTimeTask task = new CommTimeTask("Task_" + i ,taskComputeSize,taskCommunicateSize);
46 task.setTime(Msg.getClock());
47 channel.put(task,slaves[i % slavecount]);
49 // Msg.info("Send completed for the task " + task.getName() + " on the host " + slaves[i % slavecount].getName() + " [" + (i % slavecount) + "]");
52 Msg.info("All tasks have been dispatched. Let's tell everybody the computation is over.");
54 for (int i = 0; i < slavecount; i++) {
56 CommTimeTask task = new CommTimeTask("finalize_" + i,0,0);
59 Msg.info("Send task to host : " + slaves[i].getName());
60 channel.put(task,slaves[i]);
62 Msg.info("Send completed " + slaves[i].getName() + " [" + i + "]");
65 Msg.info("All finalize messages have been dispatched. Goodbye now!");