2012-02-20 22:12:43 +00:00
|
|
|
/*
|
2014-03-01 20:18:05 +00:00
|
|
|
* 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$
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* This file is almost a complete re-write for Open MPI compared to the
|
|
|
|
* original mpiJava package. Its license and copyright are listed below.
|
|
|
|
* See <path to ompi/mpi/java/README> for more information.
|
|
|
|
*/
|
|
|
|
/*
|
2012-02-20 22:12:43 +00:00
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* File : mpi_Comm.c
|
2013-09-26 21:44:39 +00:00
|
|
|
* Headerfile : mpi_Comm.h
|
2012-02-20 22:12:43 +00:00
|
|
|
* Author : Sung-Hoon Ko, Xinying Li, Sang Lim, Bryan Carpenter
|
|
|
|
* Created : Thu Apr 9 12:22:15 1998
|
|
|
|
* Revision : $Revision: 1.17 $
|
|
|
|
* Updated : $Date: 2003/01/16 16:39:34 $
|
|
|
|
* Copyright: Northeast Parallel Architectures Center
|
|
|
|
* at Syracuse University 1998
|
|
|
|
*/
|
|
|
|
#include "ompi_config.h"
|
|
|
|
#include <stdlib.h>
|
2013-09-26 21:44:39 +00:00
|
|
|
#include <assert.h>
|
2012-02-20 22:12:43 +00:00
|
|
|
#ifdef HAVE_TARGETCONDITIONALS_H
|
|
|
|
#include <TargetConditionals.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "mpi.h"
|
|
|
|
#include "mpi_Comm.h"
|
|
|
|
#include "mpiJava.h" /* must come AFTER the related .h so JNI is included */
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
static void* getArrayPtr(void** bufBase, JNIEnv *env,
|
|
|
|
jobject buf, int baseType, int offset)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2013-09-26 21:44:39 +00:00
|
|
|
switch(baseType)
|
|
|
|
{
|
|
|
|
case 0: /* NULL */
|
|
|
|
*bufBase = NULL;
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
case 1: {
|
|
|
|
jbyte* els = (*env)->GetByteArrayElements(env, buf, NULL);
|
|
|
|
*bufBase = els;
|
|
|
|
return els + offset;
|
|
|
|
}
|
|
|
|
case 2: {
|
|
|
|
jchar* els = (*env)->GetCharArrayElements(env, buf, NULL);
|
|
|
|
*bufBase = els;
|
|
|
|
return els + offset;
|
|
|
|
}
|
|
|
|
case 3: {
|
|
|
|
jshort* els = (*env)->GetShortArrayElements(env, buf, NULL);
|
|
|
|
*bufBase = els;
|
|
|
|
return els + offset;
|
|
|
|
}
|
|
|
|
case 4: {
|
|
|
|
jboolean* els = (*env)->GetBooleanArrayElements(env, buf, NULL);
|
|
|
|
*bufBase = els;
|
|
|
|
return els + offset;
|
|
|
|
}
|
|
|
|
case 5: {
|
|
|
|
jint* els = (*env)->GetIntArrayElements(env, buf, NULL);
|
|
|
|
*bufBase = els;
|
|
|
|
return els + offset;
|
|
|
|
}
|
|
|
|
case 6: {
|
|
|
|
jlong* els = (*env)->GetLongArrayElements(env, buf, NULL);
|
|
|
|
*bufBase = els;
|
|
|
|
return els + offset;
|
|
|
|
}
|
|
|
|
case 7: {
|
|
|
|
jfloat* els = (*env)->GetFloatArrayElements(env, buf, NULL);
|
|
|
|
*bufBase = els;
|
|
|
|
return els + offset;
|
|
|
|
}
|
|
|
|
case 8: {
|
|
|
|
jdouble* els = (*env)->GetDoubleArrayElements(env, buf, NULL);
|
|
|
|
*bufBase = els;
|
|
|
|
return els + offset;
|
|
|
|
}
|
|
|
|
case 9: {
|
|
|
|
jbyte* els = (*env)->GetByteArrayElements(env, buf, NULL);
|
|
|
|
*bufBase = els;
|
|
|
|
return els + offset;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
*bufBase = NULL;
|
|
|
|
return NULL; /* 'UNDEFINED' */
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
static void releaseArrayPtr(JNIEnv *e, jobject buf, void *bufBase,
|
|
|
|
int baseType, jint mode)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2013-09-26 21:44:39 +00:00
|
|
|
switch(baseType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
(*e)->ReleaseByteArrayElements(e, buf, (jbyte*)bufBase, mode);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
(*e)->ReleaseCharArrayElements(e, buf, (jchar*)bufBase, mode);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
(*e)->ReleaseShortArrayElements(e, buf, (jshort*)bufBase, mode);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
(*e)->ReleaseBooleanArrayElements(e, buf, (jboolean*)bufBase, mode);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
(*e)->ReleaseIntArrayElements(e, buf, (jint*)bufBase, mode);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
(*e)->ReleaseLongArrayElements(e, buf, (jlong*)bufBase, mode);
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
(*e)->ReleaseFloatArrayElements(e, buf, (jfloat*)bufBase, mode);
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
(*e)->ReleaseDoubleArrayElements(e, buf, (jdouble*)bufBase, mode);
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
(*e)->ReleaseByteArrayElements(e, buf, (jbyte*)bufBase, mode);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
void* ompi_java_getBufPtr(void** bufBase, JNIEnv *env, jobject buf,
|
2014-02-16 22:58:01 +00:00
|
|
|
jboolean db, int baseType, int offset)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2013-09-29 10:36:09 +00:00
|
|
|
if(buf == NULL)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2013-09-29 10:36:09 +00:00
|
|
|
/* Allow NULL buffers to send/recv 0 items as control messages. */
|
|
|
|
*bufBase = NULL;
|
|
|
|
return NULL;
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
2014-02-16 22:58:01 +00:00
|
|
|
else if(db)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2013-09-29 10:36:09 +00:00
|
|
|
*bufBase = (*env)->GetDirectBufferAddress(env, buf);
|
2014-02-16 22:58:01 +00:00
|
|
|
assert(offset == 0);
|
|
|
|
return *bufBase;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return getArrayPtr(bufBase, env, buf, baseType, offset);
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-16 22:58:01 +00:00
|
|
|
void ompi_java_releaseBufPtr(JNIEnv *env, jobject buf, jboolean db,
|
2013-09-26 21:44:39 +00:00
|
|
|
void* bufBase, int baseType)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2014-03-01 19:54:36 +00:00
|
|
|
if(!db && buf)
|
2013-09-26 21:44:39 +00:00
|
|
|
releaseArrayPtr(env, buf, bufBase, baseType, 0);
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2014-02-16 22:58:01 +00:00
|
|
|
void ompi_java_releaseReadBufPtr(JNIEnv *env, jobject buf, jboolean db,
|
|
|
|
void *bufBase, int baseType)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2014-03-01 19:54:36 +00:00
|
|
|
if(!db && buf)
|
2013-09-26 21:44:39 +00:00
|
|
|
releaseArrayPtr(env, buf, bufBase, baseType, JNI_ABORT);
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-29 10:36:09 +00:00
|
|
|
void* ompi_java_getDirectBufferAddress(JNIEnv *env, jobject buf)
|
|
|
|
{
|
|
|
|
/* Allow NULL buffers to send/recv 0 items as control messages. */
|
|
|
|
return buf == NULL ? NULL : (*env)->GetDirectBufferAddress(env, buf);
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
/* `getArrayCritical' is used in
|
|
|
|
getMPIBuf, releaseMPIBuf...
|
|
|
|
for getting pointer from `jobject buf'
|
|
|
|
*/
|
|
|
|
static void* getArrayCritical(void** bufBase, JNIEnv *env,
|
|
|
|
jobject buf, int baseType, int offset)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2013-09-26 21:44:39 +00:00
|
|
|
*bufBase = (jbyte*)(*env)->GetPrimitiveArrayCritical(env, buf, NULL);
|
|
|
|
|
|
|
|
switch(baseType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return NULL;
|
|
|
|
case 1:
|
|
|
|
return ((jbyte*)*bufBase) + offset;
|
|
|
|
case 2:
|
|
|
|
return ((jchar*)*bufBase) + offset;
|
|
|
|
case 3:
|
|
|
|
return ((jshort*)*bufBase) + offset;
|
|
|
|
case 4:
|
|
|
|
return ((jboolean*)*bufBase) + offset;
|
|
|
|
case 5:
|
|
|
|
return ((jint*)*bufBase) + offset;
|
|
|
|
case 6:
|
|
|
|
return ((jlong*)*bufBase) + offset;
|
|
|
|
case 7:
|
|
|
|
return ((jfloat*)*bufBase) + offset;
|
|
|
|
case 8:
|
|
|
|
return ((jdouble*)*bufBase) + offset;
|
|
|
|
case 9:
|
|
|
|
return ((jbyte*)*bufBase) + offset;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2014-02-16 22:58:01 +00:00
|
|
|
static void* getBufCritical(
|
|
|
|
void** bufBase, JNIEnv *env,
|
|
|
|
jobject buf, jboolean db, int baseType, int offset)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2014-02-16 22:58:01 +00:00
|
|
|
if(buf == NULL)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2014-02-16 22:58:01 +00:00
|
|
|
/* Allow NULL buffers to send/recv 0 items as control messages. */
|
|
|
|
*bufBase = NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else if(db)
|
|
|
|
{
|
|
|
|
*bufBase = (*env)->GetDirectBufferAddress(env, buf);
|
2013-09-26 21:44:39 +00:00
|
|
|
assert(offset == 0);
|
|
|
|
return *bufBase;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return getArrayCritical(bufBase, env, buf, baseType, offset);
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2014-02-16 22:58:01 +00:00
|
|
|
static void releaseBufCritical(
|
|
|
|
JNIEnv *env, jobject buf, jboolean db, void* bufBase)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2014-03-01 19:54:36 +00:00
|
|
|
if(!db && buf)
|
2013-09-26 21:44:39 +00:00
|
|
|
(*env)->ReleasePrimitiveArrayCritical(env, buf, bufBase, 0);
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
static int isInter(JNIEnv *env, MPI_Comm comm)
|
|
|
|
{
|
|
|
|
int rc, flag;
|
|
|
|
rc = MPI_Comm_test_inter(comm, &flag);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return flag;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_init(JNIEnv *env, jclass clazz)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2013-09-26 21:44:39 +00:00
|
|
|
jfieldID nullHandleID = (*env)->GetStaticFieldID(
|
|
|
|
env, clazz, "nullHandle", "J");
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
(*env)->SetStaticLongField(env, clazz, nullHandleID, (jlong)MPI_COMM_NULL);
|
|
|
|
ompi_java.CommHandle = (*env)->GetFieldID(env,clazz,"handle","J");
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_getComm(JNIEnv *env, jobject jthis,
|
2012-02-20 22:12:43 +00:00
|
|
|
jint type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case 0:
|
2013-09-26 21:44:39 +00:00
|
|
|
(*env)->SetLongField(env,jthis, ompi_java.CommHandle,(jlong)MPI_COMM_NULL);
|
2012-02-20 22:12:43 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2013-09-26 21:44:39 +00:00
|
|
|
(*env)->SetLongField(env,jthis, ompi_java.CommHandle,(jlong)MPI_COMM_SELF);
|
2012-02-20 22:12:43 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2013-09-26 21:44:39 +00:00
|
|
|
(*env)->SetLongField(env,jthis, ompi_java.CommHandle,(jlong)MPI_COMM_WORLD);
|
2012-02-20 22:12:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_dup(JNIEnv *env, jobject jthis)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2013-09-26 21:44:39 +00:00
|
|
|
MPI_Comm comm, newcomm;
|
|
|
|
comm = (MPI_Comm)(*env)->GetLongField(env, jthis, ompi_java.CommHandle);
|
|
|
|
int rc = MPI_Comm_dup(comm, &newcomm);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return (jlong)newcomm;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jint JNICALL Java_mpi_Comm_getSize(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm)
|
|
|
|
{
|
|
|
|
int rc, size;
|
|
|
|
rc = MPI_Comm_size((MPI_Comm)comm, &size);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2012-02-20 22:12:43 +00:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jint JNICALL Java_mpi_Comm_getRank(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc, rank;
|
|
|
|
rc = MPI_Comm_rank((MPI_Comm)comm, &rank);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2012-02-20 22:12:43 +00:00
|
|
|
return rank;
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jint JNICALL Java_mpi_Comm_compare(
|
|
|
|
JNIEnv *env, jclass jthis, jlong comm1, jlong comm2)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc, result;
|
|
|
|
rc = MPI_Comm_compare((MPI_Comm)comm1, (MPI_Comm)comm2, &result);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return result;
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_free(
|
|
|
|
JNIEnv *env, jobject jthis, jlong handle)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2013-09-26 21:44:39 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)handle;
|
|
|
|
int rc = MPI_Comm_free(&comm);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return (jlong)comm;
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_disconnect(
|
|
|
|
JNIEnv *env, jobject jthis, jlong handle)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2013-09-26 21:44:39 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)handle;
|
|
|
|
int rc = MPI_Comm_disconnect(&comm);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return (jlong)comm;
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jboolean JNICALL Java_mpi_Comm_isNull(JNIEnv *env, jobject jthis)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2013-09-26 21:44:39 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)((*env)->GetLongField(
|
|
|
|
env, jthis, ompi_java.CommHandle));
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
return comm == MPI_COMM_NULL ? JNI_TRUE : JNI_FALSE;
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_getGroup(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
|
|
|
MPI_Group group;
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Comm_group((MPI_Comm)comm, &group);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2012-02-20 22:12:43 +00:00
|
|
|
return (jlong)group;
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jboolean JNICALL Java_mpi_Comm_isInter(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2013-09-26 21:44:39 +00:00
|
|
|
return isInter(env, (MPI_Comm)comm) ? JNI_TRUE : JNI_FALSE;
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_createIntercomm(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm, jlong localComm,
|
|
|
|
jint localLeader, jint remoteLeader, jint tag)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
|
|
|
MPI_Comm newintercomm;
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Intercomm_create(
|
|
|
|
(MPI_Comm)localComm, localLeader,
|
|
|
|
(MPI_Comm)comm, remoteLeader, tag, &newintercomm);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2012-02-20 22:12:43 +00:00
|
|
|
return (jlong)newintercomm;
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_send(
|
2014-02-16 22:58:01 +00:00
|
|
|
JNIEnv *env, jobject jthis, jlong jComm,
|
|
|
|
jobject buf, jboolean db, jint offset, jint count,
|
|
|
|
jlong jType, jint baseType, jint dest, jint tag)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2014-02-15 19:22:55 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)jComm;
|
|
|
|
MPI_Datatype type = (MPI_Datatype)jType;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
void *bufPtr, *bufBase;
|
2014-02-16 22:58:01 +00:00
|
|
|
bufPtr = ompi_java_getBufPtr(&bufBase, env, buf, db, baseType, offset);
|
2014-02-15 19:22:55 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Send(bufPtr, count, type, dest, tag, comm);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseReadBufPtr(env, buf, db, bufBase, baseType);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_recv(
|
2014-02-15 19:22:55 +00:00
|
|
|
JNIEnv *env, jobject jthis, jlong jComm,
|
2014-02-16 22:58:01 +00:00
|
|
|
jobject buf, jboolean db, jint offset, jint count,
|
|
|
|
jlong jType, jint baseType,
|
2014-03-01 19:54:36 +00:00
|
|
|
jint source, jint tag, jlongArray jStatus)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2014-02-15 19:22:55 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)jComm;
|
|
|
|
MPI_Datatype type = (MPI_Datatype)jType;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
void *bufPtr, *bufBase;
|
2014-02-16 22:58:01 +00:00
|
|
|
bufPtr = ompi_java_getBufPtr(&bufBase, env, buf, db, baseType, offset);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
MPI_Status status;
|
|
|
|
int rc = MPI_Recv(bufPtr, count, type, source, tag, comm, &status);
|
2014-02-15 19:22:55 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseBufPtr(env, buf, db, bufBase, baseType);
|
2014-03-01 19:54:36 +00:00
|
|
|
ompi_java_status_set(env, jStatus, &status);
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_sendRecv(
|
2014-02-15 19:22:55 +00:00
|
|
|
JNIEnv *env, jobject jthis, jlong jComm,
|
2014-02-16 22:58:01 +00:00
|
|
|
jobject sBuf, jboolean sdb, jint sOffset, jint sCount,
|
2014-02-15 19:22:55 +00:00
|
|
|
jlong sjType, jint sBaseType, jint dest, jint sTag,
|
2014-02-16 22:58:01 +00:00
|
|
|
jobject rBuf, jboolean rdb, jint rOffset, jint rCount,
|
2014-03-01 19:54:36 +00:00
|
|
|
jlong rjType, jint rBaseType, jint source, jint rTag,
|
|
|
|
jlongArray jStatus)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2014-02-15 19:22:55 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)jComm;
|
|
|
|
MPI_Datatype sType = (MPI_Datatype)sjType;
|
|
|
|
MPI_Datatype rType = (MPI_Datatype)rjType;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
void *sBufPtr, *sBufBase,
|
|
|
|
*rBufPtr, *rBufBase;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2014-02-16 22:58:01 +00:00
|
|
|
sBufPtr = ompi_java_getBufPtr(&sBufBase, env, sBuf, sdb, sBaseType, sOffset);
|
|
|
|
rBufPtr = ompi_java_getBufPtr(&rBufBase, env, rBuf, rdb, rBaseType, rOffset);
|
2013-09-29 10:36:09 +00:00
|
|
|
MPI_Status status;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Sendrecv(sBufPtr, sCount, sType, dest, sTag,
|
|
|
|
rBufPtr, rCount, rType, source, rTag,
|
|
|
|
comm, &status);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseReadBufPtr(env, sBuf, sdb, sBufBase, sBaseType);
|
|
|
|
ompi_java_releaseBufPtr(env, rBuf, rdb, rBufBase, rBaseType);
|
2014-03-01 19:54:36 +00:00
|
|
|
ompi_java_status_set(env, jStatus, &status);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_sendRecvReplace(
|
2014-02-15 19:22:55 +00:00
|
|
|
JNIEnv *env, jobject jthis, jlong jComm,
|
2014-02-16 22:58:01 +00:00
|
|
|
jobject buf, jboolean db, jint offset,
|
|
|
|
jint count, jlong jType, jint baseType,
|
2014-03-01 19:54:36 +00:00
|
|
|
jint dest, jint sTag, jint source, jint rTag, jlongArray jStatus)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2014-02-15 19:22:55 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)jComm;
|
|
|
|
MPI_Datatype type = (MPI_Datatype)jType;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
MPI_Status status;
|
|
|
|
void *bufPtr, *bufBase;
|
2014-02-16 22:58:01 +00:00
|
|
|
bufPtr = ompi_java_getBufPtr(&bufBase, env, buf, db, baseType, offset);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Sendrecv_replace(bufPtr, count, type, dest,
|
|
|
|
sTag, source, rTag, comm, &status);
|
|
|
|
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseBufPtr(env, buf, db, bufBase, baseType);
|
2014-03-01 19:54:36 +00:00
|
|
|
ompi_java_status_set(env, jStatus, &status);
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_bSend(
|
2014-02-16 22:58:01 +00:00
|
|
|
JNIEnv *env, jobject jthis, jlong jComm,
|
|
|
|
jobject buf, jboolean db, jint offset,
|
2014-02-15 19:22:55 +00:00
|
|
|
jint count, jlong jType, jint baseType, jint dest, jint tag)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2014-02-15 19:22:55 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)jComm;
|
|
|
|
MPI_Datatype type = (MPI_Datatype)jType;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
void *bufPtr, *bufBase;
|
2014-02-16 22:58:01 +00:00
|
|
|
bufPtr = ompi_java_getBufPtr(&bufBase, env, buf, db, baseType, offset);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Bsend(bufPtr, count, type, dest, tag, comm);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseReadBufPtr(env, buf, db, bufBase, baseType);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_sSend(
|
2014-02-16 22:58:01 +00:00
|
|
|
JNIEnv *env, jobject jthis, jlong jComm,
|
|
|
|
jobject buf, jboolean db, jint offset,
|
2014-02-15 19:22:55 +00:00
|
|
|
jint count, jlong jType, jint baseType, jint dest, jint tag)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2014-02-15 19:22:55 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)jComm;
|
|
|
|
MPI_Datatype type = (MPI_Datatype)jType;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
void *bufPtr, *bufBase;
|
2014-02-16 22:58:01 +00:00
|
|
|
bufPtr = ompi_java_getBufPtr(&bufBase, env, buf, db, baseType, offset);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Ssend(bufPtr, count, type, dest, tag, comm);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseReadBufPtr(env, buf, db, bufBase, baseType);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_rSend(
|
2014-02-16 22:58:01 +00:00
|
|
|
JNIEnv *env, jobject jthis, jlong jComm,
|
|
|
|
jobject buf, jboolean db, jint offset,
|
2014-02-15 19:22:55 +00:00
|
|
|
jint count, jlong jType, jint baseType, jint dest, jint tag)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2014-02-15 19:22:55 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)jComm;
|
|
|
|
MPI_Datatype type = (MPI_Datatype)jType;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
void *bufPtr, *bufBase;
|
2014-02-16 22:58:01 +00:00
|
|
|
bufPtr = ompi_java_getBufPtr(&bufBase, env, buf, db, baseType, offset);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Rsend(bufPtr, count, type, dest, tag, comm);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseReadBufPtr(env, buf, db, bufBase, baseType);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_iSend(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
|
|
|
jobject buf, jint count, jlong type, jint dest, jint tag)
|
|
|
|
{
|
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;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Isend(ptr, count, (MPI_Datatype)type,
|
|
|
|
dest, tag, (MPI_Comm)comm, &request);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return (jlong)request;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_ibSend(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
|
|
|
jobject buf, jint count, jlong type, jint dest, jint tag)
|
|
|
|
{
|
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_Ibsend(ptr, count, (MPI_Datatype)type,
|
|
|
|
dest, tag, (MPI_Comm)comm, &request);
|
|
|
|
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return (jlong)request;
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_isSend(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
|
|
|
jobject buf, jint count, jlong type, jint dest, jint tag)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
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;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Issend(ptr, count, (MPI_Datatype)type,
|
|
|
|
dest, tag, (MPI_Comm)comm, &request);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return (jlong)request;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_irSend(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
|
|
|
jobject buf, jint count, jlong type, jint dest, jint tag)
|
|
|
|
{
|
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;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Irsend(ptr, count, (MPI_Datatype)type,
|
|
|
|
dest, tag, (MPI_Comm)comm, &request);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return (jlong)request;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_iRecv(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
|
|
|
jobject buf, jint count, jlong type, jint source, jint tag)
|
|
|
|
{
|
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;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Irecv(ptr, count, (MPI_Datatype)type,
|
|
|
|
source, tag, (MPI_Comm)comm, &request);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return (jlong)request;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_sendInit(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
|
|
|
jobject buf, jint count, jlong type, jint dest, jint tag)
|
|
|
|
{
|
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;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Send_init(ptr, count, (MPI_Datatype)type,
|
|
|
|
dest, tag, (MPI_Comm)comm, &request);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return (jlong)request;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_bSendInit(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
|
|
|
jobject buf, jint count, jlong type, jint dest, jint tag)
|
|
|
|
{
|
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;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Bsend_init(ptr, count, (MPI_Datatype)type,
|
|
|
|
dest, tag, (MPI_Comm)comm, &request);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return (jlong)request;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_sSendInit(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
|
|
|
jobject buf, jint count, jlong type, jint dest, jint tag)
|
|
|
|
{
|
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;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Ssend_init(ptr, count, (MPI_Datatype)type,
|
|
|
|
dest, tag, (MPI_Comm)comm, &request);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return (jlong)request;
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_rSendInit(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
|
|
|
jobject buf, jint count, jlong type, jint dest, jint tag)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
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_Rsend_init(ptr, count, (MPI_Datatype)type,
|
|
|
|
dest, tag, (MPI_Comm)comm, &request);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return (jlong)request;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_recvInit(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
|
|
|
jobject buf, jint count, jlong type, jint source, jint tag)
|
|
|
|
{
|
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;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Recv_init(ptr, count, (MPI_Datatype)type,
|
|
|
|
source, tag, (MPI_Comm)comm, &request);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return (jlong)request;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jint JNICALL Java_mpi_Comm_pack(
|
2014-02-16 22:58:01 +00:00
|
|
|
JNIEnv *env, jobject jthis, jlong jComm,
|
|
|
|
jobject inBuf, jboolean indb, jint offset,
|
2014-02-15 19:22:55 +00:00
|
|
|
jint inCount, jlong jType, jint bType, jbyteArray outBuf, jint position)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2014-02-15 19:22:55 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)jComm;
|
|
|
|
MPI_Datatype type = (MPI_Datatype)jType;
|
|
|
|
int outSize = (*env)->GetArrayLength(env, outBuf);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
void *oBufPtr, *iBufPtr, *iBufBase;
|
|
|
|
oBufPtr = (*env)->GetPrimitiveArrayCritical(env, outBuf, NULL);
|
2014-02-16 22:58:01 +00:00
|
|
|
iBufPtr = getBufCritical(&iBufBase, env, inBuf, indb, bType, offset);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(inCount != 0 && outSize != position)
|
|
|
|
{
|
|
|
|
/* LAM doesn't like count = 0 */
|
|
|
|
int rc = MPI_Pack(iBufPtr, inCount, type,
|
|
|
|
oBufPtr, outSize, &position, comm);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2014-02-16 22:58:01 +00:00
|
|
|
releaseBufCritical(env, inBuf, indb, iBufBase);
|
2013-09-26 21:44:39 +00:00
|
|
|
(*env)->ReleasePrimitiveArrayCritical(env, outBuf, oBufPtr, 0);
|
|
|
|
return position;
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jint JNICALL Java_mpi_Comm_unpack(
|
2014-02-15 19:22:55 +00:00
|
|
|
JNIEnv *env, jobject jthis, jlong jComm,
|
2014-02-16 22:58:01 +00:00
|
|
|
jbyteArray inBuf, jint position, jobject outBuf, jboolean outdb,
|
2014-02-15 19:22:55 +00:00
|
|
|
jint offset, jint outCount, jlong jType, jint bType)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2014-02-15 19:22:55 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)jComm;
|
|
|
|
MPI_Datatype type = (MPI_Datatype)jType;
|
|
|
|
int inSize = (*env)->GetArrayLength(env, inBuf);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
void *iBufPtr, *oBufPtr, *oBufBase;
|
|
|
|
iBufPtr = (*env)->GetPrimitiveArrayCritical(env, inBuf, NULL);
|
2014-02-16 22:58:01 +00:00
|
|
|
oBufPtr = getBufCritical(&oBufBase, env, outBuf, outdb, bType, offset);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Unpack(iBufPtr, inSize, &position,
|
|
|
|
oBufPtr, outCount, type, comm);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
(*env)->ReleasePrimitiveArrayCritical(env, inBuf, iBufPtr, 0);
|
2014-02-16 22:58:01 +00:00
|
|
|
releaseBufCritical(env, outBuf, outdb, oBufBase);
|
2013-09-26 21:44:39 +00:00
|
|
|
return position;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jint JNICALL Java_mpi_Comm_packSize(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm, jint incount, jlong type)
|
|
|
|
{
|
|
|
|
int rc, size;
|
|
|
|
rc = MPI_Pack_size(incount, (MPI_Datatype)type, (MPI_Comm)comm, &size);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return size;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2014-02-23 20:08:53 +00:00
|
|
|
JNIEXPORT jboolean JNICALL Java_mpi_Comm_iProbe(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
2014-03-01 19:54:36 +00:00
|
|
|
jint source, jint tag, jlongArray jStatus)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
|
|
|
int flag;
|
|
|
|
MPI_Status status;
|
|
|
|
int rc = MPI_Iprobe(source, tag, (MPI_Comm)comm, &flag, &status);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2014-02-23 20:08:53 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(flag == 0)
|
2014-02-23 20:08:53 +00:00
|
|
|
return JNI_FALSE;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2014-03-01 19:54:36 +00:00
|
|
|
ompi_java_status_set(env, jStatus, &status);
|
2014-02-23 20:08:53 +00:00
|
|
|
return JNI_TRUE;
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_probe(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
2014-03-01 19:54:36 +00:00
|
|
|
jint source, jint tag, jlongArray jStatus)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
|
|
|
MPI_Status status;
|
|
|
|
int rc = MPI_Probe(source, tag, (MPI_Comm)comm, &status);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2014-03-01 19:54:36 +00:00
|
|
|
ompi_java_status_set(env, jStatus, &status);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jint JNICALL Java_mpi_Comm_getTopology(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm)
|
|
|
|
{
|
|
|
|
int rc, status;
|
|
|
|
rc = MPI_Topo_test((MPI_Comm)comm, &status);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return status;
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_abort(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm, jint errorcode)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Abort((MPI_Comm)comm, errorcode);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_setErrhandler(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm, jlong errhandler)
|
|
|
|
{
|
|
|
|
int rc = MPI_Errhandler_set((MPI_Comm)comm, (MPI_Errhandler)errhandler);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_getErrhandler(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm)
|
|
|
|
{
|
|
|
|
MPI_Errhandler errhandler;
|
|
|
|
int rc = MPI_Errhandler_get((MPI_Comm)comm, &errhandler);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return (jlong)errhandler;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
static int commCopyAttr(MPI_Comm oldcomm, int keyval, void *extraState,
|
|
|
|
void *attrValIn, void *attrValOut, int *flag)
|
|
|
|
{
|
|
|
|
return ompi_java_attrCopy(attrValIn, attrValOut, flag);
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
static int commDeleteAttr(MPI_Comm oldcomm, int keyval,
|
|
|
|
void *attrVal, void *extraState)
|
|
|
|
{
|
|
|
|
return ompi_java_attrDelete(attrVal);
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jint JNICALL Java_mpi_Comm_createKeyval_1jni(
|
|
|
|
JNIEnv *env, jclass clazz)
|
|
|
|
{
|
|
|
|
int rc, keyval;
|
|
|
|
rc = MPI_Comm_create_keyval(commCopyAttr, commDeleteAttr, &keyval, NULL);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return keyval;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_freeKeyval_1jni(
|
|
|
|
JNIEnv *env, jclass clazz, jint keyval)
|
|
|
|
{
|
|
|
|
int rc = MPI_Comm_free_keyval((int*)(&keyval));
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_setAttr(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm, jint keyval, jbyteArray jval)
|
|
|
|
{
|
|
|
|
void *cval = ompi_java_attrSet(env, jval);
|
|
|
|
int rc = MPI_Comm_set_attr((MPI_Comm)comm, keyval, cval);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jobject JNICALL Java_mpi_Comm_getAttr_1predefined(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm, jint keyval)
|
|
|
|
{
|
|
|
|
int flag, *val;
|
|
|
|
int rc = MPI_Comm_get_attr((MPI_Comm)comm, keyval, &val, &flag);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(ompi_java_exceptionCheck(env, rc) || !flag)
|
|
|
|
return NULL;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
return ompi_java_Integer_valueOf(env, (jint)(*val));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jbyteArray JNICALL Java_mpi_Comm_getAttr(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm, jint keyval)
|
|
|
|
{
|
|
|
|
int flag;
|
|
|
|
void *cval;
|
|
|
|
int rc = MPI_Comm_get_attr((MPI_Comm)comm, keyval, &cval, &flag);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(ompi_java_exceptionCheck(env, rc) || !flag)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return ompi_java_attrGet(env, cval);
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_deleteAttr(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm, jint keyval)
|
|
|
|
{
|
|
|
|
int rc = MPI_Comm_delete_attr((MPI_Comm)comm, keyval);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_barrier(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm)
|
|
|
|
{
|
|
|
|
int rc = MPI_Barrier((MPI_Comm)comm);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_iBarrier(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
|
|
|
MPI_Request request;
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Ibarrier((MPI_Comm)comm, &request);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return (jlong)request;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_bcast(
|
2014-02-16 22:58:01 +00:00
|
|
|
JNIEnv *env, jobject jthis, jlong jComm, jobject buf, jboolean db,
|
2014-02-15 19:22:55 +00:00
|
|
|
jint offset, jint count, jlong jType, jint baseType, jint root)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2014-02-15 19:22:55 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)jComm;
|
|
|
|
MPI_Datatype type = (MPI_Datatype)jType;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
void *bufPtr, *bufBase;
|
2014-02-16 22:58:01 +00:00
|
|
|
bufPtr = ompi_java_getBufPtr(&bufBase, env, buf, db, baseType, offset);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2014-02-15 19:22:55 +00:00
|
|
|
int rc = MPI_Bcast(bufPtr, count, type, root, comm);
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseBufPtr(env, buf, db, bufBase, baseType);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_iBcast(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
|
|
|
jobject buf, jint count, jlong type, jint root)
|
|
|
|
{
|
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;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Ibcast(ptr, count, (MPI_Datatype)type,
|
|
|
|
root, (MPI_Comm)comm, &request);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return (jlong)request;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_gather(
|
2014-02-15 19:22:55 +00:00
|
|
|
JNIEnv *env, jobject jthis, jlong jComm,
|
2014-02-16 22:58:01 +00:00
|
|
|
jobject sendBuf, jboolean sdb, jint sOffset, jint sCount,
|
2014-02-15 19:22:55 +00:00
|
|
|
jlong sjType, jint sBType,
|
2014-02-16 22:58:01 +00:00
|
|
|
jobject recvBuf, jboolean rdb, jint rOffset, jint rCount,
|
2014-02-15 19:22:55 +00:00
|
|
|
jlong rjType, jint rBType, jint root)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2014-02-15 19:22:55 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)jComm;
|
2013-09-26 21:44:39 +00:00
|
|
|
int id;
|
|
|
|
int rc = MPI_Comm_rank(comm, &id);
|
|
|
|
int rootOrInter = id == root || isInter(env, comm);
|
|
|
|
|
|
|
|
if(ompi_java_exceptionCheck(env, rc))
|
|
|
|
return;
|
|
|
|
|
|
|
|
void *sPtr, *sBase, *rPtr = NULL, *rBase;
|
|
|
|
MPI_Datatype sType;
|
|
|
|
|
2014-02-15 19:22:55 +00:00
|
|
|
if(sjType == 0)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2013-09-29 10:36:09 +00:00
|
|
|
assert(sendBuf == NULL);
|
2014-02-15 19:22:55 +00:00
|
|
|
sType = MPI_DATATYPE_NULL;
|
|
|
|
sPtr = MPI_IN_PLACE;
|
|
|
|
sBase = NULL;
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-15 19:22:55 +00:00
|
|
|
sType = (MPI_Datatype)sjType;
|
2014-02-16 22:58:01 +00:00
|
|
|
sPtr = ompi_java_getBufPtr(&sBase, env, sendBuf, sdb, sBType, sOffset);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2014-02-15 19:22:55 +00:00
|
|
|
MPI_Datatype rType = (MPI_Datatype)rjType;
|
2013-09-26 21:44:39 +00:00
|
|
|
|
2013-09-29 10:36:09 +00:00
|
|
|
if(rootOrInter || sPtr == MPI_IN_PLACE)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* In principle need the "id == root" check here and elsewere for
|
|
|
|
* correctness, in case arguments that are not supposed to be
|
|
|
|
* significant except on root are legitimately passed in as `null',
|
|
|
|
* say. Shouldn't produce null pointer exception.
|
|
|
|
*
|
|
|
|
* (However in this case MPICH complains if `mpi_rtype' is not defined
|
|
|
|
* in all processes, notwithstanding what the spec says.)
|
|
|
|
*/
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2014-02-16 22:58:01 +00:00
|
|
|
rPtr = ompi_java_getBufPtr(&rBase, env, recvBuf, rdb, rBType, rOffset);
|
2013-09-26 21:44:39 +00:00
|
|
|
|
|
|
|
if(!rootOrInter)
|
|
|
|
{
|
|
|
|
/* The receive buffer is ignored for all non-root processes.
|
|
|
|
* As we are using MPI_IN_PLACE version, we use the receive
|
|
|
|
* buffer as the send buffer.
|
|
|
|
*/
|
|
|
|
assert(sendBuf == NULL);
|
|
|
|
sPtr = rPtr;
|
|
|
|
sCount = rCount;
|
|
|
|
sType = rType;
|
|
|
|
}
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
rc = MPI_Gather(sPtr, sCount, sType, rPtr, rCount, rType, root, comm);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
|
|
|
|
if(rootOrInter || sendBuf == NULL)
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseBufPtr(env, recvBuf, rdb, rBase, rBType);
|
2013-09-26 21:44:39 +00:00
|
|
|
|
|
|
|
if(sendBuf != NULL)
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseReadBufPtr(env, sendBuf, sdb, sBase, sBType);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_iGather(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
|
|
|
jobject sendBuf, jint sCount, jlong sType,
|
|
|
|
jobject recvBuf, jint rCount, jlong rType, jint root)
|
|
|
|
{
|
|
|
|
int id;
|
|
|
|
int rc = MPI_Comm_rank((MPI_Comm)comm, &id);
|
|
|
|
int rootOrInter = id == root || isInter(env, (MPI_Comm)comm);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(ompi_java_exceptionCheck(env, rc))
|
|
|
|
return (jlong)MPI_REQUEST_NULL;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
MPI_Request request;
|
|
|
|
void *sPtr, *rPtr = NULL;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-29 10:36:09 +00:00
|
|
|
if(sType == 0)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2013-09-29 10:36:09 +00:00
|
|
|
assert(sendBuf == NULL);
|
2013-09-26 21:44:39 +00:00
|
|
|
sType = (jlong)MPI_DATATYPE_NULL;
|
|
|
|
sPtr = MPI_IN_PLACE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-29 10:36:09 +00:00
|
|
|
sPtr = ompi_java_getDirectBufferAddress(env, sendBuf);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-29 10:36:09 +00:00
|
|
|
if(rootOrInter || sPtr == MPI_IN_PLACE)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* In principle need the "id == root" check here and elsewere for
|
|
|
|
* correctness, in case arguments that are not supposed to be
|
|
|
|
* significant except on root are legitimately passed in as `null',
|
|
|
|
* say. Shouldn't produce null pointer exception.
|
|
|
|
*
|
|
|
|
* (However in this case MPICH complains if `mpi_rtype' is not defined
|
|
|
|
* in all processes, notwithstanding what the spec says.)
|
|
|
|
*/
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-29 10:36:09 +00:00
|
|
|
rPtr = ompi_java_getDirectBufferAddress(env, recvBuf);
|
2013-09-26 21:44:39 +00:00
|
|
|
|
|
|
|
if(!rootOrInter)
|
|
|
|
{
|
|
|
|
/* The receive buffer is ignored for all non-root processes.
|
|
|
|
* As we are using MPI_IN_PLACE version, we use the receive
|
|
|
|
* buffer as the send buffer.
|
|
|
|
*/
|
|
|
|
assert(sendBuf == NULL);
|
|
|
|
sPtr = rPtr;
|
|
|
|
sCount = rCount;
|
|
|
|
sType = rType;
|
|
|
|
}
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
rc = MPI_Igather(sPtr, sCount, (MPI_Datatype)sType,
|
|
|
|
rPtr, rCount, (MPI_Datatype)rType,
|
|
|
|
root, (MPI_Comm)comm, &request);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return (jlong)request;
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_gatherv(
|
2014-02-15 19:22:55 +00:00
|
|
|
JNIEnv *env, jobject jthis, jlong jComm,
|
2014-02-16 22:58:01 +00:00
|
|
|
jobject sendBuf, jboolean sdb, jint sOffset,
|
|
|
|
jint sCount, jlong sjType, jint sBType,
|
|
|
|
jobject recvBuf, jboolean rdb, jint rOffset, jintArray rCounts,
|
2014-02-15 19:22:55 +00:00
|
|
|
jintArray displs, jlong rjType, jint rBType, jint root)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2014-02-15 19:22:55 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)jComm;
|
2013-09-26 21:44:39 +00:00
|
|
|
int id;
|
|
|
|
int rc = MPI_Comm_rank(comm, &id);
|
|
|
|
int rootOrInter = id == root || isInter(env, comm);
|
|
|
|
|
|
|
|
if(ompi_java_exceptionCheck(env, rc))
|
|
|
|
return;
|
|
|
|
|
|
|
|
void *sPtr, *sBase, *rPtr = NULL, *rBase;
|
|
|
|
MPI_Datatype sType;
|
|
|
|
|
2014-02-15 19:22:55 +00:00
|
|
|
if(sjType == 0)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2013-09-29 10:36:09 +00:00
|
|
|
assert(sendBuf == NULL);
|
2014-02-15 19:22:55 +00:00
|
|
|
sType = MPI_DATATYPE_NULL;
|
|
|
|
sPtr = MPI_IN_PLACE;
|
|
|
|
sBase = NULL;
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-15 19:22:55 +00:00
|
|
|
sType = (MPI_Datatype)sjType;
|
2014-02-16 22:58:01 +00:00
|
|
|
sPtr = ompi_java_getBufPtr(&sBase, env, sendBuf, sdb, sBType, sOffset);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
jint *jRCounts = NULL, *jDispls = NULL;
|
|
|
|
int *cRCounts = NULL, *cDispls = NULL;
|
|
|
|
MPI_Datatype rType = sType;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(rootOrInter)
|
|
|
|
{
|
|
|
|
ompi_java_getIntArray(env, rCounts, &jRCounts, &cRCounts);
|
|
|
|
ompi_java_getIntArray(env, displs, &jDispls, &cDispls);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2014-02-15 19:22:55 +00:00
|
|
|
rType = (MPI_Datatype)rjType;
|
2014-02-16 22:58:01 +00:00
|
|
|
rPtr = ompi_java_getBufPtr(&rBase, env, recvBuf, rdb, rBType, rOffset);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
rc = MPI_Gatherv(sPtr, sCount, sType, rPtr, cRCounts,
|
|
|
|
cDispls, rType, root, comm);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(sendBuf != NULL)
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseReadBufPtr(env, sendBuf, sdb, sBase, sBType);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(rootOrInter)
|
|
|
|
{
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseBufPtr(env, recvBuf, rdb, rBase, rBType);
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_forgetIntArray(env, rCounts, jRCounts, cRCounts);
|
|
|
|
ompi_java_forgetIntArray(env, displs, jDispls, cDispls);
|
|
|
|
}
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_iGatherv(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
|
|
|
jobject sendBuf, jint sCount, jlong sType,
|
|
|
|
jobject recvBuf, jintArray rCounts,
|
|
|
|
jintArray displs, jlong rType, jint root)
|
|
|
|
{
|
|
|
|
int id;
|
|
|
|
int rc = MPI_Comm_rank((MPI_Comm)comm, &id);
|
|
|
|
int rootOrInter = id == root || isInter(env, (MPI_Comm)comm);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(ompi_java_exceptionCheck(env, rc))
|
|
|
|
return (jlong)MPI_REQUEST_NULL;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
MPI_Request request;
|
|
|
|
void *sPtr, *rPtr = NULL;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-29 10:36:09 +00:00
|
|
|
if(sType == 0)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2013-09-29 10:36:09 +00:00
|
|
|
assert(sendBuf == NULL);
|
2013-09-26 21:44:39 +00:00
|
|
|
sType = (jlong)MPI_DATATYPE_NULL;
|
|
|
|
sPtr = MPI_IN_PLACE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-29 10:36:09 +00:00
|
|
|
sPtr = ompi_java_getDirectBufferAddress(env, sendBuf);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
jint *jRCounts, *jDispls;
|
|
|
|
int *cRCounts, *cDispls;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(rootOrInter)
|
|
|
|
{
|
|
|
|
ompi_java_getIntArray(env, rCounts, &jRCounts, &cRCounts);
|
|
|
|
ompi_java_getIntArray(env, displs, &jDispls, &cDispls);
|
2013-09-29 10:36:09 +00:00
|
|
|
rPtr = ompi_java_getDirectBufferAddress(env, recvBuf);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
jRCounts = jDispls = NULL;
|
|
|
|
cRCounts = cDispls = NULL;
|
|
|
|
rType = sType;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
rc = MPI_Igatherv(sPtr, sCount, (MPI_Datatype)sType, rPtr,
|
|
|
|
cRCounts, cDispls, (MPI_Datatype)rType,
|
|
|
|
root, (MPI_Comm)comm, &request);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(rootOrInter)
|
|
|
|
{
|
|
|
|
ompi_java_forgetIntArray(env, rCounts, jRCounts, cRCounts);
|
|
|
|
ompi_java_forgetIntArray(env, displs, jDispls, cDispls);
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
return (jlong)request;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_scatter(
|
2014-02-15 19:22:55 +00:00
|
|
|
JNIEnv *env, jobject jthis, jlong jComm,
|
2014-02-16 22:58:01 +00:00
|
|
|
jobject sendBuf, jboolean sdb, jint sOffset, jint sCount,
|
2014-02-15 19:22:55 +00:00
|
|
|
jlong sjType, jint sBType,
|
2014-02-16 22:58:01 +00:00
|
|
|
jobject recvBuf, jboolean rdb, jint rOffset, jint rCount,
|
2014-02-15 19:22:55 +00:00
|
|
|
jlong rjType, jint rBType, jint root)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2014-02-15 19:22:55 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)jComm;
|
2013-09-26 21:44:39 +00:00
|
|
|
int id;
|
|
|
|
int rc = MPI_Comm_rank(comm, &id);
|
|
|
|
int rootOrInter = id == root || isInter(env, comm);
|
|
|
|
|
|
|
|
if(ompi_java_exceptionCheck(env, rc))
|
|
|
|
return;
|
|
|
|
|
|
|
|
void *sPtr = NULL, *sBase, *rPtr, *rBase;
|
|
|
|
MPI_Datatype sType, rType;
|
|
|
|
|
2014-02-15 19:22:55 +00:00
|
|
|
if(rjType == 0)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2013-09-29 10:36:09 +00:00
|
|
|
assert(recvBuf == NULL);
|
2014-02-15 19:22:55 +00:00
|
|
|
rType = MPI_DATATYPE_NULL;
|
|
|
|
rPtr = MPI_IN_PLACE;
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-15 19:22:55 +00:00
|
|
|
rType = (MPI_Datatype)rjType;
|
2014-02-16 22:58:01 +00:00
|
|
|
rPtr = ompi_java_getBufPtr(&rBase, env, recvBuf, rdb, rBType, rOffset);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
|
|
|
|
2014-02-15 19:22:55 +00:00
|
|
|
sType = (MPI_Datatype)sjType;
|
2013-09-26 21:44:39 +00:00
|
|
|
|
2013-09-29 10:36:09 +00:00
|
|
|
if(rootOrInter || rPtr == MPI_IN_PLACE)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2014-02-16 22:58:01 +00:00
|
|
|
sPtr = ompi_java_getBufPtr(&sBase, env, sendBuf, sdb, sBType, sOffset);
|
2013-09-26 21:44:39 +00:00
|
|
|
|
|
|
|
if(!rootOrInter)
|
|
|
|
{
|
|
|
|
/* The send buffer is ignored for all non-root processes.
|
|
|
|
* As we are using MPI_IN_PLACE version, we use the send
|
|
|
|
* buffer as the receive buffer.
|
|
|
|
*/
|
|
|
|
assert(recvBuf == NULL);
|
|
|
|
rPtr = sPtr;
|
|
|
|
rCount = sCount;
|
|
|
|
rType = sType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = MPI_Scatter(sPtr, sCount, sType, rPtr, rCount, rType, root, comm);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
|
|
|
|
if(rootOrInter || recvBuf == NULL)
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseBufPtr(env, sendBuf, sdb, sBase, sBType);
|
2013-09-26 21:44:39 +00:00
|
|
|
|
|
|
|
if(recvBuf != NULL)
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseBufPtr(env, recvBuf, rdb, rBase, rBType);
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_iScatter(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
|
|
|
jobject sendBuf, jint sCount, jlong sType,
|
|
|
|
jobject recvBuf, jint rCount, jlong rType, jint root)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2013-09-26 21:44:39 +00:00
|
|
|
int id;
|
|
|
|
int rc = MPI_Comm_rank((MPI_Comm)comm, &id);
|
|
|
|
int rootOrInter = id == root || isInter(env, (MPI_Comm)comm);
|
|
|
|
|
|
|
|
if(ompi_java_exceptionCheck(env, rc))
|
|
|
|
return (jlong)MPI_REQUEST_NULL;
|
|
|
|
|
|
|
|
void *sPtr = NULL, *rPtr;
|
2012-02-20 22:12:43 +00:00
|
|
|
MPI_Request request;
|
|
|
|
|
2013-09-29 10:36:09 +00:00
|
|
|
if(rType == 0)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2013-09-29 10:36:09 +00:00
|
|
|
assert(recvBuf == NULL);
|
2013-09-26 21:44:39 +00:00
|
|
|
rType = (jlong)MPI_DATATYPE_NULL;
|
|
|
|
rPtr = MPI_IN_PLACE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-29 10:36:09 +00:00
|
|
|
rPtr = ompi_java_getDirectBufferAddress(env, recvBuf);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
|
|
|
|
2013-09-29 10:36:09 +00:00
|
|
|
if(rootOrInter || rPtr == MPI_IN_PLACE)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2013-09-29 10:36:09 +00:00
|
|
|
sPtr = ompi_java_getDirectBufferAddress(env, sendBuf);
|
2013-09-26 21:44:39 +00:00
|
|
|
|
|
|
|
if(!rootOrInter)
|
|
|
|
{
|
|
|
|
/* The send buffer is ignored for all non-root processes.
|
|
|
|
* As we are using MPI_IN_PLACE version, we use the send
|
|
|
|
* buffer as the receive buffer.
|
|
|
|
*/
|
|
|
|
assert(recvBuf == NULL);
|
|
|
|
rPtr = sPtr;
|
|
|
|
rCount = sCount;
|
|
|
|
rType = sType;
|
|
|
|
}
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
rc = MPI_Iscatter(sPtr, sCount, (MPI_Datatype)sType,
|
|
|
|
rPtr, rCount, (MPI_Datatype)rType,
|
|
|
|
root, (MPI_Comm)comm, &request);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return (jlong)request;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_scatterv(
|
2014-02-16 18:51:14 +00:00
|
|
|
JNIEnv *env, jobject jthis, jlong jComm,
|
2014-02-16 22:58:01 +00:00
|
|
|
jobject sendBuf, jboolean sdb, jint sOffset, jintArray sCounts,
|
2014-02-16 18:51:14 +00:00
|
|
|
jintArray displs, jlong sjType, jint sBType,
|
2014-02-16 22:58:01 +00:00
|
|
|
jobject recvBuf, jboolean rdb, jint rOffset, jint rCount,
|
2014-02-16 18:51:14 +00:00
|
|
|
jlong rjType, jint rBType, jint root)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2014-02-16 18:51:14 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)jComm;
|
2013-09-26 21:44:39 +00:00
|
|
|
int id;
|
|
|
|
int rc = MPI_Comm_rank(comm, &id);
|
|
|
|
int rootOrInter = id == root || isInter(env, comm);
|
|
|
|
|
|
|
|
if(ompi_java_exceptionCheck(env, rc))
|
|
|
|
return;
|
|
|
|
|
|
|
|
void *sPtr = NULL, *sBase, *rPtr, *rBase;
|
|
|
|
MPI_Datatype rType;
|
|
|
|
|
2014-02-16 18:51:14 +00:00
|
|
|
if(rjType == 0)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2013-09-29 10:36:09 +00:00
|
|
|
assert(recvBuf == NULL);
|
2014-02-16 18:51:14 +00:00
|
|
|
rType = MPI_DATATYPE_NULL;
|
|
|
|
rPtr = MPI_IN_PLACE;
|
|
|
|
rBase = NULL;
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-16 18:51:14 +00:00
|
|
|
rType = (MPI_Datatype)rjType;
|
2014-02-16 22:58:01 +00:00
|
|
|
rPtr = ompi_java_getBufPtr(&rBase, env, recvBuf, rdb, rBType, rOffset);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
jint *jSCounts = NULL, *jDispls = NULL;
|
|
|
|
int *cSCounts = NULL, *cDispls = NULL;
|
|
|
|
MPI_Datatype sType = rType;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(rootOrInter)
|
|
|
|
{
|
|
|
|
ompi_java_getIntArray(env, sCounts, &jSCounts, &cSCounts);
|
|
|
|
ompi_java_getIntArray(env, displs, &jDispls, &cDispls);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2014-02-16 18:51:14 +00:00
|
|
|
sType = (MPI_Datatype)sjType;
|
2014-02-16 22:58:01 +00:00
|
|
|
sPtr = ompi_java_getBufPtr(&sBase, env, sendBuf, sdb, sBType, sOffset);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
rc = MPI_Scatterv(sPtr, cSCounts, cDispls, sType,
|
|
|
|
rPtr, rCount, rType, root, comm);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(recvBuf != NULL)
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseBufPtr(env, recvBuf, rdb, rBase, rBType);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(rootOrInter)
|
|
|
|
{
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseBufPtr(env, sendBuf, sdb, sBase, sBType);
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_forgetIntArray(env, sCounts, jSCounts, cSCounts);
|
|
|
|
ompi_java_forgetIntArray(env, displs, jDispls, cDispls);
|
|
|
|
}
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_iScatterv(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
|
|
|
jobject sendBuf, jintArray sCounts, jintArray displs, jlong sType,
|
|
|
|
jobject recvBuf, jint rCount, jlong rType, jint root)
|
|
|
|
{
|
|
|
|
int id;
|
|
|
|
int rc = MPI_Comm_rank((MPI_Comm)comm, &id);
|
|
|
|
int rootOrInter = id == root || isInter(env, (MPI_Comm)comm);
|
|
|
|
|
|
|
|
if(ompi_java_exceptionCheck(env, rc))
|
|
|
|
return (jlong)MPI_REQUEST_NULL;
|
|
|
|
|
|
|
|
MPI_Request request;
|
|
|
|
void *sPtr = NULL, *rPtr;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-29 10:36:09 +00:00
|
|
|
if(rType == 0)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2013-09-29 10:36:09 +00:00
|
|
|
assert(recvBuf == NULL);
|
2013-09-26 21:44:39 +00:00
|
|
|
rType = (jlong)MPI_DATATYPE_NULL;
|
|
|
|
rPtr = MPI_IN_PLACE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-29 10:36:09 +00:00
|
|
|
rPtr = ompi_java_getDirectBufferAddress(env, recvBuf);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
jint *jSCounts, *jDispls;
|
|
|
|
int *cSCounts, *cDispls;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(rootOrInter)
|
|
|
|
{
|
|
|
|
ompi_java_getIntArray(env, sCounts, &jSCounts, &cSCounts);
|
|
|
|
ompi_java_getIntArray(env, displs, &jDispls, &cDispls);
|
2013-09-29 10:36:09 +00:00
|
|
|
sPtr = ompi_java_getDirectBufferAddress(env, sendBuf);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
jSCounts = jDispls = NULL;
|
|
|
|
cSCounts = cDispls = NULL;
|
|
|
|
sType = rType;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
rc = MPI_Iscatterv(sPtr, cSCounts, cDispls, (MPI_Datatype)sType,
|
|
|
|
rPtr, rCount, (MPI_Datatype)rType, root,
|
|
|
|
(MPI_Comm)comm, &request);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(rootOrInter)
|
|
|
|
{
|
|
|
|
ompi_java_forgetIntArray(env, sCounts, jSCounts, cSCounts);
|
|
|
|
ompi_java_forgetIntArray(env, displs, jDispls, cDispls);
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
return (jlong)request;
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_allGather(
|
2014-02-16 18:51:14 +00:00
|
|
|
JNIEnv *env, jobject jthis, jlong jComm,
|
2014-02-16 22:58:01 +00:00
|
|
|
jobject sendBuf, jboolean sdb, jint sOffset,
|
|
|
|
jint sCount, jlong sjType, jint sBType,
|
|
|
|
jobject recvBuf, jboolean rdb, jint rOffset,
|
|
|
|
jint rCount, jlong rjType, jint rBType)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2014-02-16 18:51:14 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)jComm;
|
2013-09-26 21:44:39 +00:00
|
|
|
MPI_Datatype sType;
|
|
|
|
void *sPtr, *sBase, *rPtr, *rBase;
|
|
|
|
|
2014-02-16 18:51:14 +00:00
|
|
|
if(sjType == 0)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2013-09-29 10:36:09 +00:00
|
|
|
assert(sendBuf == NULL);
|
2014-02-16 18:51:14 +00:00
|
|
|
sType = MPI_DATATYPE_NULL;
|
|
|
|
sPtr = MPI_IN_PLACE;
|
|
|
|
sBase = NULL;
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-16 18:51:14 +00:00
|
|
|
sType = (MPI_Datatype)sjType;
|
2014-02-16 22:58:01 +00:00
|
|
|
sPtr = ompi_java_getBufPtr(&sBase, env, sendBuf, sdb, sBType, sOffset);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2014-02-16 18:51:14 +00:00
|
|
|
MPI_Datatype rType = (MPI_Datatype)rjType;
|
2014-02-16 22:58:01 +00:00
|
|
|
rPtr = ompi_java_getBufPtr(&rBase, env, recvBuf, rdb, rBType, rOffset);
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Allgather(sPtr, sCount, sType, rPtr, rCount, rType, comm);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseBufPtr(env, recvBuf, rdb, rBase, rBType);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(sendBuf != NULL)
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseReadBufPtr(env, sendBuf, sdb, sBase, sBType);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_iAllGather(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
|
|
|
jobject sendBuf, jint sCount, jlong sType,
|
|
|
|
jobject recvBuf, jint rCount, jlong rType)
|
|
|
|
{
|
|
|
|
void *sPtr, *rPtr;
|
|
|
|
MPI_Request request;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-29 10:36:09 +00:00
|
|
|
if(sType == 0)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2013-09-29 10:36:09 +00:00
|
|
|
assert(sendBuf == NULL);
|
2013-09-26 21:44:39 +00:00
|
|
|
sType = (jlong)MPI_DATATYPE_NULL;
|
|
|
|
sPtr = MPI_IN_PLACE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-29 10:36:09 +00:00
|
|
|
sPtr = ompi_java_getDirectBufferAddress(env, sendBuf);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
|
|
|
|
2013-09-29 10:36:09 +00:00
|
|
|
rPtr = ompi_java_getDirectBufferAddress(env, recvBuf);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Iallgather(sPtr, sCount, (MPI_Datatype)sType,
|
|
|
|
rPtr, rCount, (MPI_Datatype)rType,
|
|
|
|
(MPI_Comm)comm, &request);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return (jlong)request;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_allGatherv(
|
2014-02-16 18:51:14 +00:00
|
|
|
JNIEnv *env, jobject jthis, jlong jComm,
|
2014-02-16 22:58:01 +00:00
|
|
|
jobject sendBuf, jboolean sdb, jint sOffset,
|
|
|
|
jint sCount, jlong sjType, jint sBType,
|
|
|
|
jobject recvBuf, jboolean rdb, jint rOffset,
|
|
|
|
jintArray rCounts, jintArray displs, jlong rjType, jint rBType)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2014-02-16 18:51:14 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)jComm;
|
2013-09-26 21:44:39 +00:00
|
|
|
void *sPtr, *sBase, *rPtr, *rBase;
|
|
|
|
MPI_Datatype sType;
|
|
|
|
|
2014-02-16 18:51:14 +00:00
|
|
|
if(sjType == 0)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2013-09-29 10:36:09 +00:00
|
|
|
assert(sendBuf == NULL);
|
2014-02-16 18:51:14 +00:00
|
|
|
sType = MPI_DATATYPE_NULL;
|
|
|
|
sPtr = MPI_IN_PLACE;
|
|
|
|
sBase = NULL;
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-16 18:51:14 +00:00
|
|
|
sType = (MPI_Datatype)sjType;
|
2014-02-16 22:58:01 +00:00
|
|
|
sPtr = ompi_java_getBufPtr(&sBase, env, sendBuf, sdb, sBType, sOffset);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2014-02-16 18:51:14 +00:00
|
|
|
MPI_Datatype rType = (MPI_Datatype)rjType;
|
2013-09-26 21:44:39 +00:00
|
|
|
jint *jRCounts, *jDispls;
|
|
|
|
int *cRCounts, *cDispls;
|
|
|
|
ompi_java_getIntArray(env, rCounts, &jRCounts, &cRCounts);
|
|
|
|
ompi_java_getIntArray(env, displs, &jDispls, &cDispls);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2014-02-16 22:58:01 +00:00
|
|
|
rPtr = ompi_java_getBufPtr(&rBase, env, recvBuf, rdb, rBType, rOffset);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Allgatherv(sPtr, sCount, sType, rPtr,
|
|
|
|
cRCounts, cDispls, rType, comm);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseBufPtr(env, recvBuf, rdb, rBase, rBType);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(sendBuf != NULL)
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseReadBufPtr(env, sendBuf, sdb, sBase, sBType);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_forgetIntArray(env, rCounts, jRCounts, cRCounts);
|
|
|
|
ompi_java_forgetIntArray(env, displs, jDispls, cDispls);
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_iAllGatherv(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
|
|
|
jobject sendBuf, jint sCount, jlong sType,
|
|
|
|
jobject recvBuf, jintArray rCounts, jintArray displs, jlong rType)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
|
|
|
MPI_Request request;
|
2013-09-26 21:44:39 +00:00
|
|
|
void *sPtr, *rPtr;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-29 10:36:09 +00:00
|
|
|
if(sType == 0)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2013-09-29 10:36:09 +00:00
|
|
|
assert(sendBuf == NULL);
|
2013-09-26 21:44:39 +00:00
|
|
|
sType = (jlong)MPI_DATATYPE_NULL;
|
|
|
|
sPtr = MPI_IN_PLACE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-29 10:36:09 +00:00
|
|
|
sPtr = ompi_java_getDirectBufferAddress(env, sendBuf);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
jint *jRCounts, *jDispls;
|
|
|
|
int *cRCounts, *cDispls;
|
|
|
|
ompi_java_getIntArray(env, rCounts, &jRCounts, &cRCounts);
|
|
|
|
ompi_java_getIntArray(env, displs, &jDispls, &cDispls);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-29 10:36:09 +00:00
|
|
|
rPtr = ompi_java_getDirectBufferAddress(env, recvBuf);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Iallgatherv(sPtr, sCount, (MPI_Datatype)sType,
|
|
|
|
rPtr, cRCounts, cDispls, (MPI_Datatype)rType,
|
|
|
|
(MPI_Comm)comm, &request);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
ompi_java_forgetIntArray(env, rCounts, jRCounts, cRCounts);
|
|
|
|
ompi_java_forgetIntArray(env, displs, jDispls, cDispls);
|
|
|
|
return (jlong)request;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_allToAll(
|
2014-02-16 18:51:14 +00:00
|
|
|
JNIEnv *env, jobject jthis, jlong jComm,
|
2014-02-16 22:58:01 +00:00
|
|
|
jobject sendBuf, jboolean sdb, jint sOffset,
|
|
|
|
jint sCount, jlong sjType, jint sBType,
|
|
|
|
jobject recvBuf, jboolean rdb, jint rOffset,
|
|
|
|
jint rCount, jlong rjType, jint rBType)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2014-02-16 18:51:14 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)jComm;
|
|
|
|
MPI_Datatype sType = (MPI_Datatype)sjType;
|
|
|
|
MPI_Datatype rType = (MPI_Datatype)rjType;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
void *sPtr, *sBase, *rPtr, *rBase;
|
2014-02-16 22:58:01 +00:00
|
|
|
rPtr = ompi_java_getBufPtr(&rBase, env, recvBuf, rdb, rBType, rOffset);
|
|
|
|
sPtr = ompi_java_getBufPtr(&sBase, env, sendBuf, sdb, sBType, sOffset);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Alltoall(sPtr, sCount, sType, rPtr, rCount, rType, comm);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseReadBufPtr(env, sendBuf, sdb, sBase, sBType);
|
|
|
|
ompi_java_releaseBufPtr(env, recvBuf, rdb, rBase, rBType);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_iAllToAll(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
|
|
|
jobject sendBuf, jint sCount, jlong sType,
|
|
|
|
jobject recvBuf, jint rCount, jlong rType)
|
|
|
|
{
|
2013-09-29 10:36:09 +00:00
|
|
|
void *sPtr = ompi_java_getDirectBufferAddress(env, sendBuf),
|
|
|
|
*rPtr = ompi_java_getDirectBufferAddress(env, recvBuf);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
MPI_Request request;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Ialltoall(sPtr, sCount, (MPI_Datatype)sType,
|
|
|
|
rPtr, rCount, (MPI_Datatype)rType,
|
|
|
|
(MPI_Comm)comm, &request);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return (jlong)request;
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_allToAllv(
|
2014-02-16 18:51:14 +00:00
|
|
|
JNIEnv *env, jobject jthis, jlong jComm,
|
2014-02-16 22:58:01 +00:00
|
|
|
jobject sendBuf, jboolean sdb, jint sOffset, jintArray sCount,
|
2014-02-16 18:51:14 +00:00
|
|
|
jintArray sDispls, jlong sjType, jint sBType,
|
2014-02-16 22:58:01 +00:00
|
|
|
jobject recvBuf, jboolean rdb, jint rOffset, jintArray rCount,
|
2014-02-16 18:51:14 +00:00
|
|
|
jintArray rDispls, jlong rjType, jint rBType)
|
2013-09-26 21:44:39 +00:00
|
|
|
{
|
2014-02-16 18:51:14 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)jComm;
|
|
|
|
MPI_Datatype sType = (MPI_Datatype)sjType;
|
|
|
|
MPI_Datatype rType = (MPI_Datatype)rjType;
|
2013-09-26 21:44:39 +00:00
|
|
|
|
|
|
|
jint *jSCount, *jRCount, *jSDispls, *jRDispls;
|
|
|
|
int *cSCount, *cRCount, *cSDispls, *cRDispls;
|
|
|
|
ompi_java_getIntArray(env, sCount, &jSCount, &cSCount);
|
|
|
|
ompi_java_getIntArray(env, rCount, &jRCount, &cRCount);
|
|
|
|
ompi_java_getIntArray(env, sDispls, &jSDispls, &cSDispls);
|
|
|
|
ompi_java_getIntArray(env, rDispls, &jRDispls, &cRDispls);
|
|
|
|
|
|
|
|
void *sPtr, *sBase, *rPtr, *rBase;
|
2014-02-16 22:58:01 +00:00
|
|
|
rPtr = ompi_java_getBufPtr(&rBase, env, recvBuf, rdb, rBType, rOffset);
|
|
|
|
sPtr = ompi_java_getBufPtr(&sBase, env, sendBuf, sdb, sBType, sOffset);
|
2013-09-26 21:44:39 +00:00
|
|
|
|
|
|
|
int rc = MPI_Alltoallv(sPtr, cSCount, cSDispls, sType,
|
|
|
|
rPtr, cRCount, cRDispls, rType, comm);
|
|
|
|
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseReadBufPtr(env, sendBuf, sdb, sBase, sBType);
|
|
|
|
ompi_java_releaseBufPtr(env, recvBuf, rdb, rBase, rBType);
|
2013-09-26 21:44:39 +00:00
|
|
|
|
|
|
|
ompi_java_forgetIntArray(env, sCount, jSCount, cSCount);
|
|
|
|
ompi_java_forgetIntArray(env, rCount, jRCount, cRCount);
|
|
|
|
ompi_java_forgetIntArray(env, sDispls, jSDispls, cSDispls);
|
|
|
|
ompi_java_forgetIntArray(env, rDispls, jRDispls, cRDispls);
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_iAllToAllv(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
|
|
|
jobject sendBuf, jintArray sCount, jintArray sDispls, jlong sType,
|
|
|
|
jobject recvBuf, jintArray rCount, jintArray rDispls, jlong rType)
|
|
|
|
{
|
|
|
|
jint *jSCount, *jRCount, *jSDispls, *jRDispls;
|
|
|
|
int *cSCount, *cRCount, *cSDispls, *cRDispls;
|
|
|
|
ompi_java_getIntArray(env, sCount, &jSCount, &cSCount);
|
|
|
|
ompi_java_getIntArray(env, rCount, &jRCount, &cRCount);
|
|
|
|
ompi_java_getIntArray(env, sDispls, &jSDispls, &cSDispls);
|
|
|
|
ompi_java_getIntArray(env, rDispls, &jRDispls, &cRDispls);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-29 10:36:09 +00:00
|
|
|
void *sPtr = ompi_java_getDirectBufferAddress(env, sendBuf),
|
|
|
|
*rPtr = ompi_java_getDirectBufferAddress(env, recvBuf);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
MPI_Request request;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Ialltoallv(sPtr, cSCount, cSDispls, (MPI_Datatype)sType,
|
|
|
|
rPtr, cRCount, cRDispls, (MPI_Datatype)rType,
|
|
|
|
(MPI_Comm)comm, &request);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
ompi_java_forgetIntArray(env, sCount, jSCount, cSCount);
|
|
|
|
ompi_java_forgetIntArray(env, rCount, jRCount, cRCount);
|
|
|
|
ompi_java_forgetIntArray(env, sDispls, jSDispls, cSDispls);
|
|
|
|
ompi_java_forgetIntArray(env, rDispls, jRDispls, cRDispls);
|
|
|
|
return (jlong)request;
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_reduce(
|
2014-02-16 18:51:14 +00:00
|
|
|
JNIEnv *env, jobject jthis, jlong jComm,
|
2014-02-16 22:58:01 +00:00
|
|
|
jobject sendBuf, jboolean sdb, jint sOffset,
|
|
|
|
jobject recvBuf, jboolean rdb, jint rOffset,
|
2014-02-16 18:51:14 +00:00
|
|
|
jint count, jlong jType, jint baseType, jobject op, jint root)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2014-02-16 18:51:14 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)jComm;
|
2013-09-26 21:44:39 +00:00
|
|
|
int id;
|
|
|
|
int rc = MPI_Comm_rank(comm, &id);
|
|
|
|
int rootOrInter = id == root || isInter(env, comm);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(ompi_java_exceptionCheck(env, rc))
|
|
|
|
return;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2014-02-16 18:51:14 +00:00
|
|
|
MPI_Datatype type = (MPI_Datatype)jType;
|
2013-09-26 21:44:39 +00:00
|
|
|
void *sPtr, *sBase, *rPtr = NULL, *rBase;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(sendBuf == NULL)
|
|
|
|
sPtr = MPI_IN_PLACE;
|
|
|
|
else
|
2014-02-16 22:58:01 +00:00
|
|
|
sPtr = ompi_java_getBufPtr(&sBase, env, sendBuf, sdb, baseType, sOffset);
|
2013-09-26 21:44:39 +00:00
|
|
|
|
|
|
|
if(rootOrInter || sendBuf == NULL)
|
|
|
|
{
|
2014-02-16 22:58:01 +00:00
|
|
|
rPtr = ompi_java_getBufPtr(&rBase, env, recvBuf, rdb, baseType, rOffset);
|
2013-09-26 21:44:39 +00:00
|
|
|
|
|
|
|
if(!rootOrInter)
|
|
|
|
{
|
|
|
|
/* The receive buffer is ignored for all non-root processes.
|
|
|
|
* As we are using MPI_IN_PLACE version, we use the receive
|
|
|
|
* buffer as the send buffer.
|
|
|
|
*/
|
|
|
|
assert(sendBuf == NULL);
|
|
|
|
sPtr = rPtr;
|
|
|
|
}
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
MPI_Op mpiOp = ompi_java_op_getHandle(env, op, baseType);
|
2014-02-16 18:51:14 +00:00
|
|
|
rc = MPI_Reduce(sPtr, rPtr, count, type, mpiOp, root, comm);
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(sendBuf != NULL)
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseReadBufPtr(env, sendBuf, sdb, sBase, baseType);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(rootOrInter || sendBuf == NULL)
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseBufPtr(env, recvBuf, rdb, rBase, baseType);
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_iReduce(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
|
|
|
jobject sendBuf, jobject recvBuf, int count,
|
|
|
|
jlong type, jint baseType, jobject op, jint root)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2013-09-26 21:44:39 +00:00
|
|
|
int id;
|
|
|
|
int rc = MPI_Comm_rank((MPI_Comm)comm, &id);
|
|
|
|
int rootOrInter = id == root || isInter(env, (MPI_Comm)comm);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(ompi_java_exceptionCheck(env, rc))
|
|
|
|
return (jlong)MPI_REQUEST_NULL;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
void *sPtr, *rPtr = NULL;
|
|
|
|
MPI_Request request;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(sendBuf == NULL)
|
|
|
|
sPtr = MPI_IN_PLACE;
|
|
|
|
else
|
|
|
|
sPtr = (*env)->GetDirectBufferAddress(env, sendBuf);
|
|
|
|
|
|
|
|
if(rootOrInter || sendBuf == NULL)
|
|
|
|
{
|
|
|
|
rPtr = (*env)->GetDirectBufferAddress(env, recvBuf);
|
|
|
|
|
|
|
|
if(!rootOrInter)
|
|
|
|
{
|
|
|
|
/* The receive buffer is ignored for all non-root processes.
|
|
|
|
* As we are using MPI_IN_PLACE version, we use the receive
|
|
|
|
* buffer as the send buffer.
|
|
|
|
*/
|
|
|
|
assert(sendBuf == NULL);
|
|
|
|
sPtr = rPtr;
|
|
|
|
}
|
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
MPI_Op mpiOp = ompi_java_op_getHandle(env, op, baseType);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
rc = MPI_Ireduce(sPtr, rPtr, count, (MPI_Datatype)type,
|
|
|
|
mpiOp, root, (MPI_Comm)comm, &request);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return (jlong)request;
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_allReduce(
|
2014-02-16 18:51:14 +00:00
|
|
|
JNIEnv *env, jobject jthis, jlong jComm,
|
2014-02-16 22:58:01 +00:00
|
|
|
jobject sendBuf, jboolean sdb, jint sendOffset,
|
|
|
|
jobject recvBuf, jboolean rdb, jint recvOffset,
|
2014-02-16 18:51:14 +00:00
|
|
|
jint count, jlong jType, jint baseType, jobject op)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2014-02-16 18:51:14 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)jComm;
|
|
|
|
MPI_Datatype type = (MPI_Datatype)jType;
|
2013-09-26 21:44:39 +00:00
|
|
|
void *sPtr, *sBase, *rPtr, *rBase;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(sendBuf == NULL)
|
|
|
|
sPtr = MPI_IN_PLACE;
|
|
|
|
else
|
2014-02-16 22:58:01 +00:00
|
|
|
sPtr = ompi_java_getBufPtr(&sBase, env, sendBuf, sdb, baseType, sendOffset);
|
2013-09-26 21:44:39 +00:00
|
|
|
|
2014-02-16 22:58:01 +00:00
|
|
|
rPtr = ompi_java_getBufPtr(&rBase, env, recvBuf, rdb, baseType, recvOffset);
|
2013-09-26 21:44:39 +00:00
|
|
|
MPI_Op mpiOp = ompi_java_op_getHandle(env, op, baseType);
|
2014-02-16 18:51:14 +00:00
|
|
|
int rc = MPI_Allreduce(sPtr, rPtr, count, type, mpiOp, comm);
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseBufPtr(env, recvBuf, rdb, rBase, baseType);
|
2013-09-26 21:44:39 +00:00
|
|
|
|
|
|
|
if(sendBuf != NULL)
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseReadBufPtr(env, sendBuf, sdb, sBase, baseType);
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_iAllReduce(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
|
|
|
jobject sendBuf, jobject recvBuf,
|
|
|
|
jint count, jlong type, jint baseType, jobject op)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2013-09-26 21:44:39 +00:00
|
|
|
MPI_Request request;
|
|
|
|
void *sPtr, *rPtr;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(sendBuf == NULL)
|
|
|
|
sPtr = MPI_IN_PLACE;
|
|
|
|
else
|
|
|
|
sPtr = (*env)->GetDirectBufferAddress(env, sendBuf);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
rPtr = (*env)->GetDirectBufferAddress(env, recvBuf);
|
|
|
|
MPI_Op mpiOp = ompi_java_op_getHandle(env, op, baseType);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Iallreduce(sPtr, rPtr, count, (MPI_Datatype)type,
|
|
|
|
mpiOp, (MPI_Comm)comm, &request);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return (jlong)request;
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_reduceScatter(
|
2014-02-16 18:51:14 +00:00
|
|
|
JNIEnv *env, jobject jthis, jlong jComm,
|
2014-02-16 22:58:01 +00:00
|
|
|
jobject sendBuf, jboolean sdb, jint sOffset,
|
|
|
|
jobject recvBuf, jboolean rdb, jint rOffset,
|
2014-02-16 18:51:14 +00:00
|
|
|
jintArray rCounts, jlong jType, jint bType, jobject op)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2014-02-16 18:51:14 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)jComm;
|
|
|
|
MPI_Datatype type = (MPI_Datatype)jType;
|
2013-09-26 21:44:39 +00:00
|
|
|
void *sPtr, *sBase, *rPtr, *rBase;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(sendBuf == NULL)
|
|
|
|
sPtr = MPI_IN_PLACE;
|
|
|
|
else
|
2014-02-16 22:58:01 +00:00
|
|
|
sPtr = ompi_java_getBufPtr(&sBase, env, sendBuf, sdb, bType, sOffset);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2014-02-16 22:58:01 +00:00
|
|
|
rPtr = ompi_java_getBufPtr(&rBase, env, recvBuf, rdb, bType, rOffset);
|
2013-09-26 21:44:39 +00:00
|
|
|
MPI_Op mpiOp = ompi_java_op_getHandle(env, op, bType);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
jint *jRCounts;
|
|
|
|
int *cRCounts;
|
|
|
|
ompi_java_getIntArray(env, rCounts, &jRCounts, &cRCounts);
|
|
|
|
|
|
|
|
int rc = MPI_Reduce_scatter(sPtr, rPtr, cRCounts, type, mpiOp, comm);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseBufPtr(env, recvBuf, rdb, rBase, bType);
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_forgetIntArray(env, rCounts, jRCounts, cRCounts);
|
|
|
|
|
|
|
|
if(sendBuf != NULL)
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseReadBufPtr(env, sendBuf, sdb, sBase, bType);
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_iReduceScatter(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm,
|
|
|
|
jobject sendBuf, jobject recvBuf, jintArray rCounts,
|
|
|
|
jlong type, int bType, jobject op)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2013-09-26 21:44:39 +00:00
|
|
|
void *sPtr, *rPtr;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(sendBuf == NULL)
|
|
|
|
sPtr = MPI_IN_PLACE;
|
|
|
|
else
|
|
|
|
sPtr = (*env)->GetDirectBufferAddress(env, sendBuf);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
rPtr = (*env)->GetDirectBufferAddress(env, recvBuf);
|
|
|
|
MPI_Op mpiOp = ompi_java_op_getHandle(env, op, bType);
|
|
|
|
MPI_Request request;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
jint *jRCounts;
|
|
|
|
int *cRCounts;
|
|
|
|
ompi_java_getIntArray(env, rCounts, &jRCounts, &cRCounts);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Ireduce_scatter(sPtr, rPtr, cRCounts, (MPI_Datatype)type,
|
|
|
|
mpiOp, (MPI_Comm)comm, &request);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
ompi_java_forgetIntArray(env, rCounts, jRCounts, cRCounts);
|
|
|
|
return (jlong)request;
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_reduceScatterBlock(
|
2014-02-16 18:51:14 +00:00
|
|
|
JNIEnv *env, jobject jthis, jlong jComm,
|
2014-02-16 22:58:01 +00:00
|
|
|
jobject sendBuf, jboolean sdb, jint sOffset,
|
|
|
|
jobject recvBuf, jboolean rdb, jint rOffset,
|
2014-02-16 18:51:14 +00:00
|
|
|
jint count, jlong jType, jint bType, jobject op)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2014-02-16 18:51:14 +00:00
|
|
|
MPI_Comm comm = (MPI_Comm)jComm;
|
|
|
|
MPI_Datatype type = (MPI_Datatype)jType;
|
2013-09-26 21:44:39 +00:00
|
|
|
void *sPtr, *sBase, *rPtr, *rBase;
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(sendBuf == NULL)
|
|
|
|
sPtr = MPI_IN_PLACE;
|
|
|
|
else
|
2014-02-16 22:58:01 +00:00
|
|
|
sPtr = ompi_java_getBufPtr(&sBase, env, sendBuf, sdb, bType, sOffset);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2014-02-16 22:58:01 +00:00
|
|
|
rPtr = ompi_java_getBufPtr(&rBase, env, recvBuf, rdb, bType, rOffset);
|
2013-09-26 21:44:39 +00:00
|
|
|
MPI_Op mpiOp = ompi_java_op_getHandle(env, op, bType);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
int rc = MPI_Reduce_scatter_block(sPtr, rPtr, count, type, mpiOp, comm);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseBufPtr(env, recvBuf, rdb, rBase, bType);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(sendBuf != NULL)
|
2014-02-16 22:58:01 +00:00
|
|
|
ompi_java_releaseReadBufPtr(env, sendBuf, sdb, sBase, bType);
|
2013-09-26 21:44:39 +00:00
|
|
|
}
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_mpi_Comm_iReduceScatterBlock(
|
|
|
|
JNIEnv *env, jobject jthis, jlong comm, jobject sendBuf,
|
|
|
|
jobject recvBuf, jint count, jlong type, jint bType, jobject op)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2013-09-26 21:44:39 +00:00
|
|
|
void *sPtr, *rPtr;
|
|
|
|
|
|
|
|
if(sendBuf == NULL)
|
|
|
|
sPtr = MPI_IN_PLACE;
|
|
|
|
else
|
|
|
|
sPtr = (*env)->GetDirectBufferAddress(env, sendBuf);
|
|
|
|
|
|
|
|
rPtr = (*env)->GetDirectBufferAddress(env, recvBuf);
|
|
|
|
MPI_Op mpiOp = ompi_java_op_getHandle(env, op, bType);
|
|
|
|
MPI_Request request;
|
|
|
|
|
|
|
|
int rc = MPI_Ireduce_scatter_block(sPtr, rPtr, count, (MPI_Datatype)type,
|
|
|
|
mpiOp, (MPI_Comm)comm, &request);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
return (jlong)request;
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2014-01-02 21:57:48 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_reduceLocal(
|
2014-02-16 22:58:01 +00:00
|
|
|
JNIEnv *env, jclass clazz, jobject inBuf, jboolean idb, jint inOff,
|
|
|
|
jobject inOutBuf, jboolean iodb, jint inOutOff, jint count,
|
2014-02-16 18:51:14 +00:00
|
|
|
jlong jType, jint bType, jobject op)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2014-02-16 18:51:14 +00:00
|
|
|
MPI_Datatype type = (MPI_Datatype)jType;
|
|
|
|
void *inPtr, *inBase, *inOutPtr, *inOutBase;
|
2014-02-16 22:58:01 +00:00
|
|
|
inPtr = getBufCritical(&inBase, env, inBuf, idb, bType, inOff);
|
|
|
|
inOutPtr = getBufCritical(&inOutBase, env, inOutBuf, iodb, bType, inOutOff);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2014-02-16 18:51:14 +00:00
|
|
|
int rc = MPI_Reduce_local(inPtr, inOutPtr, count, type,
|
|
|
|
ompi_java_op_getHandle(env, op, bType));
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
ompi_java_exceptionCheck(env, rc);
|
2014-02-16 22:58:01 +00:00
|
|
|
releaseBufCritical(env, inBuf, idb, inBase);
|
|
|
|
releaseBufCritical(env, inOutBuf, iodb, inOutBase);
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT void JNICALL Java_mpi_Comm_setName(
|
|
|
|
JNIEnv *env, jobject jthis, jlong handle, jstring jname)
|
2012-02-20 22:12:43 +00:00
|
|
|
{
|
2013-09-26 21:44:39 +00:00
|
|
|
const char *name = (*env)->GetStringUTFChars(env, jname, NULL);
|
|
|
|
int rc = MPI_Comm_set_name((MPI_Comm)handle, (char*)name);
|
|
|
|
ompi_java_exceptionCheck(env, rc);
|
|
|
|
(*env)->ReleaseStringUTFChars(env, jname, name);
|
2012-02-20 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
JNIEXPORT jstring JNICALL Java_mpi_Comm_getName(
|
|
|
|
JNIEnv *env, jobject jthis, jlong handle)
|
|
|
|
{
|
|
|
|
char name[MPI_MAX_OBJECT_NAME];
|
|
|
|
int len;
|
|
|
|
int rc = MPI_Comm_get_name((MPI_Comm)handle, name, &len);
|
2012-02-20 22:12:43 +00:00
|
|
|
|
2013-09-26 21:44:39 +00:00
|
|
|
if(ompi_java_exceptionCheck(env, rc))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return (*env)->NewStringUTF(env, name);
|
|
|
|
}
|