2013-09-26 21:44:39 +00:00
|
|
|
#include "ompi_config.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_TARGETCONDITIONALS_H
|
|
|
|
#include <TargetConditionals.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "mpi.h"
|
|
|
|
#include "mpi_Message.h"
|
|
|
|
#include "mpiJava.h"
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_mpi_Message_init(JNIEnv *e, jclass c)
|
|
|
|
{
|
|
|
|
ompi_java_setStaticLongField(e, c, "NULL", (jlong)MPI_MESSAGE_NULL);
|
|
|
|
ompi_java_setStaticLongField(e, c, "NO_PROC", (jlong)MPI_MESSAGE_NO_PROC);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jobject JNICALL Java_mpi_Message_imProbe(
|
|
|
|
JNIEnv *env, jobject jthis, jint source, jint tag, jlong comm)
|
|
|
|
{
|
|
|
|
MPI_Message message = (MPI_Message)((*env)->GetLongField(
|
|
|
|
env, jthis, ompi_java.MessageHandle));
|
|
|
|
int rc, flag;
|
|
|
|
MPI_Status status;
|
|
|
|
rc = MPI_Improbe(source, tag, (MPI_Comm)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;
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_mpi_Message_mRecv(
|
2014-02-16 22:58:01 +00:00
|
|
|
JNIEnv *env, jobject jthis, jobject buf, jboolean db,
|
|
|
|
jint offset, jint count, jobject jType, jobject stat)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
|
|
|
MPI_Message msg = (MPI_Message)((*env)->GetLongField(
|
|
|
|
env, jthis, ompi_java.MessageHandle));
|
|
|
|
|
|
|
|
MPI_Datatype type = (MPI_Datatype)((*env)->GetLongField(
|
|
|
|
env, jType, ompi_java.DatatypeHandle));
|
|
|
|
|
|
|
|
int bType = (*env)->GetIntField(env, jType, ompi_java.DatatypeBaseType);
|
|
|
|
void *bufPtr, *bufBase;
|
2014-02-16 22:58:01 +00:00
|
|
|
bufPtr = ompi_java_getBufPtr(&bufBase, env, buf, db, bType, offset);
|
2013-09-26 21:44:39 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseBufPtr(env, buf, db, bufBase, bType);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Message_imRecv(
|
|
|
|
JNIEnv *env, jobject jthis, jobject buf, jint count, jlong type)
|
|
|
|
{
|
|
|
|
MPI_Message msg = (MPI_Message)((*env)->GetLongField(
|
|
|
|
env, jthis, ompi_java.MessageHandle));
|
|
|
|
|
2013-09-29 10:36:09 +00:00
|
|
|
void *ptr = ompi_java_getDirectBufferAddress(env, buf);
|
2013-09-26 21:44:39 +00:00
|
|
|
MPI_Request request;
|
|
|
|
|
|
|
|
int rc = MPI_Imrecv(ptr, count, (MPI_Datatype)type, &msg, &request);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
(*env)->SetLongField(env, jthis, ompi_java.MessageHandle, (jlong)msg);
|
|
|
|
return (jlong)request;
|
|
|
|
}
|