Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
aba2c71d691ff860eb9f832f8a91c29b68b35441
[simgrid.git] / examples / scala / masterslave / Master.scala
1 /*
2  * Master of a basic master/slave example in Java
3  *
4  * Copyright 2006-2012 The SimGrid Team. All rights reserved. 
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. 
8  */
9 package masterslave;
10
11 import org.simgrid.msg.Host;
12 import org.simgrid.msg.Msg;
13 import org.simgrid.msg.MsgException;
14 import org.simgrid.msg.Task;
15 import org.simgrid.msg.Process;;
16
17 class Master(host:Host, name:String, args:Array[String]) extends Process(host,name,args) {
18   def main(args:Array[String]) {
19     if (args.length < 4) {
20       Msg.info("Master needs 4 arguments")
21       System.exit(1)
22     }
23
24     val tasksCount = args(0).toInt              
25     val taskComputeSize = args(1).toDouble              
26     val taskCommunicateSize = args(2).toDouble
27     val slavesCount = args(3).toInt
28
29     Msg.info("Hello! Got " +  slavesCount + " slaves and " + tasksCount + " tasks to process")
30
31     for (i <- 0 until tasksCount) {
32       val task = new Task("Task_" + i, taskComputeSize, taskCommunicateSize)
33       task.send("slave_"+(i%slavesCount))
34     }
35
36     Msg.info("All tasks have been dispatched. Let's tell everybody the computation is over.")
37
38     for (i <- 0 until slavesCount) {
39       val task = new FinalizeTask()
40       task.send("slave_"+(i%slavesCount))
41     }
42
43     Msg.info("Goodbye now!")
44   }
45 }