Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a straightforward implementation of start_time and kill_time. This change the...
authorSamuel Lepetit <samuel.lepetit@inria.fr>
Wed, 16 May 2012 09:47:19 +0000 (11:47 +0200)
committerSamuel Lepetit <samuel.lepetit@inria.fr>
Wed, 16 May 2012 09:47:19 +0000 (11:47 +0200)
19 files changed:
examples/async/Forwarder.java
examples/async/Master.java
examples/async/Slave.java
examples/basic/Forwarder.java
examples/basic/Master.java
examples/basic/Slave.java
examples/basic/deploy.xml
examples/commTime/Master.java
examples/commTime/Slave.java
examples/mutualExclusion/centralized/Coordinator.java
examples/mutualExclusion/centralized/Node.java
examples/pingPong/Receiver.java
examples/pingPong/Sender.java
org/simgrid/msg/ApplicationHandler.java
org/simgrid/msg/Process.java
src/jmsg_application_handler.c
src/jmsg_process.c
src/jmsg_process.h
src/smx_context_java.c

index 29e9d18..35fb2e4 100644 (file)
@@ -14,8 +14,8 @@ import org.simgrid.msg.Process;
 
 
 public class Forwarder extends Process {
-       public Forwarder(Host host, String name, String[]args) {
-               super(host,name,args);
+       public Forwarder(Host host, String name, String[]args, double startTime, double killTime) {
+               super(host,name,args,startTime,killTime);
        }
        public void main(String[] args) throws MsgException {
                if (args.length < 3) {   
index 19e840c..971cd5f 100644 (file)
@@ -19,8 +19,8 @@ import org.simgrid.msg.Task;
 import org.simgrid.msg.Process;;
 
 public class Master extends Process {
-       public Master(Host host, String name, String[]args) {
-               super(host,name,args);
+       public Master(Host host, String name, String[]args, double startTime, double killTime) {
+               super(host,name,args,startTime,killTime);
        }
        public void main(String[] args) throws MsgException {
                if (args.length < 4) {
index d58910f..f271dc6 100644 (file)
@@ -17,8 +17,8 @@ import org.simgrid.msg.TransferFailureException;
 import org.simgrid.msg.Process;
 
 public class Slave extends Process {
-       public Slave(Host host, String name, String[]args) {
-               super(host,name,args);
+       public Slave(Host host, String name, String[]args, double startTime, double killTime) {
+               super(host,name,args,startTime,killTime);
        }
        public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
                if (args.length < 1) {
index 0a5d051..6152da1 100644 (file)
@@ -15,9 +15,9 @@ import org.simgrid.msg.Process;
 
 
 public class Forwarder extends Process {
-       public Forwarder(Host host, String name, String[]args) {
-               super(host,name,args);
-       }    
+       public Forwarder(Host host, String name, String[]args, double startTime, double killTime) {
+               super(host,name,args,startTime,killTime);
+       } 
    public void main(String[] args) throws MsgException {
       if (args.length < 3) {    
         Msg.info("Forwarder needs 3 arguments (input mailbox, first output mailbox, last one)");
index efd3a8e..5df6154 100644 (file)
@@ -15,9 +15,9 @@ import org.simgrid.msg.Task;
 import org.simgrid.msg.Process;;
 
 public class Master extends Process {
-       public Master(Host host, String name, String[]args) {
-               super(host,name,args);
-       }
+       public Master(Host host, String name, String[]args, double startTime, double killTime) {
+               super(host,name,args,startTime,killTime);
+       } 
        public void main(String[] args) throws MsgException {
                if (args.length < 4) {
                        Msg.info("Master needs 4 arguments");
index dc216a4..6f43f34 100644 (file)
@@ -16,8 +16,8 @@ import org.simgrid.msg.TransferFailureException;
 import org.simgrid.msg.Process;
 
 public class Slave extends Process {
-       public Slave(Host host, String name, String[]args) {
-               super(host,name,args);
+       public Slave(Host host, String name, String[]args, double startTime, double killTime) {
+               super(host,name,args,startTime,killTime);
        }
        public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
                if (args.length < 1) {
index eae9acf..f1351dc 100644 (file)
@@ -11,7 +11,7 @@
   </process>
   <!-- The slave process (with no argument) -->
   <process host="Jacquelin" function="basic.Slave"><argument value="0"/></process>
-  <process host="Boivin" function="basic.Slave"><argument value="1"/></process>
+  <process host="Boivin" function="basic.Slave" start_time="5"><argument value="1"/></process>
 <!--  <process host="Jean_Yves" function="Slave"><argument value="2"/></process>
   <process host="TeX" function="Slave"><argument value="3"/></process>
   <process host="Geoff" function="Slave"><argument value="4"/></process>
index 2080469..cd68e14 100644 (file)
@@ -17,8 +17,8 @@ import org.simgrid.msg.Task;
 import org.simgrid.msg.Process;
 
 public class Master extends Process {
-       public Master(Host host, String name, String[]args) {
-               super(host,name,args);
+       public Master(Host host, String name, String[]args, double startTime, double killTime) {
+               super(host,name,args, startTime, killTime);
        }
        public void main(String[] args) throws MsgException {
       if (args.length < 4) {
index f68848c..52c10a0 100644 (file)
@@ -10,8 +10,8 @@ package commTime;
 import org.simgrid.msg.*;
 
 public class Slave extends org.simgrid.msg.Process {
-       public Slave(Host host, String name, String[]args) {
-               super(host,name,args);
+       public Slave(Host host, String name, String[]args, double startTime, double killTime) {
+               super(host,name,args, startTime, killTime);
        }
        public void main(String[] args) throws MsgException {
       if (args.length < 1) {
index ef3da1e..dc4935a 100644 (file)
@@ -18,8 +18,8 @@ import org.simgrid.msg.Process;
 
 
 public class Coordinator extends Process  {
-       public Coordinator(Host host, String name, String[]args) {
-               super(host,name,args);
+       public Coordinator(Host host, String name, String[]args, double startTime, double killTime) {
+               super(host,name,args, startTime, killTime);
        }
        LinkedList<RequestTask> waitingQueue=new LinkedList<RequestTask>();
        int CsToServe;
index af0249b..d261b79 100644 (file)
@@ -15,8 +15,8 @@ import org.simgrid.msg.Task;
 import org.simgrid.msg.Process;
 
 public class Node extends Process {
-       public Node(Host host, String name, String[]args) {
-               super(host,name,args);
+       public Node(Host host, String name, String[]args, double startTime, double killTime) {
+               super(host,name,args,startTime,killTime);
        }
        public void request(double CStime) throws MsgException {
                RequestTask req = new RequestTask(this.name);
index 4d44ea3..a0cb0ff 100644 (file)
@@ -15,8 +15,8 @@ import org.simgrid.msg.Task;
 import org.simgrid.msg.Process;
 
 public class Receiver extends Process {
-       public Receiver(Host host, String name, String[]args) {
-               super(host,name,args);
+       public Receiver(Host host, String name, String[]args, double startTime, double killTime) {
+               super(host,name,args,startTime,killTime);
        }
    final double commSizeLat = 1;
    final double commSizeBw = 100000000;
index ff8efdc..7e00cc0 100644 (file)
@@ -14,8 +14,8 @@ import org.simgrid.msg.MsgException;
 import org.simgrid.msg.Process;
 
 public class Sender extends Process {
-       public Sender(Host host, String name, String[]args) {
-               super(host,name,args);
+       public Sender(Host host, String name, String[]args, double startTime, double killTime) {
+               super(host,name,args,startTime,killTime);
        }
     private final double commSizeLat = 1;
     final double commSizeBw = 100000000;
index 3edcc92..b485d77 100644 (file)
@@ -38,7 +38,14 @@ public final class ApplicationHandler {
                 * The function of the process.
                 */
                private  static String function;
-               
+               /**
+                * Start time of the process
+                */
+               private static double startTime;
+               /**
+                * Kill time of the process
+                */
+               private static double killTime;
                /**
                 * This method is called by the start element handler.
                 * It sets the host and the function of the process to create,
@@ -51,9 +58,11 @@ public final class ApplicationHandler {
                 * @function                    The function of the process to create.
                 *
                 */
-               public  static void setProcessIdentity(String hostName_, String function_) {
-                       hostName = hostName_;    
-                       function = function_;
+               public  static void setProcessIdentity(String hostName, String function, String startTime, String killTime) {
+                       ApplicationHandler.hostName = hostName;    
+                       ApplicationHandler.function = function;
+                       ApplicationHandler.startTime = Double.valueOf(startTime);
+                       ApplicationHandler.killTime = Double.valueOf(killTime);
 
                        if (!args.isEmpty())
                                args.clear();
@@ -99,14 +108,14 @@ public final class ApplicationHandler {
                 public  static void createProcess() {
                         try {
                                 Class<Process> cls = (Class<Process>) Class.forName(function);
-                                Constructor<Process> constructor = cls.getConstructor(new Class [] {Host.class, java.lang.String.class, java.lang.String[].class});
+                                Constructor<Process> constructor = cls.getConstructor(new Class [] {Host.class, java.lang.String.class, java.lang.String[].class, double.class, double.class});
                                 String[] args_ = args.toArray(new String[args.size()]);
-                                Process process = constructor.newInstance(Host.getByName(hostName), function, args_);
+                                Process process = constructor.newInstance(Host.getByName(hostName), function, args_, startTime, killTime);
                                 process.start();
                         } 
                         catch (NoSuchMethodException e) {
                                 throw new RuntimeException("Can't find the correct constructor for the class " + function + ". \n" +
-                                "Is there a constructor with the signature: \"Host host, String name, String[]args\" in the class ?");
+                                "Is there a constructor with the signature: \"Host host, String name, String[]args, double startTime, double killTime\" in the class ?");
                         }
                         catch (InvocationTargetException e) {
                                 e.printStackTrace();
@@ -139,6 +148,8 @@ public final class ApplicationHandler {
                        properties = new Hashtable<String,String>();
                        hostName = null;
                        function = null;
+                       startTime = 0;
+                       killTime = -1;
        }
 
          /**
@@ -146,8 +157,8 @@ public final class ApplicationHandler {
           * @param hostName
           * @param function
           */
-         public  static void onBeginProcess(String hostName, String function) {
-               setProcessIdentity(hostName, function);
+         public  static void onBeginProcess(String hostName, String function, String startTime, String killTime) {
+               setProcessIdentity(hostName, function, startTime, killTime);
                
        }
     /**
@@ -156,7 +167,7 @@ public final class ApplicationHandler {
      * @param value
      */
     public  static void onProperty(String id, String value) {
-               setProperty(id, value);
+       setProperty(id, value);
        }
 
     /**
@@ -164,7 +175,7 @@ public final class ApplicationHandler {
      * @param arg
      */
     public  static void onProcessArg(String arg) {
-               registerProcessArg(arg);
+       registerProcessArg(arg);
        }
 
     /**
index 380335a..ea1f275 100644 (file)
@@ -55,19 +55,31 @@ public abstract class Process implements Runnable {
         * access to it. It is set automatically during the build of the object.
         */
        public long bind;
-
+       /**
+        * Indicates if the process is started
+        */
+       boolean started;
        /**
         * Even if this attribute is public you must never access to it.
         * It is used to compute the id of an MSG process.
         */
        public static long nextProcessId = 0;
-
+       
        /**
         * Even if this attribute is public you must never access to it.
         * It is compute automatically during the creation of the object. 
         * The native functions use this identifier to synchronize the process.
         */
        public long id;
+       
+       /**
+        * Start time of the process
+        */
+       public double startTime;
+       /**
+        * Kill time of the process
+        */
+       public double killTime;
 
     public Hashtable<String,String> properties;
 
@@ -90,6 +102,7 @@ public abstract class Process implements Runnable {
 
        /** The arguments of the method function of the process. */     
        public Vector<String> args;
+
        
        /**
         * Default constructor (used in ApplicationHandler to initialize it)
@@ -115,7 +128,7 @@ public abstract class Process implements Runnable {
         *
         */
        public Process(String hostname, String name) throws HostNotFoundException {
-               this(Host.getByName(hostname), name, null);
+               this(Host.getByName(hostname), name, null, 0, -1);
        }
        /**
         * Constructs a new process from the name of a host and his name. The arguments
@@ -131,7 +144,7 @@ public abstract class Process implements Runnable {
         *
         */ 
        public Process(String hostname, String name, String args[]) throws HostNotFoundException, NativeException {
-               this(Host.getByName(hostname), name, args);
+               this(Host.getByName(hostname), name, args, 0, -1);
        }
        /**
         * Constructs a new process from a host and his name. The method function of the 
@@ -142,7 +155,7 @@ public abstract class Process implements Runnable {
         *
         */
        public Process(Host host, String name) {
-               this(host, name, null);
+               this(host, name, null, 0, -1);
        }
        /**
         * Constructs a new process from a host and his name, the arguments of here method function are
@@ -151,9 +164,11 @@ public abstract class Process implements Runnable {
         * @param host                  The host of the process to create.
         * @param name                  The name of the process.
         * @param args                  The arguments of main method of the process.
+        * @param startTime             Start time of the process
+        * @param killTime              Kill time of the process
         *
         */
-       public Process(Host host, String name, String[]args) {
+       public Process(Host host, String name, String[]args, double startTime, double killTime) {
                /* This is the constructor called by all others */
                this();
                this.host = host;
@@ -167,12 +182,14 @@ public abstract class Process implements Runnable {
                
                this.properties = new Hashtable<String,String>();
                
+               this.startTime = startTime;
+               this.killTime = killTime;               
        }
        /**
         * The natively implemented method to create an MSG process.
         * @param host    A valid (binded) host where create the process.
         */
-       protected native void create(String hostName) throws HostNotFoundException;
+       protected native void create(String hostName, double startTime, double killTime) throws HostNotFoundException;
        /**
         * This method kills all running process of the simulation.
         *
@@ -302,10 +319,14 @@ public abstract class Process implements Runnable {
        }
     /**
      * This method actually creates and run the process.
+     * It is a noop if the process is already launched.
      * @throws HostNotFoundException
      */
-    public void start() throws HostNotFoundException {
-       create(host.getName());
+    public final void start() throws HostNotFoundException {
+       if (!started) {
+               started = true;
+               create(host.getName(), startTime, killTime);
+       }
     }
     
        /**
@@ -329,7 +350,7 @@ public abstract class Process implements Runnable {
                        System.exit(1);
                }
                 catch(ProcessKilledError pk) {
-
+                        
                 }      
        }
 
index 885c50d..ac40766 100644 (file)
@@ -46,19 +46,25 @@ void japplication_handler_on_begin_process(void)
 {
   jstring jhostName;
   jstring jfunction;
+  jstring jstartTime, jkillTime;
   jclass cls;
   JNIEnv *env = get_current_thread_env();
   jmethodID id =
       jxbt_get_static_smethod(env, "org/simgrid/msg/ApplicationHandler",
                               "onBeginProcess",
-                              "(Ljava/lang/String;Ljava/lang/String;)V");
+                              "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
   if (!id
       || !(cls = jxbt_get_class(env, "org/simgrid/msg/ApplicationHandler")))
     return;
   jhostName = (jstring) (*env)->NewStringUTF(env, A_surfxml_process_host);
   jfunction =
       (jstring) (*env)->NewStringUTF(env, A_surfxml_process_function);
-  (*env)->CallStaticVoidMethod(env, cls, id, jhostName, jfunction);
+
+  jstartTime = (jstring) (*env)->NewStringUTF(env, A_surfxml_process_start_time);
+  jkillTime = (jstring) (*env)->NewStringUTF(env, A_surfxml_process_kill_time);
+
+
+  (*env)->CallStaticVoidMethod(env, cls, id, jhostName, jfunction, jstartTime, jkillTime);
 }
 
 void japplication_handler_on_process_arg(void)
index b7d7a3b..83dcfbd 100644 (file)
@@ -93,7 +93,7 @@ Java_org_simgrid_msg_Process_nativeInit(JNIEnv *env, jclass cls) {
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_Process_create(JNIEnv * env,
                                     jobject jprocess_arg,
-                                    jobject jhostname)
+                                    jobject jhostname, jdouble jstartTime, jdouble jkillTime)
 {
 
 
@@ -142,7 +142,7 @@ Java_org_simgrid_msg_Process_create(JNIEnv * env,
                                                (xbt_main_func_t) jprocess,
                                                /*data*/ NULL,
                                                host,
-                                               /* kill_time */-1,
+                                               (double)jkillTime, /* kill time */
                                                /*argc, argv, properties*/
                                                0,NULL,NULL);
 
index ff30980..f917960 100644 (file)
@@ -141,7 +141,8 @@ Java_org_simgrid_msg_Process_nativeInit(JNIEnv *env, jclass cls);
  */
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_Process_create(JNIEnv * env,
-                                         jobject jprocess, jobject jhost);
+                                    jobject jprocess_arg,
+                                    jobject jhostname, jdouble jstartTime, jdouble jkillTime);
 
 /*
  * Class               org_simgrid_msg_Process
index 04dd49b..fd385bb 100644 (file)
@@ -97,6 +97,13 @@ static void* smx_ctx_java_thread_run(void *data) {
   context->jenv = get_current_thread_env();
   //Wait for the first scheduling round to happen.
   xbt_os_sem_acquire(context->begin);
+  //wait for the process to be able to begin
+  //TODO: Cache it
+       jfieldID jprocess_field_Process_startTime = jxbt_get_sfield(env, "org/simgrid/msg/Process", "startTime", "D");
+  jdouble startTime =  (*env)->GetDoubleField(env, context->jprocess, jprocess_field_Process_startTime);
+  if (startTime > MSG_get_clock()) {
+       MSG_process_sleep(startTime - MSG_get_clock());
+  }
   //Execution of the "run" method.
   jmethodID id = jxbt_get_smethod(env, "org/simgrid/msg/Process", "run", "()V");
   xbt_assert( (id != NULL), "Method not found...");