Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add an example for the cloud API (doesn't work yet).
authorSamuel Lepetit <samuel.lepetit@inria.fr>
Thu, 14 Jun 2012 13:49:43 +0000 (15:49 +0200)
committerSamuel Lepetit <samuel.lepetit@inria.fr>
Thu, 14 Jun 2012 13:50:28 +0000 (15:50 +0200)
Removed an useless MSG_process_set_data

CMakeLists.txt
examples/cloud/Cloud.java [new file with mode: 0644]
examples/cloud/FinalizeTask.java [new file with mode: 0644]
examples/cloud/Master.java [new file with mode: 0644]
examples/cloud/Slave.java [new file with mode: 0644]
org/simgrid/msg/VM.java
src/jmsg_process.c
src/jmsg_vm.c

index 9b442b3..9806f48 100644 (file)
@@ -157,6 +157,10 @@ set(JAVA_EXAMPLES
   ${CMAKE_HOME_DIRECTORY}/examples/chord/FindSuccessorTask.java
   ${CMAKE_HOME_DIRECTORY}/examples/chord/GetPredecessorAnswerTask.java
   ${CMAKE_HOME_DIRECTORY}/examples/chord/NotifyTask.java
+  ${CMAKE_HOME_DIRECTORY}/examples/cloud/Cloud.java
+  ${CMAKE_HOME_DIRECTORY}/examples/cloud/FinalizeTask.java
+  ${CMAKE_HOME_DIRECTORY}/examples/cloud/Master.java
+  ${CMAKE_HOME_DIRECTORY}/examples/cloud/Slave.java
   ${CMAKE_HOME_DIRECTORY}/examples/commTime/FinalizeTask.java
   ${CMAKE_HOME_DIRECTORY}/examples/commTime/Master.java
   ${CMAKE_HOME_DIRECTORY}/examples/commTime/Slave.java
@@ -391,6 +395,7 @@ add_custom_command(
   COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/async/*.java
   COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/bittorrent/*.java
   COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/chord/*.java
+  COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/cloud/*.java
   COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/commTime/*.java
   COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/io/*.java
   COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/masterslave/*.java
diff --git a/examples/cloud/Cloud.java b/examples/cloud/Cloud.java
new file mode 100644 (file)
index 0000000..69dd79b
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2012. The SimGrid Team. All rights reserved. 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. 
+ */
+package cloud;
+
+import org.simgrid.msg.Host;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.MsgException;
+
+/**
+ * Example showing the use of the new experimental Cloud API.
+ */
+public class Cloud {
+       public static final double task_comp_size = 10000000;
+       public static final double task_comm_size = 10000000;
+
+       public static void main(String[] args) throws MsgException {       
+           Msg.init(args); 
+           
+           if (args.length < 1) {
+               Msg.info("Usage  : Cloud platform_file");
+               Msg.info("Usage  : Cloud platform.xml");
+               System.exit(1);
+           }
+           /* Construct the platform */
+               Msg.createEnvironment(args[0]);
+                 /* Retrieve the 10 first hosts of the platform file */
+               Host[] hosts = Host.all();
+               if (hosts.length < 10) {
+                       Msg.info("I need at least 10 hosts in the platform file, but " + args[0] + " contains only " + hosts.length + " hosts");
+                       System.exit(42);
+               }
+               new Master(hosts[0],"Master",hosts).start();
+               /* Execute the simulation */
+               Msg.run();
+               
+               Msg.clean();
+    }
+}
\ No newline at end of file
diff --git a/examples/cloud/FinalizeTask.java b/examples/cloud/FinalizeTask.java
new file mode 100644 (file)
index 0000000..c7b5c54
--- /dev/null
@@ -0,0 +1,15 @@
+/*
+ * Copyright 2012. The SimGrid Team. All rights reserved. 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. 
+ */
+package cloud;
+
+import org.simgrid.msg.Task;
+
+public class FinalizeTask extends Task {
+       public FinalizeTask(double compSize, double commSize) {
+               super("Finalize",compSize,commSize);
+       }
+}
\ No newline at end of file
diff --git a/examples/cloud/Master.java b/examples/cloud/Master.java
new file mode 100644 (file)
index 0000000..791a956
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2012. The SimGrid Team. All rights reserved. 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. 
+ */
+package cloud;
+
+import java.util.ArrayList;
+
+import org.simgrid.msg.Host;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.MsgException;
+import org.simgrid.msg.Process;
+import org.simgrid.msg.Task;
+import org.simgrid.msg.VM;
+
+public class Master extends Process {
+       private Host[] hosts;
+       
+       public Master(Host host, String name, Host[] hosts) {
+               super(host,name,null);
+               this.hosts = hosts;
+       }
+       public void main(String[] args) throws MsgException {
+               int slavesCount = 10;
+               
+               ArrayList<VM> vms = new ArrayList<VM>();
+               
+               for (int i = 0; i < slavesCount; i++) {
+                       Slave slave = new Slave(hosts[i],i);
+                       slave.start();
+                       VM vm = new VM(hosts[i],1);
+                       vm.bind(slave);
+                       vms.add(vm);
+               }
+               Msg.info("Launched " + vms.size() + " VMs");
+               
+               Msg.info("Send a first batch of work to everyone");
+               workBatch(slavesCount);
+               
+               Msg.info("Now suspend all VMs, just for fun");
+               for (int i = 0; i < vms.size(); i++) {
+                       vms.get(i).suspend();
+               }
+               
+               Msg.info("Wait a while");
+               waitFor(2);
+               
+               Msg.info("Enough. Let's resume everybody.");
+               for (int i = 0; i < vms.size(); i++) {
+                       vms.get(i).resume();
+               }
+               
+               Msg.info("Sleep long enough for everyone to be done with previous batch of work");
+               waitFor(1000 - Msg.getClock());
+               
+               Msg.info("Add one more process per VM, and dispatch a batch of work to everyone");
+               for (int i = 0; i < vms.size(); i++) {
+                       VM vm = vms.get(i);
+                       Slave slave = new Slave(hosts[i],i + slavesCount);
+                       slave.start();
+                       vm.bind(slave);
+               }
+               
+               Msg.info("Migrate everyone to the second host.");
+               for (int i = 0; i < vms.size(); i++) {
+                       vms.get(i).migrate(hosts[1]);
+               }
+               
+               Msg.info("Suspend everyone, move them to the third host, and resume them.");
+               for (int i = 0; i < vms.size(); i++) {
+                       VM vm = vms.get(i);
+                       vm.suspend();
+                       vm.migrate(hosts[2]);
+               }
+               
+               workBatch(slavesCount * 2);
+               
+               Msg.info("Let's shut down the simulation. 10 first processes will be shut down cleanly while the second half will forcefully get killed");
+               
+               for (int i = 0; i < 10; i++) {
+                       FinalizeTask task = new FinalizeTask(0,0);
+                       task.send("slave_" + i);
+               }
+               
+               for (int i = 0; i < vms.size(); i++) {
+                       vms.get(i).shutdown();
+               }                               
+       }
+       
+       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);
+                       task.send("slave_" + i);
+               }
+       }
+}
\ No newline at end of file
diff --git a/examples/cloud/Slave.java b/examples/cloud/Slave.java
new file mode 100644 (file)
index 0000000..ca5ecaf
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2012. The SimGrid Team. All rights reserved. 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. 
+ */
+package cloud;
+
+import org.simgrid.msg.Host;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.MsgException;
+import org.simgrid.msg.Process;
+import org.simgrid.msg.Task;
+import org.simgrid.msg.TaskCancelledException;
+
+public class Slave extends Process {
+       private int number;
+       public Slave(Host host, int number) {
+               super(host,"Slave " + number,null);
+               this.number = number;
+       }
+       public void main(String[] args) throws MsgException {
+               while(true) {  
+                       Task task = Task.receive("slave_"+number);      
+
+                       if (task instanceof FinalizeTask) {
+                               break;
+                       }
+                       Msg.info("Received \"" + task.getName() +  "\". Processing it.");
+                       try {
+                               task.execute();
+                       } catch (TaskCancelledException e) {
+
+                       }
+               //      Msg.info("\"" + task.getName() + "\" done ");
+               }
+
+               Msg.info("Received Finalize. I'm done. See you!");
+               
+       }
+}
\ No newline at end of file
index 137fa17..c084163 100644 (file)
@@ -29,6 +29,7 @@ public class VM {
         */
        public VM(Host host, int coreAmount) {
                this.coreAmount = coreAmount;
+               start(host,coreAmount);
        }
        /**
         * Natively implemented method starting the VM.
@@ -76,5 +77,7 @@ public class VM {
         * of VM resume to you.
         */
        public native void resume();
+       
+       public native void shutdown();
                
 }
\ No newline at end of file
index dc3d262..9115d7e 100644 (file)
@@ -150,7 +150,6 @@ Java_org_simgrid_msg_Process_create(JNIEnv * env,
                                                /*argc, argv, properties*/
                                                0,NULL,NULL);
   MSG_process_set_kill_time(process, (double)jkill);
-  MSG_process_set_data(process,&process);
   /* bind the java process instance to the native process */
   jprocess_bind(jprocess, process, env);
 
index 38e4cca..1615e42 100644 (file)
@@ -35,6 +35,7 @@ Java_org_simgrid_msg_VM_start(JNIEnv *env, jobject jvm, jobject jhost, jint jcor
 
        jvm_bind(env,jvm,vm);
 }
+
 JNIEXPORT jboolean JNICALL
 Java_org_simgrid_msg_VM_isSuspended(JNIEnv *env, jobject jvm) {
        msg_vm_t vm = jvm_get_native(env,jvm);
@@ -52,6 +53,9 @@ Java_org_simgrid_msg_VM_bind(JNIEnv *env, jobject jvm, jobject jprocess) {
        msg_vm_t vm = jvm_get_native(env,jvm);
        m_process_t process = jprocess_to_native_process(jprocess,env);
 
+       xbt_assert((vm != NULL), "VM object is not binded");
+       xbt_assert((process != NULL), "Process object is not binded.");
+
        MSG_vm_bind(vm,process);
 }
 JNIEXPORT void JNICALL