Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Java bindings - Adrien
[simgrid.git] / examples / java / cloud / Master.java
index 72bf8db..a832cac 100644 (file)
@@ -23,16 +23,18 @@ public class Master extends Process {
                this.hosts = hosts;
        }
        public void main(String[] args) throws MsgException {
-               int slavesCount = 5;
+               int slavesCount = Cloud.hostNB;
                
                ArrayList<VM> vms = new ArrayList<VM>();
                
                // Create one VM per host and bind a process inside each one. 
                for (int i = 0; i < slavesCount; i++) {
-                       VM vm = new VM(hosts[i],"VM_"+i);
+                       Msg.info("create VM0"+i);       
+                       VM vm = new VM(hosts[i+1],"VM0"+i);
                        vm.start();
                        vms.add(vm);
                        Slave slave = new Slave(vm,i);
+                       Msg.info("Put Worker "+slave.msgName()+ " on "+vm.getName());
                        slave.start();
        
                }
@@ -41,15 +43,16 @@ public class Master extends Process {
                Msg.info("Send a first batch of work to everyone");
                workBatch(slavesCount);
                
-               Msg.info("Now suspend all VMs, just for fun");
+               Msg.info("Suspend all VMs");
                for (int i = 0; i < vms.size(); i++) {
+                       Msg.info("Suspend "+vms.get(i).getName());
                        vms.get(i).suspend();
                }
                
                Msg.info("Wait a while");
                waitFor(2);
                
-               Msg.info("Enough. Let's resume everybody.");
+               Msg.info("Resume all VMs.");
                for (int i = 0; i < vms.size(); i++) {
                        vms.get(i).resume();
                }
@@ -63,10 +66,12 @@ public class Master extends Process {
                        Slave slave = new Slave(vm,i + vms.size());
                        slave.start();
                }
+       
+               workBatch(slavesCount * 2);
                
-               Msg.info("Migrate everyone to the second host.");
+               Msg.info("Migrate everyone to "+hosts[2].getName());
                for (int i = 0; i < vms.size(); i++) {
-                       vms.get(i).migrate(hosts[1]);
+                       vms.get(i).migrate(hosts[2]);
                }
                
 //             Msg.info("Suspend everyone, move them to the third host, and resume them.");
@@ -76,25 +81,26 @@ public class Master extends Process {
                for (int i = 0; i < vms.size(); i++) {
                        VM vm = vms.get(i);
        //              vm.suspend();
-                       vm.migrate(hosts[2]);
+                       vm.migrate(hosts[3]);
                //      vm.resume();
                }
                
-               workBatch(slavesCount * 2);
+       
                
                Msg.info("Let's shut down the simulation and kill everyone.");
                
                for (int i = 0; i < vms.size(); i++) {
                        vms.get(i).shutdown();
+                       vms.get(i).destroy();
                }                               
                Msg.info("Master done.");
        }
        
        public void workBatch(int slavesCount) throws MsgException {
                for (int i = 0; i < slavesCount; i++) {
-                       Task task = new Task("Task_" + i, Cloud.task_comp_size, Cloud.task_comm_size);
-                       Msg.info("Sending to " + i);
-                       task.send("slave_" + i);
+                       Task task = new Task("Task0" + i, Cloud.task_comp_size, Cloud.task_comm_size);
+                       Msg.info("Sending to WRK0" + i);
+                       task.send("MBOX:WRK0" + i);
                }
        }
 }