Skip to content

Commit 7548e34

Browse files
author
Nathaniel Graham
committed
Java bindings for alltoallw functions.
Includes bindings for MPI_ALLTOALLW and MPI_IALLTOALLW. Signed-off-by: Nathaniel Graham <[email protected]>
1 parent ec3a383 commit 7548e34

File tree

4 files changed

+199
-1
lines changed

4 files changed

+199
-1
lines changed

ompi/mpi/java/c/mpiJava.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* University of Stuttgart. All rights reserved.
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
12+
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
13+
* reserved.
1214
* $COPYRIGHT$
1315
*
1416
* Additional copyrights may follow
@@ -95,7 +97,7 @@ void ompi_java_releaseReadPtr(
9597
/* Gets a buffer pointer for writing. */
9698
void ompi_java_getWritePtr(
9799
void **ptr, ompi_java_buffer_t **item, JNIEnv *env,
98-
jobject buf, jboolean db, int count, MPI_Datatype type);
100+
jobject buf, jboolean db, int count, MPI_Datatype type);
99101

100102
/* Gets a buffer pointer for writing.
101103
* 'size' is the number of processes. */
@@ -133,6 +135,11 @@ void ompi_java_releaseIntArray(
133135
void ompi_java_forgetIntArray(
134136
JNIEnv *env, jintArray array, jint *jptr, int *cptr);
135137

138+
void ompi_java_getDatatypeArray(
139+
JNIEnv *env, jlongArray array, jlong **jptr, MPI_Datatype **cptr);
140+
void ompi_java_forgetDatatypeArray(
141+
JNIEnv *env, jlongArray array, jlong *jptr, MPI_Datatype *cptr);
142+
136143
void ompi_java_getBooleanArray(
137144
JNIEnv *env, jbooleanArray array, jboolean **jptr, int **cptr);
138145
void ompi_java_releaseBooleanArray(

ompi/mpi/java/c/mpi_Comm.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,82 @@ JNIEXPORT jlong JNICALL Java_mpi_Comm_iAllToAllv(
15811581
return (jlong)request;
15821582
}
15831583

1584+
JNIEXPORT void JNICALL Java_mpi_Comm_allToAllw(
1585+
JNIEnv *env, jobject jthis, jlong jComm,
1586+
jobject sendBuf, jintArray sCount, jintArray sDispls, jlongArray sTypes,
1587+
jobject recvBuf, jintArray rCount, jintArray rDispls, jlongArray rTypes)
1588+
{
1589+
MPI_Comm comm = (MPI_Comm)jComm;
1590+
1591+
jlong* jSTypes, *jRTypes;
1592+
MPI_Datatype *cSTypes, *cRTypes;
1593+
1594+
ompi_java_getDatatypeArray(env, sTypes, &jSTypes, &cSTypes);
1595+
ompi_java_getDatatypeArray(env, rTypes, &jRTypes, &cRTypes);
1596+
1597+
jint *jSCount, *jRCount, *jSDispls, *jRDispls;
1598+
int *cSCount, *cRCount, *cSDispls, *cRDispls;
1599+
ompi_java_getIntArray(env, sCount, &jSCount, &cSCount);
1600+
ompi_java_getIntArray(env, rCount, &jRCount, &cRCount);
1601+
ompi_java_getIntArray(env, sDispls, &jSDispls, &cSDispls);
1602+
ompi_java_getIntArray(env, rDispls, &jRDispls, &cRDispls);
1603+
1604+
void *sPtr = ompi_java_getDirectBufferAddress(env, sendBuf),
1605+
*rPtr = ompi_java_getDirectBufferAddress(env, recvBuf);
1606+
1607+
int rc = MPI_Alltoallw(
1608+
sPtr, cSCount, cSDispls, cSTypes,
1609+
rPtr, cRCount, cRDispls, cRTypes, comm);
1610+
1611+
ompi_java_exceptionCheck(env, rc);
1612+
ompi_java_forgetIntArray(env, sCount, jSCount, cSCount);
1613+
ompi_java_forgetIntArray(env, rCount, jRCount, cRCount);
1614+
ompi_java_forgetIntArray(env, sDispls, jSDispls, cSDispls);
1615+
ompi_java_forgetIntArray(env, rDispls, jRDispls, cRDispls);
1616+
ompi_java_forgetDatatypeArray(env, sTypes, jSTypes, cSTypes);
1617+
ompi_java_forgetDatatypeArray(env, rTypes, jRTypes, cRTypes);
1618+
}
1619+
1620+
JNIEXPORT jlong JNICALL Java_mpi_Comm_iAllToAllw(
1621+
JNIEnv *env, jobject jthis, jlong jComm,
1622+
jobject sendBuf, jintArray sCount, jintArray sDispls, jlongArray sTypes,
1623+
jobject recvBuf, jintArray rCount, jintArray rDispls, jlongArray rTypes)
1624+
{
1625+
MPI_Comm comm = (MPI_Comm)jComm;
1626+
1627+
jlong* jSTypes, *jRTypes;
1628+
MPI_Datatype *cSTypes, *cRTypes;
1629+
1630+
ompi_java_getDatatypeArray(env, sTypes, &jSTypes, &cSTypes);
1631+
ompi_java_getDatatypeArray(env, rTypes, &jRTypes, &cRTypes);
1632+
1633+
jint *jSCount, *jRCount, *jSDispls, *jRDispls;
1634+
int *cSCount, *cRCount, *cSDispls, *cRDispls;
1635+
ompi_java_getIntArray(env, sCount, &jSCount, &cSCount);
1636+
ompi_java_getIntArray(env, rCount, &jRCount, &cRCount);
1637+
ompi_java_getIntArray(env, sDispls, &jSDispls, &cSDispls);
1638+
ompi_java_getIntArray(env, rDispls, &jRDispls, &cRDispls);
1639+
1640+
void *sPtr = ompi_java_getDirectBufferAddress(env, sendBuf),
1641+
*rPtr = ompi_java_getDirectBufferAddress(env, recvBuf);
1642+
1643+
MPI_Request request;
1644+
1645+
int rc = MPI_Ialltoallw(
1646+
sPtr, cSCount, cSDispls, cSTypes,
1647+
rPtr, cRCount, cRDispls, cRTypes, comm, &request);
1648+
1649+
ompi_java_exceptionCheck(env, rc);
1650+
ompi_java_forgetIntArray(env, sCount, jSCount, cSCount);
1651+
ompi_java_forgetIntArray(env, rCount, jRCount, cRCount);
1652+
ompi_java_forgetIntArray(env, sDispls, jSDispls, cSDispls);
1653+
ompi_java_forgetIntArray(env, rDispls, jRDispls, cRDispls);
1654+
ompi_java_forgetDatatypeArray(env, sTypes, jSTypes, cSTypes);
1655+
ompi_java_forgetDatatypeArray(env, rTypes, jRTypes, cRTypes);
1656+
1657+
return (jlong)request;
1658+
}
1659+
15841660
JNIEXPORT void JNICALL Java_mpi_Comm_neighborAllGather(
15851661
JNIEnv *env, jobject jthis, jlong jComm,
15861662
jobject sBuf, jboolean sdb, jint sOff,

ompi/mpi/java/c/mpi_MPI.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,30 @@ void ompi_java_forgetIntArray(JNIEnv *env, jintArray array,
975975
(*env)->ReleaseIntArrayElements(env, array, jptr, JNI_ABORT);
976976
}
977977

978+
void ompi_java_getDatatypeArray(JNIEnv *env, jlongArray array,
979+
jlong **jptr, MPI_Datatype **cptr)
980+
{
981+
jlong *jLongs = (*env)->GetLongArrayElements(env, array, NULL);
982+
*jptr = jLongs;
983+
984+
int i, length = (*env)->GetArrayLength(env, array);
985+
MPI_Datatype *cDatatypes = calloc(length, sizeof(MPI_Datatype));
986+
987+
for(i = 0; i < length; i++){
988+
cDatatypes[i] = (MPI_Datatype)jLongs[i];
989+
}
990+
*cptr = cDatatypes;
991+
}
992+
993+
void ompi_java_forgetDatatypeArray(JNIEnv *env, jlongArray array,
994+
jlong *jptr, MPI_Datatype *cptr)
995+
{
996+
if(jptr != cptr)
997+
free(cptr);
998+
999+
(*env)->ReleaseLongArrayElements(env, array, jptr, JNI_ABORT);
1000+
}
1001+
9781002
void ompi_java_getBooleanArray(JNIEnv *env, jbooleanArray array,
9791003
jboolean **jptr, int **cptr)
9801004
{

ompi/mpi/java/java/Comm.java

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ public static int compare(Comm comm1, Comm comm2) throws MPIException
229229

230230
/**
231231
* Test if communicator object is null (has been freed).
232+
* Java binding of {@code MPI_COMM_NULL}.
232233
* @return true if the comm object is null, false otherwise
233234
*/
234235
public final boolean isNull()
@@ -2307,6 +2308,79 @@ private native long iAllToAllv(long comm,
23072308
Buffer recvbuf, int[] recvcount, int[] rdispls, long recvtype)
23082309
throws MPIException;
23092310

2311+
/**
2312+
* Adds flexibility to {@code allToAll}: location of data for send is //here
2313+
* specified by {@code sDispls} and location to place data on receive
2314+
* side is specified by {@code rDispls}.
2315+
* <p>Java binding of the MPI operation {@code MPI_ALLTOALLW}.
2316+
* @param sendBuf send buffer
2317+
* @param sendCount number of items sent to each buffer
2318+
* @param sDispls displacements from which to take outgoing data
2319+
* @param sendTypes datatypes of send buffer items
2320+
* @param recvBuf receive buffer
2321+
* @param recvCount number of elements received from each process
2322+
* @param rDispls displacements at which to place incoming data
2323+
* @param recvTypes datatype of each item in receive buffer
2324+
* @throws MPIException Signals that an MPI exception of some sort has occurred.
2325+
*/
2326+
public final void allToAllw(
2327+
Buffer sendBuf, int[] sendCount, int[] sDispls, Datatype[] sendTypes,
2328+
Buffer recvBuf, int[] recvCount, int[] rDispls, Datatype[] recvTypes)
2329+
throws MPIException
2330+
{
2331+
MPI.check();
2332+
assertDirectBuffer(sendBuf, recvBuf);
2333+
2334+
long[] sendHandles = convertTypeArray(sendTypes);
2335+
long[] recvHandles = convertTypeArray(recvTypes);
2336+
2337+
allToAllw(handle, sendBuf, sendCount, sDispls,
2338+
sendHandles, recvBuf, recvCount, rDispls,
2339+
recvHandles);
2340+
}
2341+
2342+
private native void allToAllw(long comm,
2343+
Buffer sendBuf, int[] sendCount, int[] sDispls, long[] sendTypes,
2344+
Buffer recvBuf, int[] recvCount, int[] rDispls, long[] recvTypes)
2345+
throws MPIException;
2346+
2347+
/**
2348+
* Adds flexibility to {@code iAllToAll}: location of data for send is
2349+
* specified by {@code sDispls} and location to place data on receive
2350+
* side is specified by {@code rDispls}.
2351+
* <p>Java binding of the MPI operation {@code MPI_IALLTOALLW}.
2352+
* @param sendBuf send buffer
2353+
* @param sendCount number of items sent to each buffer
2354+
* @param sDispls displacements from which to take outgoing data
2355+
* @param sendTypes datatype send buffer items
2356+
* @param recvBuf receive buffer
2357+
* @param recvCount number of elements received from each process
2358+
* @param rDispls displacements at which to place incoming data
2359+
* @param recvTypes datatype of each item in receive buffer
2360+
* @return communication request
2361+
* @throws MPIException Signals that an MPI exception of some sort has occurred.
2362+
*/
2363+
public final Request iAllToAllw(
2364+
Buffer sendBuf, int[] sendCount, int[] sDispls, Datatype[] sendTypes,
2365+
Buffer recvBuf, int[] recvCount, int[] rDispls, Datatype[] recvTypes)
2366+
throws MPIException
2367+
{
2368+
MPI.check();
2369+
assertDirectBuffer(sendBuf, recvBuf);
2370+
2371+
long[] sendHandles = convertTypeArray(sendTypes);
2372+
long[] recvHandles = convertTypeArray(recvTypes);
2373+
2374+
return new Request(iAllToAllw(
2375+
handle, sendBuf, sendCount, sDispls, sendHandles,
2376+
recvBuf, recvCount, rDispls, recvHandles));
2377+
}
2378+
2379+
private native long iAllToAllw(long comm,
2380+
Buffer sendBuf, int[] sendCount, int[] sDispls, long[] sendTypes,
2381+
Buffer recvBuf, int[] recvCount, int[] rDispls, long[] recvTypes)
2382+
throws MPIException;
2383+
23102384
/**
23112385
* Java binding of {@code MPI_NEIGHBOR_ALLGATHER}.
23122386
* @param sendbuf send buffer
@@ -3232,4 +3306,21 @@ public final String getName() throws MPIException
32323306

32333307
private native String getName(long handle) throws MPIException;
32343308

3309+
/**
3310+
* A helper method to convert an array of Datatypes to
3311+
* an array of longs (handles).
3312+
* @param dArray Array of Datatypes
3313+
* @return converted Datatypes
3314+
*/
3315+
private long[] convertTypeArray(Datatype[] dArray) {
3316+
long[] lArray = new long[dArray.length];
3317+
3318+
for(int i = 0; i < lArray.length; i++) {
3319+
if(dArray[i] != null) {
3320+
lArray[i] = dArray[i].handle;
3321+
}
3322+
}
3323+
return lArray;
3324+
}
3325+
32353326
} // Comm

0 commit comments

Comments
 (0)