1
1
openmpi/ompi/mpi/java/c/mpi_Message.c

100 строки
3.3 KiB
C
Исходник Обычный вид История

/*
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#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 jlong JNICALL Java_mpi_Message_mProbe(
JNIEnv *env, jobject jthis,
jint source, jint tag, jlong jComm, jlongArray jStatus)
{
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(env, jStatus, &status);
return (jlong)message;
}
JNIEXPORT jboolean JNICALL Java_mpi_Message_imProbe(
JNIEnv *env, jobject jthis, jint source,
jint tag, jlong jComm, jlongArray jStatus)
{
MPI_Comm comm = (MPI_Comm)jComm;
MPI_Message message;
MPI_Status status;
int rc, flag;
rc = MPI_Improbe(source, tag, comm, &flag, &message, &status);
if(ompi_java_exceptionCheck(env, rc) || !flag)
return JNI_FALSE;
(*env)->SetLongField(env, jthis, ompi_java.MessageHandle, (jlong)message);
ompi_java_status_set(env, jStatus, &status);
return JNI_TRUE;
}
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, jlongArray jStatus)
{
MPI_Message message = (MPI_Message)jMessage;
MPI_Datatype type = (MPI_Datatype)jType;
void *bufPtr, *bufBase;
bufPtr = ompi_java_getBufPtr(&bufBase, env, buf, db, bType, offset);
MPI_Status status;
int rc = MPI_Mrecv(bufPtr, count, type, &message, &status);
ompi_java_exceptionCheck(env, rc);
ompi_java_status_set(env, jStatus, &status);
ompi_java_releaseBufPtr(env, buf, db, bufBase, bType);
return (jlong)message;
}
JNIEXPORT jlong JNICALL Java_mpi_Message_imRecv(
JNIEnv *env, jobject jthis, jlong jMessage,
jobject buf, jint count, jlong jType)
{
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, type, &message, &request);
ompi_java_exceptionCheck(env, rc);
(*env)->SetLongField(env, jthis, ompi_java.MessageHandle, (jlong)message);
return (jlong)request;
}