1 /* Copyright (c) 2012-2014. The SimGrid Team.
2 * 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.Msg;
12 import org.simgrid.msg.VM;
13 import org.simgrid.msg.Host;
14 import org.simgrid.msg.Task;
15 import org.simgrid.msg.Process;
16 import org.simgrid.msg.MsgException;
18 public class Master extends Process {
21 public Master(Host host, String name, Host[] hosts) {
22 super(host,name,null);
26 public void main(String[] args) throws MsgException {
27 int slavesCount = Cloud.hostNB;
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 Msg.info("create VM0"+i);
33 VM vm = new VM(hosts[i+1],"VM0"+i);
36 Slave slave = new Slave(vm,i);
37 Msg.info("Put Worker "+slave.getName()+ " on "+vm.getName());
41 Msg.info("Launched " + vms.size() + " VMs");
43 Msg.info("Send a first batch of work to everyone");
44 workBatch(slavesCount);
46 Msg.info("Suspend all VMs");
47 for (int i = 0; i < vms.size(); i++) {
48 Msg.info("Suspend "+vms.get(i).getName());
52 Msg.info("Wait a while");
55 Msg.info("Resume all VMs.");
56 for (int i = 0; i < vms.size(); i++) {
60 Msg.info("Sleep long enough for everyone to be done with previous batch of work");
61 waitFor(1000 - Msg.getClock());
63 /* Msg.info("Add one more process per VM.");
64 for (int i = 0; i < vms.size(); i++) {
66 Slave slave = new Slave(vm,i + vms.size());
70 workBatch(slavesCount * 2);
73 Msg.info("Migrate everyone to "+hosts[3].getName());
74 for (int i = 0; i < vms.size(); i++) {
75 Msg.info("Migrate "+vms.get(i).getName()+"from"+hosts[i+1].getName()+"to "+hosts[3].getName());
76 vms.get(i).migrate(hosts[3]);
79 Msg.info("Let's shut down the simulation and kill everyone.");
81 for (int i = 0; i < vms.size(); i++) {
82 vms.get(i).shutdown();
84 Msg.info("Master done.");
87 public void workBatch(int slavesCount) throws MsgException {
88 for (int i = 0; i < slavesCount; i++) {
89 Task task = new Task("Task0" + i, Cloud.task_comp_size, Cloud.task_comm_size);
90 Msg.info("Sending to WRK0" + i);
91 task.send("MBOX:WRK0" + i);