Error handling improvements
This commit improves and corrects error handling. In cases where existing objects are altered after a call to ompi_java_exceptionCheck, the results of the exception check method are checked. In the case of an exception, memory is cleaned up and the code returns to Java without altering existing objects. Signed-off-by: Nathaniel Graham <ngraham@lanl.gov>
Этот коммит содержится в:
родитель
9c496f767b
Коммит
5380427050
@ -11,6 +11,8 @@
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2015 Research Organization for Information Science
|
||||
* and Technology (RIST). All rights reserved.
|
||||
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
|
||||
* reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -205,7 +207,10 @@ JNIEXPORT jlongArray JNICALL Java_mpi_Comm_iDup(
|
||||
MPI_Comm newcomm;
|
||||
MPI_Request request;
|
||||
int rc = MPI_Comm_idup((MPI_Comm)comm, &newcomm, &request);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
|
||||
if(ompi_java_exceptionCheck(env, rc))
|
||||
return NULL;
|
||||
|
||||
jlongArray jcr = (*env)->NewLongArray(env, 2);
|
||||
jlong *cr = (jlong*)(*env)->GetPrimitiveArrayCritical(env, jcr, NULL);
|
||||
cr[0] = (jlong)newcomm;
|
||||
@ -332,6 +337,7 @@ JNIEXPORT void JNICALL Java_mpi_Comm_recv(
|
||||
jobject buf, jboolean db, jint offset, jint count,
|
||||
jlong jType, jint bType, jint source, jint tag, jlongArray jStatus)
|
||||
{
|
||||
jboolean exception;
|
||||
MPI_Comm comm = (MPI_Comm)jComm;
|
||||
MPI_Datatype type = (MPI_Datatype)jType;
|
||||
|
||||
@ -341,9 +347,11 @@ JNIEXPORT void JNICALL Java_mpi_Comm_recv(
|
||||
|
||||
MPI_Status status;
|
||||
int rc = MPI_Recv(ptr, count, type, source, tag, comm, &status);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
exception = ompi_java_exceptionCheck(env, rc);
|
||||
|
||||
ompi_java_releaseWritePtr(ptr,item,env,buf,db,offset,count,type,bType);
|
||||
|
||||
if(!exception)
|
||||
ompi_java_status_set(env, jStatus, &status);
|
||||
}
|
||||
|
||||
@ -355,6 +363,7 @@ JNIEXPORT void JNICALL Java_mpi_Comm_sendRecv(
|
||||
jlong rjType, jint rBType, jint source, jint rTag,
|
||||
jlongArray jStatus)
|
||||
{
|
||||
jboolean exception;
|
||||
MPI_Comm comm = (MPI_Comm)jComm;
|
||||
MPI_Datatype sType = (MPI_Datatype)sjType;
|
||||
MPI_Datatype rType = (MPI_Datatype)rjType;
|
||||
@ -369,9 +378,11 @@ JNIEXPORT void JNICALL Java_mpi_Comm_sendRecv(
|
||||
int rc = MPI_Sendrecv(sPtr, sCount, sType, dest, sTag,
|
||||
rPtr, rCount, rType, source, rTag, comm, &status);
|
||||
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
exception = ompi_java_exceptionCheck(env, rc);
|
||||
ompi_java_releaseReadPtr(sPtr, sItem, sBuf, sdb);
|
||||
ompi_java_releaseWritePtr(rPtr,rItem,env,rBuf,rdb,rOff,rCount,rType,rBType);
|
||||
|
||||
if(!exception)
|
||||
ompi_java_status_set(env, jStatus, &status);
|
||||
}
|
||||
|
||||
@ -392,8 +403,9 @@ JNIEXPORT void JNICALL Java_mpi_Comm_sendRecvReplace(
|
||||
int rc = MPI_Sendrecv_replace(ptr, count, type, dest,
|
||||
sTag, source, rTag, comm, &status);
|
||||
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
if(!ompi_java_exceptionCheck(env, rc))
|
||||
ompi_java_status_set(env, jStatus, &status);
|
||||
|
||||
ompi_java_releaseWritePtr(ptr,item,env,buf,db,offset,count,type,bType);
|
||||
}
|
||||
|
||||
@ -662,7 +674,8 @@ JNIEXPORT void JNICALL Java_mpi_Comm_probe(
|
||||
{
|
||||
MPI_Status status;
|
||||
int rc = MPI_Probe(source, tag, (MPI_Comm)comm, &status);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
|
||||
if(!ompi_java_exceptionCheck(env, rc))
|
||||
ompi_java_status_set(env, jStatus, &status);
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,8 @@
|
||||
* University of Stuttgart. All rights reserved.
|
||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
|
||||
* reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -92,7 +94,8 @@ JNIEXPORT void JNICALL Java_mpi_Datatype_getLbExtent(
|
||||
{
|
||||
MPI_Aint lb, extent;
|
||||
int rc = MPI_Type_get_extent((MPI_Datatype)type, &lb, &extent);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
if(ompi_java_exceptionCheck(env, rc))
|
||||
return;
|
||||
|
||||
jint *lbExt = (*env)->GetIntArrayElements(env, jLbExt, NULL);
|
||||
lbExt[0] = (jint)lb;
|
||||
@ -105,7 +108,8 @@ JNIEXPORT void JNICALL Java_mpi_Datatype_getTrueLbExtent(
|
||||
{
|
||||
MPI_Aint lb, extent;
|
||||
int rc = MPI_Type_get_true_extent((MPI_Datatype)type, &lb, &extent);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
if(ompi_java_exceptionCheck(env, rc))
|
||||
return;
|
||||
|
||||
jint *lbExt = (*env)->GetIntArrayElements(env, jLbExt, NULL);
|
||||
lbExt[0] = (jint)lb;
|
||||
|
@ -9,6 +9,8 @@
|
||||
* University of Stuttgart. All rights reserved.
|
||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
|
||||
* reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -137,6 +139,7 @@ JNIEXPORT void JNICALL Java_mpi_File_readAt(
|
||||
jobject buf, jboolean db, jint off, jint count,
|
||||
jlong jType, jint bType, jlongArray stat)
|
||||
{
|
||||
jboolean exception;
|
||||
MPI_Datatype type = (MPI_Datatype)jType;
|
||||
void *ptr;
|
||||
ompi_java_buffer_t *item;
|
||||
@ -146,8 +149,10 @@ JNIEXPORT void JNICALL Java_mpi_File_readAt(
|
||||
int rc = MPI_File_read_at((MPI_File)fh, (MPI_Offset)fileOffset,
|
||||
ptr, count, type, &status);
|
||||
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
exception = ompi_java_exceptionCheck(env, rc);
|
||||
ompi_java_releaseWritePtr(ptr, item, env, buf, db, off, count, type, bType);
|
||||
|
||||
if(!exception)
|
||||
ompi_java_status_set(env, stat, &status);
|
||||
}
|
||||
|
||||
@ -156,6 +161,7 @@ JNIEXPORT void JNICALL Java_mpi_File_readAtAll(
|
||||
jobject buf, jboolean db, jint off, jint count,
|
||||
jlong jType, jint bType, jlongArray stat)
|
||||
{
|
||||
jboolean exception;
|
||||
MPI_Datatype type = (MPI_Datatype)jType;
|
||||
void *ptr;
|
||||
ompi_java_buffer_t *item;
|
||||
@ -165,8 +171,10 @@ JNIEXPORT void JNICALL Java_mpi_File_readAtAll(
|
||||
int rc = MPI_File_read_at_all((MPI_File)fh, (MPI_Offset)fileOffset,
|
||||
ptr, count, type, &status);
|
||||
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
exception = ompi_java_exceptionCheck(env, rc);
|
||||
ompi_java_releaseWritePtr(ptr, item, env, buf, db, off, count, type, bType);
|
||||
|
||||
if(!exception)
|
||||
ompi_java_status_set(env, stat, &status);
|
||||
}
|
||||
|
||||
@ -175,6 +183,7 @@ JNIEXPORT void JNICALL Java_mpi_File_writeAt(
|
||||
jobject buf, jboolean db, jint off, jint count,
|
||||
jlong jType, jint bType, jlongArray stat)
|
||||
{
|
||||
jboolean exception;
|
||||
MPI_Datatype type = (MPI_Datatype)jType;
|
||||
void *ptr;
|
||||
ompi_java_buffer_t *item;
|
||||
@ -184,8 +193,10 @@ JNIEXPORT void JNICALL Java_mpi_File_writeAt(
|
||||
int rc = MPI_File_write_at((MPI_File)fh, (MPI_Offset)fileOffset,
|
||||
ptr, count, type, &status);
|
||||
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
exception = ompi_java_exceptionCheck(env, rc);
|
||||
ompi_java_releaseReadPtr(ptr, item, buf, db);
|
||||
|
||||
if(!exception)
|
||||
ompi_java_status_set(env, stat, &status);
|
||||
}
|
||||
|
||||
@ -194,6 +205,7 @@ JNIEXPORT void JNICALL Java_mpi_File_writeAtAll(
|
||||
jobject buf, jboolean db, jint off, jint count,
|
||||
jlong jType, jint bType, jlongArray stat)
|
||||
{
|
||||
jboolean exception;
|
||||
MPI_Datatype type = (MPI_Datatype)jType;
|
||||
void *ptr;
|
||||
ompi_java_buffer_t *item;
|
||||
@ -203,8 +215,10 @@ JNIEXPORT void JNICALL Java_mpi_File_writeAtAll(
|
||||
int rc = MPI_File_write_at_all((MPI_File)fh, (MPI_Offset)fileOffset,
|
||||
ptr, count, (MPI_Datatype)type, &status);
|
||||
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
exception = ompi_java_exceptionCheck(env, rc);
|
||||
ompi_java_releaseReadPtr(ptr, item, buf, db);
|
||||
|
||||
if(!exception)
|
||||
ompi_java_status_set(env, stat, &status);
|
||||
}
|
||||
|
||||
@ -240,14 +254,17 @@ JNIEXPORT void JNICALL Java_mpi_File_read(
|
||||
JNIEnv *env, jobject jthis, jlong fh, jobject buf, jboolean db,
|
||||
jint off, jint count, jlong jType, jint bType, jlongArray stat)
|
||||
{
|
||||
jboolean exception;
|
||||
MPI_Datatype type = (MPI_Datatype)jType;
|
||||
void *ptr;
|
||||
ompi_java_buffer_t *item;
|
||||
ompi_java_getWritePtr(&ptr, &item, env, buf, db, count, type);
|
||||
MPI_Status status;
|
||||
int rc = MPI_File_read((MPI_File)fh, ptr, count, type, &status);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
exception = ompi_java_exceptionCheck(env, rc);
|
||||
ompi_java_releaseWritePtr(ptr, item, env, buf, db, off, count, type, bType);
|
||||
|
||||
if(!exception)
|
||||
ompi_java_status_set(env, stat, &status);
|
||||
}
|
||||
|
||||
@ -255,14 +272,17 @@ JNIEXPORT void JNICALL Java_mpi_File_readAll(
|
||||
JNIEnv *env, jobject jthis, jlong fh, jobject buf, jboolean db,
|
||||
jint off, jint count, jlong jType, jint bType, jlongArray stat)
|
||||
{
|
||||
jboolean exception;
|
||||
MPI_Datatype type = (MPI_Datatype)jType;
|
||||
void *ptr;
|
||||
ompi_java_buffer_t *item;
|
||||
ompi_java_getWritePtr(&ptr, &item, env, buf, db, count, type);
|
||||
MPI_Status status;
|
||||
int rc = MPI_File_read_all((MPI_File)fh, ptr, count, type, &status);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
exception = ompi_java_exceptionCheck(env, rc);
|
||||
ompi_java_releaseWritePtr(ptr, item, env, buf, db, off, count, type, bType);
|
||||
|
||||
if(!exception)
|
||||
ompi_java_status_set(env, stat, &status);
|
||||
}
|
||||
|
||||
@ -270,14 +290,17 @@ JNIEXPORT void JNICALL Java_mpi_File_write(
|
||||
JNIEnv *env, jobject jthis, jlong fh, jobject buf, jboolean db,
|
||||
jint off, jint count, jlong jType, jint bType, jlongArray stat)
|
||||
{
|
||||
jboolean exception;
|
||||
MPI_Datatype type = (MPI_Datatype)jType;
|
||||
void *ptr;
|
||||
ompi_java_buffer_t *item;
|
||||
ompi_java_getReadPtr(&ptr, &item, env, buf, db, off, count, type, bType);
|
||||
MPI_Status status;
|
||||
int rc = MPI_File_write((MPI_File)fh, ptr, count, type, &status);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
exception = ompi_java_exceptionCheck(env, rc);
|
||||
ompi_java_releaseReadPtr(ptr, item, buf, db);
|
||||
|
||||
if(!exception)
|
||||
ompi_java_status_set(env, stat, &status);
|
||||
}
|
||||
|
||||
@ -285,14 +308,17 @@ JNIEXPORT void JNICALL Java_mpi_File_writeAll(
|
||||
JNIEnv *env, jobject jthis, jlong fh, jobject buf, jboolean db,
|
||||
jint off, jint count, jlong jType, jint bType, jlongArray stat)
|
||||
{
|
||||
jboolean exception;
|
||||
MPI_Datatype type = (MPI_Datatype)jType;
|
||||
void *ptr;
|
||||
ompi_java_buffer_t *item;
|
||||
ompi_java_getReadPtr(&ptr, &item, env, buf, db, off, count, type, bType);
|
||||
MPI_Status status;
|
||||
int rc = MPI_File_write_all((MPI_File)fh, ptr, count, type, &status);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
exception = ompi_java_exceptionCheck(env, rc);
|
||||
ompi_java_releaseReadPtr(ptr, item, buf, db);
|
||||
|
||||
if(!exception)
|
||||
ompi_java_status_set(env, stat, &status);
|
||||
}
|
||||
|
||||
@ -353,14 +379,17 @@ JNIEXPORT void JNICALL Java_mpi_File_readShared(
|
||||
JNIEnv *env, jobject jthis, jlong fh, jobject buf, jboolean db,
|
||||
jint off, jint count, jlong jType, jint bType, jlongArray stat)
|
||||
{
|
||||
jboolean exception;
|
||||
MPI_Datatype type = (MPI_Datatype)jType;
|
||||
void *ptr;
|
||||
ompi_java_buffer_t *item;
|
||||
ompi_java_getWritePtr(&ptr, &item, env, buf, db, count, type);
|
||||
MPI_Status status;
|
||||
int rc = MPI_File_read_shared((MPI_File)fh, ptr, count, type, &status);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
exception = ompi_java_exceptionCheck(env, rc);
|
||||
ompi_java_releaseWritePtr(ptr, item, env, buf, db, off, count, type, bType);
|
||||
|
||||
if(!exception)
|
||||
ompi_java_status_set(env, stat, &status);
|
||||
}
|
||||
|
||||
@ -368,14 +397,17 @@ JNIEXPORT void JNICALL Java_mpi_File_writeShared(
|
||||
JNIEnv *env, jobject jthis, jlong fh, jobject buf, jboolean db,
|
||||
jint off, jint count, jlong jType, jint bType, jlongArray stat)
|
||||
{
|
||||
jboolean exception;
|
||||
MPI_Datatype type = (MPI_Datatype)jType;
|
||||
void *ptr;
|
||||
ompi_java_buffer_t *item;
|
||||
ompi_java_getReadPtr(&ptr, &item, env, buf, db, off, count, type, bType);
|
||||
MPI_Status status;
|
||||
int rc = MPI_File_write_shared((MPI_File)fh, ptr, count, type, &status);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
exception = ompi_java_exceptionCheck(env, rc);
|
||||
ompi_java_releaseReadPtr(ptr, item, buf, db);
|
||||
|
||||
if(!exception)
|
||||
ompi_java_status_set(env, stat, &status);
|
||||
}
|
||||
|
||||
@ -411,14 +443,17 @@ JNIEXPORT void JNICALL Java_mpi_File_readOrdered(
|
||||
JNIEnv *env, jobject jthis, jlong fh, jobject buf, jboolean db,
|
||||
jint off, jint count, jlong jType, jint bType, jlongArray stat)
|
||||
{
|
||||
jboolean exception;
|
||||
MPI_Datatype type = (MPI_Datatype)jType;
|
||||
void *ptr;
|
||||
ompi_java_buffer_t *item;
|
||||
ompi_java_getWritePtr(&ptr, &item, env, buf, db, count, type);
|
||||
MPI_Status status;
|
||||
int rc = MPI_File_read_ordered((MPI_File)fh, ptr, count, type, &status);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
exception = ompi_java_exceptionCheck(env, rc);
|
||||
ompi_java_releaseWritePtr(ptr, item, env, buf, db, off, count, type, bType);
|
||||
|
||||
if(!exception)
|
||||
ompi_java_status_set(env, stat, &status);
|
||||
}
|
||||
|
||||
@ -426,14 +461,17 @@ JNIEXPORT void JNICALL Java_mpi_File_writeOrdered(
|
||||
JNIEnv *env, jobject jthis, jlong fh, jobject buf, jboolean db,
|
||||
jint off, jint count, jlong jType, jint bType, jlongArray stat)
|
||||
{
|
||||
jboolean exception;
|
||||
MPI_Datatype type = (MPI_Datatype)jType;
|
||||
void *ptr;
|
||||
ompi_java_buffer_t *item;
|
||||
ompi_java_getReadPtr(&ptr, &item, env, buf, db, off, count, type, bType);
|
||||
MPI_Status status;
|
||||
int rc = MPI_File_write_ordered((MPI_File)fh, ptr, count, type, &status);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
exception = ompi_java_exceptionCheck(env, rc);
|
||||
ompi_java_releaseReadPtr(ptr, item, buf, db);
|
||||
|
||||
if(!exception)
|
||||
ompi_java_status_set(env, stat, &status);
|
||||
}
|
||||
|
||||
@ -470,7 +508,8 @@ JNIEXPORT void JNICALL Java_mpi_File_readAtAllEnd(
|
||||
MPI_Status status;
|
||||
void *ptr = (*env)->GetDirectBufferAddress(env, buf);
|
||||
int rc = MPI_File_read_at_all_end((MPI_File)fh, ptr, &status);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
|
||||
if(!ompi_java_exceptionCheck(env, rc))
|
||||
ompi_java_status_set(env, stat, &status);
|
||||
}
|
||||
|
||||
@ -491,7 +530,8 @@ JNIEXPORT void JNICALL Java_mpi_File_writeAtAllEnd(
|
||||
MPI_Status status;
|
||||
void *ptr = (*env)->GetDirectBufferAddress(env, buf);
|
||||
int rc = MPI_File_write_at_all_end((MPI_File)fh, ptr, &status);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
|
||||
if(!ompi_java_exceptionCheck(env, rc))
|
||||
ompi_java_status_set(env, stat, &status);
|
||||
}
|
||||
|
||||
@ -513,7 +553,8 @@ JNIEXPORT void JNICALL Java_mpi_File_readAllEnd(
|
||||
MPI_Status status;
|
||||
void *ptr = (*env)->GetDirectBufferAddress(env, buf);
|
||||
int rc = MPI_File_read_all_end((MPI_File)fh, ptr, &status);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
|
||||
if(!ompi_java_exceptionCheck(env, rc))
|
||||
ompi_java_status_set(env, stat, &status);
|
||||
}
|
||||
|
||||
@ -535,7 +576,8 @@ JNIEXPORT void JNICALL Java_mpi_File_writeAllEnd(
|
||||
MPI_Status status;
|
||||
void *ptr = (*env)->GetDirectBufferAddress(env, buf);
|
||||
int rc = MPI_File_write_all_end((MPI_File)fh, ptr, &status);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
|
||||
if(!ompi_java_exceptionCheck(env, rc))
|
||||
ompi_java_status_set(env, stat, &status);
|
||||
}
|
||||
|
||||
@ -557,7 +599,8 @@ JNIEXPORT void JNICALL Java_mpi_File_readOrderedEnd(
|
||||
MPI_Status status;
|
||||
void *ptr = (*env)->GetDirectBufferAddress(env, buf);
|
||||
int rc = MPI_File_read_ordered_end((MPI_File)fh, ptr, &status);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
|
||||
if(!ompi_java_exceptionCheck(env, rc))
|
||||
ompi_java_status_set(env, stat, &status);
|
||||
}
|
||||
|
||||
@ -579,7 +622,8 @@ JNIEXPORT void JNICALL Java_mpi_File_writeOrderedEnd(
|
||||
MPI_Status status;
|
||||
void *ptr = (*env)->GetDirectBufferAddress(env, buf);
|
||||
int rc = MPI_File_write_ordered_end((MPI_File)fh, ptr, &status);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
|
||||
if(!ompi_java_exceptionCheck(env, rc))
|
||||
ompi_java_status_set(env, stat, &status);
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
* University of Stuttgart. All rights reserved.
|
||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
|
||||
* Copyright (c) 2015-2016 Los Alamos National Security, LLC. All rights
|
||||
* reserved.
|
||||
* Copyright (c) 2015-2016 Cisco Systems, Inc. All rights reserved.
|
||||
* Copyright (c) 2015 Intel, Inc. All rights reserved.
|
||||
@ -316,7 +316,14 @@ JNIEXPORT jobjectArray JNICALL Java_mpi_MPI_Init_1jni(
|
||||
}
|
||||
|
||||
int rc = MPI_Init(&len, &sargs);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
|
||||
if(ompi_java_exceptionCheck(env, rc)) {
|
||||
for(i = 0; i < len; i++)
|
||||
free (sargs[i]);
|
||||
free(sargs);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mca_base_var_register("ompi", "mpi", "java", "eager",
|
||||
"Java buffers eager size",
|
||||
MCA_BASE_VAR_TYPE_INT, NULL, 0, 0,
|
||||
@ -360,7 +367,13 @@ JNIEXPORT jint JNICALL Java_mpi_MPI_InitThread_1jni(
|
||||
|
||||
int provided;
|
||||
int rc = MPI_Init_thread(&len, &sargs, required, &provided);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
|
||||
if(ompi_java_exceptionCheck(env, rc)) {
|
||||
for(i = 0; i < len; i++)
|
||||
free (sargs[i]);
|
||||
free(sargs);
|
||||
return -1;
|
||||
}
|
||||
|
||||
findClasses(env);
|
||||
initFreeList();
|
||||
@ -1126,6 +1139,18 @@ void ompi_java_releasePtrArray(JNIEnv *env, jlongArray array,
|
||||
(*env)->ReleaseLongArrayElements(env, array, jptr, 0);
|
||||
}
|
||||
|
||||
/* This method checks whether an MPI or JNI exception has occurred.
|
||||
* If an exception occurs, the C code will continue running. Once
|
||||
* code execution returns to Java code, an exception is immediately
|
||||
* thrown. Since an exception has occurred somewhere in the C code,
|
||||
* the object that is returned from C may not be valid. This is not
|
||||
* an issue, however, as the assignment opperation will not be
|
||||
* executed. The results of this method need not be checked if the
|
||||
* only following code cleans up memory and then returns to Java.
|
||||
* If existing objects are changed after a call to this method, the
|
||||
* results need to be checked and, if an error has occurred, the
|
||||
* code should instead cleanup any memory and return.
|
||||
*/
|
||||
jboolean ompi_java_exceptionCheck(JNIEnv *env, int rc)
|
||||
{
|
||||
jboolean jni_exception;
|
||||
|
@ -9,6 +9,8 @@
|
||||
* University of Stuttgart. All rights reserved.
|
||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
|
||||
* reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -41,8 +43,10 @@ JNIEXPORT jlong JNICALL Java_mpi_Message_mProbe(
|
||||
MPI_Message message;
|
||||
MPI_Status status;
|
||||
int rc = MPI_Mprobe(source, tag, comm, &message, &status);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
|
||||
if(!ompi_java_exceptionCheck(env, rc))
|
||||
ompi_java_status_set(env, jStatus, &status);
|
||||
|
||||
return (jlong)message;
|
||||
}
|
||||
|
||||
@ -75,9 +79,10 @@ JNIEXPORT jlong JNICALL Java_mpi_Message_mRecv(
|
||||
|
||||
MPI_Status status;
|
||||
int rc = MPI_Mrecv(ptr, count, type, &message, &status);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
|
||||
if(!ompi_java_exceptionCheck(env, rc))
|
||||
ompi_java_status_set(env, jStatus, &status);
|
||||
|
||||
ompi_java_releaseWritePtr(ptr, item, env, buf, db, off, count, type, bType);
|
||||
return (jlong)message;
|
||||
}
|
||||
|
@ -9,6 +9,8 @@
|
||||
* University of Stuttgart. All rights reserved.
|
||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
|
||||
* reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -145,8 +147,10 @@ JNIEXPORT jlong JNICALL Java_mpi_Request_waitStatus(
|
||||
MPI_Request req = (MPI_Request)handle;
|
||||
MPI_Status status;
|
||||
int rc = MPI_Wait(&req, &status);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
|
||||
if(!ompi_java_exceptionCheck(env, rc))
|
||||
ompi_java_status_set(env, stat, &status);
|
||||
|
||||
return (jlong)req;
|
||||
}
|
||||
|
||||
@ -166,8 +170,10 @@ JNIEXPORT jobject JNICALL Java_mpi_Request_testStatus(
|
||||
int flag;
|
||||
MPI_Status status;
|
||||
int rc = MPI_Test(&req, &flag, &status);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
|
||||
if(!ompi_java_exceptionCheck(env, rc))
|
||||
(*env)->SetLongField(env, jthis, ompi_java.ReqHandle, (jlong)req);
|
||||
|
||||
return flag ? ompi_java_status_new(env, &status) : NULL;
|
||||
}
|
||||
|
||||
@ -178,8 +184,10 @@ JNIEXPORT jobject JNICALL Java_mpi_Request_getStatus(
|
||||
int flag;
|
||||
MPI_Status status;
|
||||
int rc = MPI_Request_get_status(req, &flag, &status);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
|
||||
if(!ompi_java_exceptionCheck(env, rc))
|
||||
(*env)->SetLongField(env, jthis, ompi_java.ReqHandle, (jlong)req);
|
||||
|
||||
return flag ? ompi_java_status_new(env, &status) : NULL;
|
||||
}
|
||||
|
||||
@ -189,14 +197,17 @@ JNIEXPORT jboolean JNICALL Java_mpi_Request_test(
|
||||
MPI_Request req = (MPI_Request)handle;
|
||||
int flag;
|
||||
int rc = MPI_Test(&req, &flag, MPI_STATUS_IGNORE);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
|
||||
if(!ompi_java_exceptionCheck(env, rc))
|
||||
(*env)->SetLongField(env, jthis, ompi_java.ReqHandle, (jlong)req);
|
||||
|
||||
return flag ? JNI_TRUE : JNI_FALSE;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_mpi_Request_waitAnyStatus(
|
||||
JNIEnv *env, jclass clazz, jlongArray requests, jobject stat)
|
||||
{
|
||||
jboolean exception;
|
||||
int count = (*env)->GetArrayLength(env, requests);
|
||||
jlong* jReq;
|
||||
MPI_Request *cReq;
|
||||
@ -204,8 +215,10 @@ JNIEXPORT void JNICALL Java_mpi_Request_waitAnyStatus(
|
||||
int index;
|
||||
MPI_Status status;
|
||||
int rc = MPI_Waitany(count, cReq, &index, &status);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
exception = ompi_java_exceptionCheck(env, rc);
|
||||
ompi_java_releasePtrArray(env, requests, jReq, (void**)cReq);
|
||||
|
||||
if(!exception)
|
||||
ompi_java_status_setIndex(env, stat, &status, index);
|
||||
}
|
||||
|
||||
@ -333,6 +346,7 @@ JNIEXPORT jobjectArray JNICALL Java_mpi_Request_waitSomeStatus(
|
||||
JNIEXPORT jintArray JNICALL Java_mpi_Request_waitSome(
|
||||
JNIEnv *env, jclass clazz, jlongArray requests)
|
||||
{
|
||||
jboolean exception;
|
||||
int incount = (*env)->GetArrayLength(env, requests);
|
||||
jlong* jReq;
|
||||
MPI_Request *cReq;
|
||||
@ -340,8 +354,14 @@ JNIEXPORT jintArray JNICALL Java_mpi_Request_waitSome(
|
||||
int *indices = (int*)calloc(incount, sizeof(int));
|
||||
int outcount;
|
||||
int rc = MPI_Waitsome(incount, cReq, &outcount, indices, MPI_STATUSES_IGNORE);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
exception = ompi_java_exceptionCheck(env, rc);
|
||||
ompi_java_releasePtrArray(env, requests, jReq, (void**)cReq);
|
||||
|
||||
if(exception) {
|
||||
free(indices);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
jintArray jindices = NULL;
|
||||
|
||||
if(outcount != MPI_UNDEFINED)
|
||||
@ -376,6 +396,7 @@ JNIEXPORT jobjectArray JNICALL Java_mpi_Request_testSomeStatus(
|
||||
JNIEXPORT jintArray JNICALL Java_mpi_Request_testSome(
|
||||
JNIEnv *env, jclass clazz, jlongArray requests)
|
||||
{
|
||||
jboolean exception;
|
||||
int incount = (*env)->GetArrayLength(env, requests);
|
||||
jlong* jReq;
|
||||
MPI_Request *cReq;
|
||||
@ -383,8 +404,14 @@ JNIEXPORT jintArray JNICALL Java_mpi_Request_testSome(
|
||||
int *indices = (int*)calloc(incount, sizeof(int));
|
||||
int outcount;
|
||||
int rc = MPI_Testsome(incount, cReq, &outcount, indices, MPI_STATUSES_IGNORE);
|
||||
ompi_java_exceptionCheck(env, rc);
|
||||
exception = ompi_java_exceptionCheck(env, rc);
|
||||
ompi_java_releasePtrArray(env, requests, jReq, (void**)cReq);
|
||||
|
||||
if(exception) {
|
||||
free(indices);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
jintArray jindices = NULL;
|
||||
|
||||
if(outcount != MPI_UNDEFINED)
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user