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 // Create one VM per host and bind a process inside each one.
31 for (int i = 0; i < slavesCount; i++) {
32 VM vm = new VM(hosts[i],"VM_"+i);
35 Slave slave = new Slave(vm,i);
39 Msg.info("Launched " + vms.size() + " VMs");
41 Msg.info("Send a first batch of work to everyone");
42 workBatch(slavesCount);
44 Msg.info("Now suspend all VMs, just for fun");
45 for (int i = 0; i < vms.size(); i++) {
49 Msg.info("Wait a while");
52 Msg.info("Enough. Let's resume everybody.");
53 for (int i = 0; i < vms.size(); i++) {
57 Msg.info("Sleep long enough for everyone to be done with previous batch of work");
58 waitFor(1000 - Msg.getClock());
60 Msg.info("Add one more process per VM.");
61 for (int i = 0; i < vms.size(); i++) {
63 Slave slave = new Slave(vm,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 Msg.info("Migrate everyone to the third host (please note that cold migration is not yet available");
76 for (int i = 0; i < vms.size(); i++) {
83 workBatch(slavesCount * 2);
85 Msg.info("Let's shut down the simulation and kill everyone.");
87 for (int i = 0; i < vms.size(); i++) {
88 vms.get(i).shutdown();
90 Msg.info("Master done.");
93 public void workBatch(int slavesCount) throws MsgException {
94 for (int i = 0; i < slavesCount; i++) {
95 Task task = new Task("Task_" + i, Cloud.task_comp_size, Cloud.task_comm_size);
96 Msg.info("Sending to " + i);
97 task.send("slave_" + i);