2 * Copyright (c) 2012-2013. The SimGrid Team.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package.
10 import java.util.ArrayList;
12 import org.simgrid.msg.Host;
13 import org.simgrid.msg.Msg;
14 import org.simgrid.msg.MsgException;
15 import org.simgrid.msg.Process;
16 import org.simgrid.msg.Task;
17 import org.simgrid.msg.VM;
19 public class Master extends Process {
22 public Master(Host host, String name, Host[] hosts) {
23 super(host,name,null);
26 public void main(String[] args) throws MsgException {
29 ArrayList<VM> vms = new ArrayList<VM>();
31 for (int i = 0; i < slavesCount; i++) {
32 Slave slave = new Slave(hosts[i],i);
34 VM vm = new VM(hosts[i],hosts[i]+"_"+i,1);
38 Msg.info("Launched " + vms.size() + " VMs");
40 Msg.info("Send a first batch of work to everyone");
41 workBatch(slavesCount);
43 Msg.info("Now suspend all VMs, just for fun");
44 for (int i = 0; i < vms.size(); i++) {
48 Msg.info("Wait a while");
51 Msg.info("Enough. Let's resume everybody.");
52 for (int i = 0; i < vms.size(); i++) {
56 Msg.info("Sleep long enough for everyone to be done with previous batch of work");
57 waitFor(1000 - Msg.getClock());
59 Msg.info("Add one more process per VM.");
60 for (int i = 0; i < vms.size(); i++) {
62 Slave slave = new Slave(hosts[i],i + vms.size());
67 Msg.info("Migrate everyone to the second host.");
68 for (int i = 0; i < vms.size(); i++) {
69 vms.get(i).migrate(hosts[1]);
72 Msg.info("Suspend everyone, move them to the third host, and resume them.");
73 for (int i = 0; i < vms.size(); i++) {
80 workBatch(slavesCount * 2);
82 Msg.info("Let's shut down the simulation and kill everyone.");
84 for (int i = 0; i < vms.size(); i++) {
85 vms.get(i).shutdown();
87 Msg.info("Master done.");
90 public void workBatch(int slavesCount) throws MsgException {
91 for (int i = 0; i < slavesCount; i++) {
92 Task task = new Task("Task_" + i, Cloud.task_comp_size, Cloud.task_comm_size);
93 Msg.info("Sending to " + i);
94 task.send("slave_" + i);