Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines with new year.
[simgrid.git] / examples / deprecated / java / app / masterworker / Master.java
1 /* Master of a basic master/worker example in Java */
2
3 /* Copyright (c) 2006-2020. The SimGrid Team.
4  * 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 app.masterworker;
10 import org.simgrid.msg.Host;
11 import org.simgrid.msg.Msg;
12 import org.simgrid.msg.MsgException;
13 import org.simgrid.msg.Task;
14 import org.simgrid.msg.Process;
15
16 public class Master extends Process {
17   public Master(Host host, String name, String[]args) {
18     super(host,name,args);
19   } 
20   public void main(String[] args) throws MsgException {
21     if (args.length < 4) {
22       Msg.info("Master needs 4 arguments");
23       System.exit(1);
24     }
25
26     int tasksCount = Integer.parseInt(args[0]);
27     double taskComputeSize = Double.parseDouble(args[1]);
28     double taskCommunicateSize = Double.parseDouble(args[2]);
29
30     int workersCount = Integer.parseInt(args[3]);
31
32     Msg.info("Hello! My PID is "+getPID()+". Got "+  workersCount + " workers and "+tasksCount+" tasks to process");
33
34     for (int i = 0; i < tasksCount; i++) {
35       Task task = new Task("Task_" + i, taskComputeSize, taskCommunicateSize); 
36       Msg.debug("Sending \"" + task.getName()+ "\" to \"worker_" + i % workersCount + "\"");
37       task.send("worker_"+(i%workersCount));
38     }
39
40     Msg.info("All tasks have been dispatched. Let's tell everybody the computation is over.");
41
42     for (int i = 0; i < workersCount; i++) {
43       Task task = new Task("finalize", 0, 0);
44       task.send("worker_"+(i%workersCount));
45     }
46
47     Msg.info("Goodbye now!");
48   }
49 }