Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make MSG_process_yield visible from java, and test it
authorMartin Quinson <martin.quinson@loria.fr>
Thu, 26 Jan 2017 22:29:42 +0000 (23:29 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Thu, 26 Jan 2017 22:29:42 +0000 (23:29 +0100)
.gitignore
examples/java/CMakeLists.txt
examples/java/async/yield/Main.java [new file with mode: 0644]
examples/java/async/yield/Yielder.java [new file with mode: 0644]
examples/java/async/yield/async_yield.tesh [new file with mode: 0644]
src/bindings/java/jmsg_process.cpp
src/bindings/java/jmsg_process.h
src/bindings/java/org/simgrid/msg/Process.java

index 9b56f91..24d8a14 100644 (file)
@@ -979,6 +979,7 @@ examples/java/app/centralizedmutex/java_app_centralizedmutex_compiled
 examples/java/app/masterworker/java_app_masterworker_compiled
 examples/java/app/pingpong/java_app_pingpong_compiled
 examples/java/app/tokenring/java_app_tokenring_compiled
+examples/java/async/yield/java_async_yield_compiled
 examples/java/async/dsend/java_async_dsend_compiled
 examples/java/async/waitall/java_async_waitall_compiled
 examples/java/dht/chord/java_dht_chord_compiled
index 4b73e94..7fa8d74 100644 (file)
@@ -20,6 +20,9 @@ set(app_tokenring_sources      ${srcdir}/Main.java ${srcdir}/RelayRunner.java)
 set (srcdir ${CMAKE_CURRENT_SOURCE_DIR}/async/waitall)
 set(async_waitall_sources      ${srcdir}/Main.java  ${srcdir}/Receiver.java ${srcdir}/Sender.java)
 
+set (srcdir ${CMAKE_CURRENT_SOURCE_DIR}/async/yield)
+set(async_yield_sources      ${srcdir}/Main.java  ${srcdir}/Yielder.java)
+
 set (srcdir ${CMAKE_CURRENT_SOURCE_DIR}/async/dsend)
 set(async_dsend_sources        ${srcdir}/Main.java  ${srcdir}/Receiver.java ${srcdir}/Sender.java)
 
@@ -76,7 +79,7 @@ set(process_suspend_sources    ${srcdir}/Main.java  ${srcdir}/DreamMaster.java
 set (srcdir ${CMAKE_CURRENT_SOURCE_DIR}/task/priority)
 set(task_priority_sources      ${srcdir}/Main.java  ${srcdir}/Test.java)
 
-foreach (example app_bittorrent app_centralizedmutex app_masterworker app_pingpong app_tokenring async_waitall async_dsend
+foreach (example app_bittorrent app_centralizedmutex app_masterworker app_pingpong app_tokenring async_yield async_waitall async_dsend
          cloud_migration cloud_masterworker dht_chord dht_kademlia energy_consumption energy_pstate energy_vm io_file io_storage 
          process_kill process_migration process_startkilltime process_suspend task_priority trace_pingpong)
   string (REPLACE "_" "/" example_dir ${example})
@@ -110,7 +113,7 @@ set(xml_files     ${xml_files}     ${CMAKE_CURRENT_SOURCE_DIR}/app/bittorrent/bi
                                    ${CMAKE_CURRENT_SOURCE_DIR}/task/priority/priority.xml                  PARENT_SCOPE)
 
 if(enable_java)
-  foreach (example app_bittorrent app_centralizedmutex app_masterworker app_pingpong app_tokenring async_waitall async_dsend
+  foreach (example app_bittorrent app_centralizedmutex app_masterworker app_pingpong app_tokenring async_yield async_waitall async_dsend
            cloud_migration cloud_masterworker dht_chord dht_kademlia energy_consumption energy_pstate energy_vm io_file io_storage 
            process_kill process_migration process_startkilltime process_suspend task_priority trace_pingpong)
     string (REPLACE "_" "/" example_dir ${example})
diff --git a/examples/java/async/yield/Main.java b/examples/java/async/yield/Main.java
new file mode 100644 (file)
index 0000000..d4c9bea
--- /dev/null
@@ -0,0 +1,42 @@
+/* Copyright (c) 2017. 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 async.yield;
+
+/** This example demonstrates the use of the Task.dsend() method.
+ * 
+ *  This way, the sender can be detached from the communication: it is not blocked as with Task.send() 
+ *  and has nothing to do at the end as with Task.isend() where it must do a Comm.wait().
+ */
+
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.Host;
+import org.simgrid.msg.NativeException;
+import org.simgrid.msg.HostNotFoundException;
+
+class Main {
+  private Main() {
+       /* This is just to ensure that nobody creates an instance of this singleton */
+    throw new IllegalAccessError("Utility class");
+  }
+
+  public static void main(String[] args) throws NativeException, HostNotFoundException {
+    Msg.init(args);
+
+    String platform = "../platforms/small_platform.xml";
+    if (args.length >= 1) {
+       platform = args[0]; // Override the default value if passed on the command line
+    }
+
+    /* construct the platform and deploy the application */
+    Msg.createEnvironment(platform);
+    Host[] hosts = Host.all();
+    new Yielder(hosts[0],"Yielder", new String[] {"10"}).start();
+    new Yielder(hosts[1],"Yielder", new String[] {"15"}).start();
+    
+    /*  execute the simulation. */
+    Msg.run();
+  }
+}
diff --git a/examples/java/async/yield/Yielder.java b/examples/java/async/yield/Yielder.java
new file mode 100644 (file)
index 0000000..1118f80
--- /dev/null
@@ -0,0 +1,27 @@
+/* Copyright (c) 2017. 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 async.yield;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.Host;
+import org.simgrid.msg.Task;
+import org.simgrid.msg.Process;
+import org.simgrid.msg.HostFailureException;
+import org.simgrid.msg.TimeoutException;
+import org.simgrid.msg.TransferFailureException;
+
+public class Yielder extends Process {
+  public Yielder (Host host, String name, String[] args) {
+    super(host, name, args);
+  }
+
+  @Override
+  public void main(String[] args) {
+    int yieldsCount = Integer.parseInt(args[0]);
+    for (int i=0; i<yieldsCount; i++)
+       yield();
+    Msg.info("Yielded "+yieldsCount+". Good bye now!");
+  }
+}
\ No newline at end of file
diff --git a/examples/java/async/yield/async_yield.tesh b/examples/java/async/yield/async_yield.tesh
new file mode 100644 (file)
index 0000000..68eddaa
--- /dev/null
@@ -0,0 +1,8 @@
+#! tesh
+
+! timeout 30
+$ java -classpath ${classpath:=.} async/yield/Main ${srcdir:=.}/../platforms/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [  0.000000] (0:maestro@) Using regular java threads.
+> [  0.000000] (1:Yielder@Boivin) Yielded 10. Good bye now!
+> [  0.000000] (2:Yielder@Bourassa) Yielded 15. Good bye now!
+> [  0.000000] (0:maestro@) MSG_main finished; Cleaning up the simulation...
index 6ec0684..7ddb3b6 100644 (file)
@@ -382,6 +382,11 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_migrate(JNIEnv * env, jobjec
   env->SetObjectField(jprocess, jprocess_field_Process_host, jhost);
 }
 
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_yield(JNIEnv* env, jclass cls)
+{
+  MSG_process_yield();
+}
+
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_setKillTime (JNIEnv *env , jobject jprocess, jdouble jkilltime) {
   msg_process_t process = jprocess_to_native_process(jprocess, env);
   MSG_process_set_kill_time(process, (double)jkilltime);
index 6704662..3c4bf5f 100644 (file)
@@ -235,6 +235,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_kill (JNIEnv *, jobject);
  */
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_migrate (JNIEnv *, jobject, jobject);
 
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_yield(JNIEnv* env, jclass cls);
 /*
  * Class    org_simgrid_msg_Process
  * Method    setKillTime
index 01f94b6..6d65b67 100644 (file)
@@ -200,6 +200,9 @@ public abstract class Process implements Runnable {
         */
        public native boolean isSuspended();
        
+       /** Yield the current process. All other processes that are ready at the same timestamp will be executed first */
+       public native static void yield();
+       
        /**
         * Specify whether the process should restart when its host restarts after a failure
         *