Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Committing automatically generated file (after the "sed" dependancy
[simgrid.git] / examples / java / comm_time / Master.java
1 /*
2  * $Id$
3  *
4  * Copyright 2006,2007 Martin Quinson, Malek Cherier         
5  * All rights reserved. 
6  *
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. 
9  */
10
11 import simgrid.msg.*;
12
13 public class Master extends simgrid.msg.Process {
14    
15    public void main(String[] args) throws JniException, NativeException {
16       
17       Msg.info("Hello i'm the master");
18       
19       int numberoftasks = Integer.valueOf(args[0]).intValue();
20       double taskComputeSize = Double.valueOf(args[1]).doubleValue();           
21       double taskCommunicateSize = Double.valueOf(args[2]).doubleValue();
22                 
23       int slavecount = args.length - 3;
24       Host[] slaves = new Host[slavecount] ;
25         
26       for (int i = 3; i < args.length; i++) {
27          try {
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! " );
32             System.exit(1);
33          }
34       }
35                 
36       Msg.info("Got " + slavecount + " slave(s):");             
37       for (int i = 0; i < slavecount; i++)
38         Msg.info("\t " + slaves[i].getName());
39       
40       Msg.info("Got "+numberoftasks+" task(s) to process.");
41       
42       Channel channel = new Channel(0);
43                 
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]);
48          
49 //       Msg.info("Send completed for the task " + task.getName() + " on the host " + slaves[i % slavecount].getName() +  " [" + (i % slavecount) + "]");
50       }
51                 
52       Msg.info("All tasks have been dispatched. Let's tell everybody the computation is over.");
53                 
54       for (int i = 0; i < slavecount; i++) { 
55                         
56          CommTimeTask task = new CommTimeTask("finalize_" + i,0,0);
57          task.setData(221297);
58                         
59          Msg.info("Send task to host : " + slaves[i].getName());
60          channel.put(task,slaves[i]);
61                         
62          Msg.info("Send completed " + slaves[i].getName() +  " [" + i + "]");
63       }
64       
65       Msg.info("All finalize messages have been dispatched. Goodbye now!");
66    }
67 }