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 {
27 int slavesCount = Cloud.hostNB;
29 ArrayList<VM> vms = new ArrayList<VM>();
31 // Create one VM per host and bind a process inside each one.
32 for (int i = 0; i < slavesCount; i++) {
33 Msg.info("create VM0"+i);
34 VM vm = new VM(hosts[i+1],"VM0"+i);
37 Slave slave = new Slave(vm,i);
38 Msg.info("Put Worker "+slave.msgName()+ " on "+vm.getName());
42 Msg.info("Launched " + vms.size() + " VMs");
44 Msg.info("Send a first batch of work to everyone");
45 workBatch(slavesCount);
47 Msg.info("Suspend all VMs");
48 for (int i = 0; i < vms.size(); i++) {
49 Msg.info("Suspend "+vms.get(i).getName());
53 Msg.info("Wait a while");
56 Msg.info("Resume all VMs.");
57 for (int i = 0; i < vms.size(); i++) {
61 Msg.info("Sleep long enough for everyone to be done with previous batch of work");
62 waitFor(1000 - Msg.getClock());
64 Msg.info("Add one more process per VM.");
65 for (int i = 0; i < vms.size(); i++) {
67 Slave slave = new Slave(vm,i + vms.size());
71 workBatch(slavesCount * 2);
73 Msg.info("Migrate everyone to "+hosts[2].getName());
74 for (int i = 0; i < vms.size(); i++) {
75 vms.get(i).migrate(hosts[2]);
78 // Msg.info("Suspend everyone, move them to the third host, and resume them.");
79 Msg.info("Migrate everyone to the third host (please note that cold migration is not yet available");
82 for (int i = 0; i < vms.size(); i++) {
91 Msg.info("Let's shut down the simulation and kill everyone.");
93 for (int i = 0; i < vms.size(); i++) {
94 vms.get(i).shutdown();
97 Msg.info("Master done.");
100 public void workBatch(int slavesCount) throws MsgException {
101 for (int i = 0; i < slavesCount; i++) {
102 Task task = new Task("Task0" + i, Cloud.task_comp_size, Cloud.task_comm_size);
103 Msg.info("Sending to WRK0" + i);
104 task.send("MBOX:WRK0" + i);