From 98530055d17c085d7ae7d272d4f80193af9732b8 Mon Sep 17 00:00:00 2001 From: Oscar Vega-Gisbert Date: Mon, 17 Feb 2014 22:26:30 +0000 Subject: [PATCH] mpi.Message: java object members as parameters This commit was SVN r30755. --- ompi/mpi/java/c/mpi_Message.c | 76 ++++++++++++++------------------- ompi/mpi/java/java/Message.java | 20 +++++---- 2 files changed, 43 insertions(+), 53 deletions(-) diff --git a/ompi/mpi/java/c/mpi_Message.c b/ompi/mpi/java/c/mpi_Message.c index f30be27ac6..543758feb4 100644 --- a/ompi/mpi/java/c/mpi_Message.c +++ b/ompi/mpi/java/c/mpi_Message.c @@ -15,77 +15,65 @@ JNIEXPORT void JNICALL Java_mpi_Message_init(JNIEnv *e, jclass c) ompi_java.MessageHandle = (*e)->GetFieldID(e, c, "handle", "J"); } -JNIEXPORT jobject JNICALL Java_mpi_Message_mProbe( - JNIEnv *env, jobject jthis, jint source, jint tag, jlong comm) +JNIEXPORT jlong JNICALL Java_mpi_Message_mProbe( + JNIEnv *env, jobject jthis, + jint source, jint tag, jlong jComm, jobject jStatus) { - MPI_Message message = (MPI_Message)((*env)->GetLongField( - env, jthis, ompi_java.MessageHandle)); - int rc; - MPI_Status status; - rc = MPI_Mprobe(source, tag, (MPI_Comm)comm, &message, &status); - - if(ompi_java_exceptionCheck(env, rc)) - return NULL; - - (*env)->SetLongField(env, jthis, ompi_java.MessageHandle, (jlong)message); - jobject stat = ompi_java_status_new(&status, env); - return stat; + MPI_Comm comm = (MPI_Comm)jComm; + MPI_Message message; + MPI_Status status; + int rc = MPI_Mprobe(source, tag, comm, &message, &status); + ompi_java_exceptionCheck(env, rc); + ompi_java_status_set(&status, env, jStatus); + return (jlong)message; } JNIEXPORT jobject JNICALL Java_mpi_Message_imProbe( - JNIEnv *env, jobject jthis, jint source, jint tag, jlong comm) + JNIEnv *env, jobject jthis, jint source, jint tag, jlong jComm) { - MPI_Message message = (MPI_Message)((*env)->GetLongField( - env, jthis, ompi_java.MessageHandle)); + MPI_Comm comm = (MPI_Comm)jComm; + MPI_Message message; + MPI_Status status; int rc, flag; - MPI_Status status; - rc = MPI_Improbe(source, tag, (MPI_Comm)comm, &flag, &message, &status); + rc = MPI_Improbe(source, tag, comm, &flag, &message, &status); if(ompi_java_exceptionCheck(env, rc) || !flag) return NULL; (*env)->SetLongField(env, jthis, ompi_java.MessageHandle, (jlong)message); - jobject stat = ompi_java_status_new(&status, env); - return stat; + return ompi_java_status_new(&status, env); } -JNIEXPORT void JNICALL Java_mpi_Message_mRecv( - JNIEnv *env, jobject jthis, jobject buf, jboolean db, - jint offset, jint count, jobject jType, jobject stat) +JNIEXPORT jlong JNICALL Java_mpi_Message_mRecv( + JNIEnv *env, jobject jthis, jlong jMessage, jobject buf, jboolean db, + jint offset, jint count, jlong jType, jint bType, jobject stat) { - MPI_Message msg = (MPI_Message)((*env)->GetLongField( - env, jthis, ompi_java.MessageHandle)); + MPI_Message message = (MPI_Message)jMessage; + MPI_Datatype type = (MPI_Datatype)jType; - MPI_Datatype type = (MPI_Datatype)((*env)->GetLongField( - env, jType, ompi_java.DatatypeHandle)); - - int bType = (*env)->GetIntField(env, jType, ompi_java.DatatypeBaseType); void *bufPtr, *bufBase; bufPtr = ompi_java_getBufPtr(&bufBase, env, buf, db, bType, offset); MPI_Status status; - int rc = MPI_Mrecv(bufPtr, count, type, &msg, &status); - - if(!ompi_java_exceptionCheck(env, rc)) - { - (*env)->SetLongField(env, jthis, ompi_java.MessageHandle, (jlong)msg); - ompi_java_status_set(&status, env, stat); - } + int rc = MPI_Mrecv(bufPtr, count, type, &message, &status); + ompi_java_exceptionCheck(env, rc); + ompi_java_status_set(&status, env, stat); ompi_java_releaseBufPtr(env, buf, db, bufBase, bType); + return (jlong)message; } JNIEXPORT jlong JNICALL Java_mpi_Message_imRecv( - JNIEnv *env, jobject jthis, jobject buf, jint count, jlong type) + JNIEnv *env, jobject jthis, jlong jMessage, + jobject buf, jint count, jlong jType) { - MPI_Message msg = (MPI_Message)((*env)->GetLongField( - env, jthis, ompi_java.MessageHandle)); - + MPI_Message message = (MPI_Message)jMessage; + MPI_Datatype type = (MPI_Datatype)jType; void *ptr = ompi_java_getDirectBufferAddress(env, buf); - MPI_Request request; - int rc = MPI_Imrecv(ptr, count, (MPI_Datatype)type, &msg, &request); + MPI_Request request; + int rc = MPI_Imrecv(ptr, count, type, &message, &request); ompi_java_exceptionCheck(env, rc); - (*env)->SetLongField(env, jthis, ompi_java.MessageHandle, (jlong)msg); + (*env)->SetLongField(env, jthis, ompi_java.MessageHandle, (jlong)message); return (jlong)request; } diff --git a/ompi/mpi/java/java/Message.java b/ompi/mpi/java/java/Message.java index 6dc72424e8..f28d69b2ad 100644 --- a/ompi/mpi/java/java/Message.java +++ b/ompi/mpi/java/java/Message.java @@ -1,7 +1,6 @@ package mpi; import java.nio.*; -import static mpi.MPI.isHeapBuffer; import static mpi.MPI.assertDirectBuffer; /** @@ -56,10 +55,12 @@ public boolean isNoProc() public Status mProbe(int source, int tag, Comm comm) throws MPIException { MPI.check(); - return mProbe(source, tag, comm.handle); + Status status = new Status(); + handle = mProbe(source, tag, comm.handle, status); + return status; } -private native Status mProbe(int source, int tag, long comm) +private native long mProbe(int source, int tag, long comm, Status status) throws MPIException; /** @@ -100,13 +101,14 @@ public Status mRecv(Object buf, int count, Datatype type) } Status status = new Status(); - mRecv(buf, db, off, count, type, status); + handle = mRecv(handle, buf, db, off, count, + type.handle, type.baseType, status); return status; } -private native void mRecv( - Object buf, boolean db, int offset, int count, - Datatype type, Status status) throws MPIException; +private native long mRecv( + long message, Object buf, boolean db, int offset, int count, + long type, int baseType, Status status) throws MPIException; /** * Java binding of {@code MPI_IMRECV}. @@ -121,10 +123,10 @@ public Request imRecv(Buffer buf, int count, Datatype type) { MPI.check(); assertDirectBuffer(buf); - return new Request(imRecv(buf, count, type.handle)); + return new Request(imRecv(handle, buf, count, type.handle)); } -private native long imRecv(Object buf, int count, long type) +private native long imRecv(long message, Object buf, int count, long type) throws MPIException; } // Message