System.exit(1);
}
- /* specify a paje output file. */
- Msg.pajeOutput("basic.trace");
-
/* construct the platform and deploy the application */
Msg.createEnvironment(args[0]);
Msg.deployApplication(args[1]);
/*
* $Id$
*
- * Copyright 2006,2007 Martin Quinson, Malek Cherier
+ * Copyright 2006,2007,2010 The SimGrid Team
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
public class Forwarder extends simgrid.msg.Process {
public void main(String[] args) throws JniException, NativeException {
- Msg.info("hello!");
-
- int slavesCount = args.length;
- Host[] slaves = new Host[slavesCount];
-
- for (int i = 0; i < args.length; i++) {
- try {
- slaves[i] = Host.getByName(args[i]);
- } catch (HostNotFoundException e) {
- Msg.info("Buggy deployment file");
- e.printStackTrace();
- System.exit(1);
- }
+ if (args.length < 3) {
+ Msg.info("Forwarder needs 3 arguments (input mailbox, first output mailbox, last one)");
+ Msg.info("Got "+args.length+" instead");
+ System.exit(1);
}
+ int input = Integer.valueOf(args[0]).intValue();
+ int firstOutput = Integer.valueOf(args[1]).intValue();
+ int lastOutput = Integer.valueOf(args[2]).intValue();
int taskCount = 0;
+ int slavesCount = lastOutput - firstOutput + 1;
+ Msg.info("Receiving on 'slave_"+input+"'");
while(true) {
- Task t = Task.get(0);
+ Task t = Task.receive("slave_"+input);
if (t instanceof FinalizeTask) {
- Msg.info("All tasks have been dispatched. Let's tell everybody the computation is over.");
+ Msg.info("Got a finalize task. Let's forward that we're done.");
- for (int cpt = 0; cpt<slavesCount; cpt++) {
- slaves[cpt].put(0,new FinalizeTask());
+ for (int cpt = firstOutput; cpt<=lastOutput; cpt++) {
+ Task tf = new FinalizeTask();
+ tf.send("slave_"+cpt);
}
break;
}
BasicTask task = (BasicTask)t;
+ int dest = firstOutput + (taskCount % slavesCount);
- Msg.info("Received \"" + task.getName() + "\" ");
-
- Msg.info("Sending \"" + task.getName() + "\" to \"" + slaves[taskCount % slavesCount].getName() + "\"");
- slaves[taskCount % slavesCount].put(0, task);
+ Msg.info("Sending \"" + task.getName() + "\" to \"slave_" + dest + "\"");
+ task.send("slave_"+dest);
taskCount++;
}
/*
- * $Id$
+ * Master of a basic master/slave example in Java
*
- * Copyright 2006,2007 Martin Quinson, Malek Cherier
- * All rights reserved.
+ * Copyright 2006,2007,2010 The SimGrid Team. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package.
public class Master extends simgrid.msg.Process {
public void main(String[] args) throws JniException, NativeException {
- int channel = 0;
- Msg.info("hello!");
-
- int slaveCount = 0;
- Host[] slaves = null;
-
- Msg.info("argc="+args.length);
- for (int i = 0; i<args.length; i++)
- Msg.info("argv:"+args[i]);
-
- if (args.length < 3) {
- Msg.info("Master needs 3 arguments");
+ if (args.length < 4) {
+ Msg.info("Master needs 4 arguments");
System.exit(1);
}
- int numberOfTasks = Integer.valueOf(args[0]).intValue();
+ int tasksCount = Integer.valueOf(args[0]).intValue();
double taskComputeSize = Double.valueOf(args[1]).doubleValue();
double taskCommunicateSize = Double.valueOf(args[2]).doubleValue();
- BasicTask[] todo = new BasicTask[numberOfTasks];
- for (int i = 0; i < numberOfTasks; i++) {
- todo[i] = new BasicTask("Task_" + i, taskComputeSize, taskCommunicateSize);
- }
+ int slavesCount = Integer.valueOf(args[3]).intValue();
- slaveCount = args.length - 3;
- slaves = new Host[slaveCount];
+ Msg.info("Hello! Got "+ slavesCount + " slaves and "+tasksCount+" tasks to process");
- for(int i = 3; i < args.length ; i++) {
- try {
- slaves[i-3] = Host.getByName(args[i]);
- }
- catch(HostNotFoundException e) {
- Msg.info("Unknown host " + args[i] + ". Stopping Now!");
- e.printStackTrace();
- System.exit(1);
- }
+ for (int i = 0; i < tasksCount; i++) {
+ BasicTask task = new BasicTask("Task_" + i, taskComputeSize, taskCommunicateSize);
+ Msg.info("Sending \"" + task.getName()+ "\" to \"slave_" + i % slavesCount + "\"");
+ task.send("slave_"+(i%slavesCount));
}
- Msg.info("Got "+ slaveCount + " slave(s) :");
-
- for (int i = 0; i < slaveCount; i++)
- Msg.info("\t"+slaves[i].getName());
-
- Msg.info("Got "+ numberOfTasks + " task to process.");
-
- for (int i = 0; i < numberOfTasks; i++) {
- Msg.info("Sending \"" + todo[i].getName()+ "\" to \"" + slaves[i % slaveCount].getName() + "\"");
-
- if((Host.currentHost()).equals(slaves[i % slaveCount]))
- Msg.info("Hey ! It's me ! ");
-
- slaves[i % slaveCount].put(channel, todo[i]);
- }
-
- Msg.info("Send completed");
-
Msg.info("All tasks have been dispatched. Let's tell everybody the computation is over.");
- for (int i = 0; i < slaveCount; i++) {
- slaves[i].put(channel, new FinalizeTask());
+ for (int i = 0; i < slavesCount; i++) {
+ FinalizeTask task = new FinalizeTask();
+ task.send("slave_"+(i%slavesCount));
}
Msg.info("Goodbye now!");
public class Slave extends simgrid.msg.Process {
public void main(String[] args) throws JniException, NativeException {
- Msg.info("Hello !");
+ if (args.length < 1) {
+ Msg.info("Slave needs 1 argument (its number)");
+ System.exit(1);
+ }
+
+ int num = Integer.valueOf(args[0]).intValue();
+ Msg.info("Receiving on 'slave_"+num+"'");
while(true) {
- Task t = Task.get(0);
+ Task t = Task.receive("slave_"+num);
if (t instanceof FinalizeTask) {
break;
}
BasicTask task = (BasicTask)t;
- Msg.info("Received \"" + task.getName() + "\" ");
-
- Msg.info("Processing \"" + task.getName() + "\" ");
+ Msg.info("Received \"" + task.getName() + "\". Processing it.");
task.execute();
Msg.info("\"" + task.getName() + "\" done ");
}
<!DOCTYPE platform SYSTEM "simgrid.dtd">
<platform version="2">
<process host="Jacquelin" function="Master">
- <argument value="5"/>
- <argument value="50000"/>
- <argument value="10"/>
- <argument value="iRMX"/>
- <argument value="Casavant"/>
- <argument value="Bousquet"/>
- <argument value="Soucy"/>
- <argument value="Jackson"/>
+ <argument value="5"/> <!-- Amount of tasks to dispatch -->
+ <argument value="50000"/> <!-- Computation size of each task -->
+ <argument value="10"/> <!-- Communication size of each one -->
+ <argument value="7"/> <!-- Amount of slaves waiting for orders -->
</process>
+
<process host="Jackson" function="Forwarder">
- <argument value="Kuenning"/>
- <argument value="Browne"/>
- <argument value="Stephen"/>
- </process>
+ <argument value="0"/> <!-- Input mailbox -->
+ <argument value="7"/> <!-- First output mailbox -->
+ <argument value="8"/> <!-- Last output mailbox -->
+ </process>
<process host="Casavant" function="Forwarder">
- <argument value="Robert"/>
- <argument value="Sirois"/>
- <argument value="Monique"/>
- </process>
- <process host="iRMX" function="Slave"/>
- <process host="Bousquet" function="Slave"/>
- <process host="Soucy" function="Slave"/>
- <process host="Kuenning" function="Slave"/>
- <process host="Browne" function="Slave"/>
- <process host="Stephen" function="Slave"/>
- <process host="Robert" function="Slave"/>
- <process host="Sirois" function="Slave"/>
- <process host="Monique" function="Slave"/>
+ <argument value="1"/> <!-- Input mailbox -->
+ <argument value="9"/> <!-- First output mailbox -->
+ <argument value="10"/> <!-- Last output mailbox -->
+ </process>
+
+ <process host="iRMX" function="Slave">
+ <argument value="2"/> <!-- Input mailbox -->
+ </process>
+ <process host="Bousquet" function="Slave">
+ <argument value="3"/> <!-- Input mailbox -->
+ </process>
+ <process host="Soucy" function="Slave">
+ <argument value="4"/> <!-- Input mailbox -->
+ </process>
+ <process host="Kuenning" function="Slave">
+ <argument value="5"/> <!-- Input mailbox -->
+ </process>
+ <process host="Browne" function="Slave">
+ <argument value="6"/> <!-- Input mailbox -->
+ </process>
+ <process host="Stephen" function="Slave">
+ <argument value="7"/> <!-- Input mailbox -->
+ </process>
+ <process host="Robert" function="Slave">
+ <argument value="8"/> <!-- Input mailbox -->
+ </process>
+ <process host="Sirois" function="Slave">
+ <argument value="9"/> <!-- Input mailbox -->
+ </process>
+ <process host="Monique" function="Slave">
+ <argument value="10"/> <!-- Input mailbox -->
+ </process>
</platform>