2 * Copyright 2012. The SimGrid Team. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package.
9 import java.util.ArrayList;
11 import org.simgrid.msg.Host;
12 import org.simgrid.msg.Msg;
13 import org.simgrid.msg.MsgException;
14 import org.simgrid.msg.Process;
15 import org.simgrid.msg.Task;
16 import org.simgrid.msg.VM;
18 public class Master extends Process {
21 public Master(Host host, String name, Host[] hosts) {
22 super(host,name,null);
25 public void main(String[] args) throws MsgException {
28 ArrayList<VM> vms = new ArrayList<VM>();
30 for (int i = 0; i < slavesCount; i++) {
31 Slave slave = new Slave(hosts[i],i);
33 VM vm = new VM(hosts[i],hosts[i]+"_"+i,1);
37 Msg.info("Launched " + vms.size() + " VMs");
39 Msg.info("Send a first batch of work to everyone");
40 workBatch(slavesCount);
42 Msg.info("Now suspend all VMs, just for fun");
43 for (int i = 0; i < vms.size(); i++) {
47 Msg.info("Wait a while");
50 Msg.info("Enough. Let's resume everybody.");
51 for (int i = 0; i < vms.size(); i++) {
55 Msg.info("Sleep long enough for everyone to be done with previous batch of work");
56 waitFor(1000 - Msg.getClock());
58 Msg.info("Add one more process per VM.");
59 for (int i = 0; i < vms.size(); i++) {
61 Slave slave = new Slave(hosts[i],i + vms.size());
66 Msg.info("Migrate everyone to the second host.");
67 for (int i = 0; i < vms.size(); i++) {
68 vms.get(i).migrate(hosts[1]);
71 Msg.info("Suspend everyone, move them to the third host, and resume them.");
72 for (int i = 0; i < vms.size(); i++) {
79 workBatch(slavesCount * 2);
81 Msg.info("Let's shut down the simulation and kill everyone.");
83 for (int i = 0; i < vms.size(); i++) {
84 vms.get(i).shutdown();
86 Msg.info("Master done.");
89 public void workBatch(int slavesCount) throws MsgException {
90 for (int i = 0; i < slavesCount; i++) {
91 Task task = new Task("Task_" + i, Cloud.task_comp_size, Cloud.task_comm_size);
92 Msg.info("Sending to " + i);
93 task.send("slave_" + i);