Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[SMPI] Update test output (smpi_replay.tesh)
[simgrid.git] / examples / scala / masterslave / Master.scala
1 /*
2  * Master of a basic master/slave example in Java
3  *
4  * Copyright (c) 2006-2013. The SimGrid Team.
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 package masterslave;
11
12 import org.simgrid.msg.Host;
13 import org.simgrid.msg.Msg;
14 import org.simgrid.msg.MsgException;
15 import org.simgrid.msg.Task;
16 import org.simgrid.msg.Process;;
17
18 class Master(host:Host, name:String, args:Array[String]) extends Process(host,name,args) {
19   def main(args:Array[String]) {
20     if (args.length < 4) {
21       Msg.info("Master needs 4 arguments")
22       System.exit(1)
23     }
24
25     val tasksCount = args(0).toInt              
26     val taskComputeSize = args(1).toDouble              
27     val taskCommunicateSize = args(2).toDouble
28     val slavesCount = args(3).toInt
29
30     Msg.info("Hello! Got " +  slavesCount + " slaves and " + tasksCount + " tasks to process")
31
32     for (i <- 0 until tasksCount) {
33       val task = new Task("Task_" + i, taskComputeSize, taskCommunicateSize)
34       task.send("slave_"+(i%slavesCount))
35     }
36
37     Msg.info("All tasks have been dispatched. Let's tell everybody the computation is over.")
38
39     for (i <- 0 until slavesCount) {
40       val task = new FinalizeTask()
41       task.send("slave_"+(i%slavesCount))
42     }
43
44     Msg.info("Goodbye now!")
45   }
46 }