Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[java] New function: msg.Comm.waitAll()
authorMartin Quinson <martin.quinson@loria.fr>
Mon, 22 Aug 2016 23:34:49 +0000 (01:34 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Mon, 22 Aug 2016 23:34:49 +0000 (01:34 +0200)
ChangeLog
src/bindings/java/jmsg_comm.cpp
src/bindings/java/jmsg_comm.h
src/bindings/java/org/simgrid/msg/Comm.java

index 6f5ac48..dc40fe4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -36,7 +36,8 @@ SimGrid (3.14) UNRELEASED; urgency=low
    They may become useful to some lucky ones.
    
  Java:
- * app_tokenring: new example, very similar to the MSG Token Ring
+ * New function: msg.Comm.waitAll()
+ * ex/app_tokenring: new example, very similar to the MSG Token Ring
 
  -- $date Da SimGrid team <simgrid-devel@lists.gforge.inria.fr>
 
index 9570c3c..c15abe3 100644 (file)
@@ -120,3 +120,31 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_waitCompletion(JNIEnv *env, job
     jmsg_throw_status(env,status);
   }
 }
+
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_waitAll(JNIEnv *env, jclass cls, jobjectArray jcomms, jdouble timeout)
+{
+  int count = env->GetArrayLength(jcomms);
+  msg_comm_t* comms = xbt_new(msg_comm_t, count);
+
+  for (int i=0; i < count; i++) {
+     jobject jcomm = env->GetObjectArrayElement(jcomms, i);
+     if (env->ExceptionOccurred())
+        break;
+
+     comms[i] = (msg_comm_t) (uintptr_t) env->GetLongField(jcomm, jcomm_field_Comm_bind);
+     if (!comms[i]) {
+       jxbt_throw_native(env,bprintf("comm at rank %d is null",i));
+       return;
+     }
+
+     env->DeleteLocalRef(jcomm); // reduce the load on the garbage collector: we don't need that object anymore
+  }
+  MSG_comm_waitall(comms, count, static_cast<double>(timeout));
+  xbt_free(comms);
+}
+/*
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_waitAny(JNIEnv *env, jobject jcomm, jarray comms)
+{
+
+}
+*/
index e5cd3de..919f8d1 100644 (file)
@@ -23,6 +23,8 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_nativeFinalize(JNIEnv *env, job
 JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Comm_test(JNIEnv *env, jobject jcomm);
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_waitCompletion(JNIEnv *env, jobject jcomm, jdouble timeout);
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_waitAll(JNIEnv *env, jclass cls, jobjectArray comms, jdouble timeout);
+//JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_waitAny(JNIEnv *env, jobject jcomm, jarray comms);
 
 SG_END_DECL()
 #endif /* MSG_JCOMM_H */
index 29c5587..16844aa 100644 (file)
@@ -54,6 +54,14 @@ public class Comm {
         */
        public native void waitCompletion(double timeout) throws TransferFailureException, HostFailureException, TimeoutException;
 
+       /** Wait all of the communications */
+       public native static void waitAll(Comm[] comms, double timeout) throws TransferFailureException, HostFailureException, TimeoutException;
+       /** Wait all of the communications, with no maximal delay */
+       public static void waitAll(Comm[] comms) throws TransferFailureException, HostFailureException, TimeoutException {
+               waitAll(comms, -1.);
+       }
+       /** Wait any of the communications, and return the rank of the terminating comm */
+       //public native int waitAny(Comm[] comms);
        /**
         * Returns the task associated with the communication.
         * if the communication isn't finished yet, will return null.