Skip to content

Commit 982a232

Browse files
author
Nathaniel Graham
committed
Additional Java Bindings
Java bindings for the following functions: MPI_RACCUMULATE, MPI_GET_ACCUMULATE, MPI_RGET_ACCUMULATE, MPI_WIN_LOCK_ALL, MPI_WIN_UNLOCK_ALL, MPI_WIN_SYNC, MPI_WIN_FLUSH, MPI_WIN_FLUSH_ALL, MPI_COMPARE_AND_SWAP, and MPI_FETCH_AND_OP. Also includes Java bindings for the Operations MPI_REPLACE and MPI_NO_OP. Signed-off-by: Nathaniel Graham <[email protected]>
1 parent bb5699e commit 982a232

File tree

4 files changed

+338
-2
lines changed

4 files changed

+338
-2
lines changed

ompi/mpi/java/c/mpi_Op.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ JNIEXPORT void JNICALL Java_mpi_Op_getOp(JNIEnv *env, jobject jthis, jint type)
6969
static MPI_Op Ops[] = {
7070
MPI_OP_NULL, MPI_MAX, MPI_MIN, MPI_SUM,
7171
MPI_PROD, MPI_LAND, MPI_BAND, MPI_LOR, MPI_BOR, MPI_LXOR,
72-
MPI_BXOR, MPI_MINLOC, MPI_MAXLOC
72+
MPI_BXOR, MPI_MINLOC, MPI_MAXLOC, MPI_REPLACE, MPI_NO_OP
7373
};
7474
(*env)->SetLongField(env,jthis, ompi_java.OpHandle, (jlong)Ops[type]);
7575
}

ompi/mpi/java/c/mpi_Win.c

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,106 @@ JNIEXPORT jlong JNICALL Java_mpi_Win_rGet(JNIEnv *env, jobject jthis, jlong win,
329329
return (jlong)request;
330330
}
331331

332+
JNIEXPORT jlong JNICALL Java_mpi_Win_rAccumulate(JNIEnv *env, jobject jthis, jlong win,
333+
jobject origin, jint orgCount, jlong orgType, jint targetRank, jint targetDisp,
334+
jint targetCount, jlong targetType, jobject jOp, jlong hOp, jint baseType)
335+
{
336+
void *orgPtr = (*env)->GetDirectBufferAddress(env, origin);
337+
MPI_Op op = ompi_java_op_getHandle(env, jOp, hOp, baseType);
338+
MPI_Request request;
339+
340+
int rc = MPI_Raccumulate(orgPtr, orgCount, (MPI_Datatype)orgType,
341+
targetRank, (MPI_Aint)targetDisp, targetCount,
342+
(MPI_Datatype)targetType, op, (MPI_Win)win, &request);
343+
344+
ompi_java_exceptionCheck(env, rc);
345+
return (jlong)request;
346+
}
347+
348+
JNIEXPORT void JNICALL Java_mpi_Win_getAccumulate(JNIEnv *env, jobject jthis, jlong win,
349+
jobject origin, jint orgCount, jlong orgType, jobject resultBuff, jint resultCount,
350+
jlong resultType, jint targetRank, jint targetDisp, jint targetCount, jlong targetType,
351+
jobject jOp, jlong hOp, jint baseType)
352+
{
353+
void *orgPtr = (*env)->GetDirectBufferAddress(env, origin);
354+
void *resultPtr = (*env)->GetDirectBufferAddress(env, resultBuff);
355+
MPI_Op op = ompi_java_op_getHandle(env, jOp, hOp, baseType);
356+
357+
int rc = MPI_Get_accumulate(orgPtr, orgCount, (MPI_Datatype)orgType,
358+
resultPtr, resultCount, (MPI_Datatype)resultType,
359+
targetRank, (MPI_Aint)targetDisp, targetCount,
360+
(MPI_Datatype)targetType, op, (MPI_Win)win);
361+
362+
ompi_java_exceptionCheck(env, rc);
363+
}
364+
365+
JNIEXPORT jlong JNICALL Java_mpi_Win_rGetAccumulate(JNIEnv *env, jobject jthis, jlong win,
366+
jobject origin, jint orgCount, jlong orgType, jobject resultBuff, jint resultCount,
367+
jlong resultType, jint targetRank, jint targetDisp, jint targetCount, jlong targetType,
368+
jobject jOp, jlong hOp, jint baseType)
369+
{
370+
void *orgPtr = (*env)->GetDirectBufferAddress(env, origin);
371+
void *resultPtr = (*env)->GetDirectBufferAddress(env, resultBuff);
372+
MPI_Op op = ompi_java_op_getHandle(env, jOp, hOp, baseType);
373+
MPI_Request request;
374+
375+
int rc = MPI_Rget_accumulate(orgPtr, orgCount, (MPI_Datatype)orgType,
376+
resultPtr, resultCount, (MPI_Datatype)resultType,
377+
targetRank, (MPI_Aint)targetDisp, targetCount,
378+
(MPI_Datatype)targetType, op, (MPI_Win)win, &request);
379+
380+
ompi_java_exceptionCheck(env, rc);
381+
return (jlong)request;
382+
}
383+
384+
JNIEXPORT void JNICALL Java_mpi_Win_lockAll(JNIEnv *env, jobject jthis, jlong win, jint assertion)
385+
{
386+
int rc = MPI_Win_lock_all(assertion, (MPI_Win)win);
387+
ompi_java_exceptionCheck(env, rc);
388+
}
389+
390+
JNIEXPORT void JNICALL Java_mpi_Win_unlockAll(JNIEnv *env, jobject jthis, jlong win)
391+
{
392+
int rc = MPI_Win_unlock_all((MPI_Win)win);
393+
ompi_java_exceptionCheck(env, rc);
394+
}
395+
396+
JNIEXPORT void JNICALL Java_mpi_Win_sync(JNIEnv *env, jobject jthis, jlong win)
397+
{
398+
int rc = MPI_Win_sync((MPI_Win)win);
399+
ompi_java_exceptionCheck(env, rc);
400+
}
401+
402+
JNIEXPORT void JNICALL Java_mpi_Win_flush(JNIEnv *env, jobject jthis, jlong win, jint targetRank)
403+
{
404+
int rc = MPI_Win_flush(targetRank, (MPI_Win)win);
405+
ompi_java_exceptionCheck(env, rc);
406+
}
407+
408+
JNIEXPORT void JNICALL Java_mpi_Win_flushAll(JNIEnv *env, jobject jthis, jlong win)
409+
{
410+
int rc = MPI_Win_flush_all((MPI_Win)win);
411+
ompi_java_exceptionCheck(env, rc);
412+
}
413+
414+
JNIEXPORT void JNICALL Java_mpi_Win_compareAndSwap (JNIEnv *env, jobject jthis, jlong win, jobject origin,
415+
jobject compareAddr, jobject resultAddr, jlong dataType, jint targetRank, jint targetDisp)
416+
{
417+
void *orgPtr = (*env)->GetDirectBufferAddress(env, origin);
418+
void *compPtr = (*env)->GetDirectBufferAddress(env, compareAddr);
419+
void *resultPtr = (*env)->GetDirectBufferAddress(env, resultAddr);
420+
421+
int rc = MPI_Compare_and_swap(orgPtr, compPtr, resultPtr, dataType, targetRank, targetDisp, (MPI_Win)win);
422+
ompi_java_exceptionCheck(env, rc);
423+
}
424+
425+
JNIEXPORT void JNICALL Java_mpi_Win_fetchAndOp(JNIEnv *env, jobject jthis, jlong win, jobject origin,
426+
jobject resultAddr, jlong dataType, jint targetRank, jint targetDisp, jobject jOp, jlong hOp, jint baseType)
427+
{
428+
void *orgPtr = (*env)->GetDirectBufferAddress(env, origin);
429+
void *resultPtr = (*env)->GetDirectBufferAddress(env, resultAddr);
430+
MPI_Op op = ompi_java_op_getHandle(env, jOp, hOp, baseType);
431+
432+
int rc = MPI_Fetch_and_op(orgPtr, resultPtr, dataType, targetRank, targetDisp, op, (MPI_Win)win);
433+
ompi_java_exceptionCheck(env, rc);
434+
}

ompi/mpi/java/java/MPI.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public final class MPI
6868
public static final int ANY_SOURCE, ANY_TAG;
6969

7070
public static final Op MAX, MIN, SUM, PROD, LAND, BAND,
71-
LOR, BOR, LXOR, BXOR;
71+
LOR, BOR, LXOR, BXOR, REPLACE, NO_OP;
7272

7373
/**
7474
* Global minimum operator.
@@ -241,6 +241,8 @@ public final class MPI
241241
BXOR = new Op(10);
242242
MINLOC = new Op(11);
243243
MAXLOC = new Op(12);
244+
REPLACE = new Op(13);
245+
NO_OP = new Op(14);
244246

245247
GROUP_EMPTY = new Group(Group.getEmpty());
246248
REQUEST_NULL = new Request(Request.getNull());

ompi/mpi/java/java/Win.java

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,4 +558,235 @@ private native long rGet(
558558
int targetRank, int targetDisp, int targetCount, long targetType,
559559
int baseType) throws MPIException;
560560

561+
/**
562+
* Java binding of {@code MPI_RACCUMULATE}.
563+
* @param origin origin buffer
564+
* @param orgCount number of entries in origin buffer
565+
* @param orgType datatype of each entry in origin buffer
566+
* @param targetRank rank of target
567+
* @param targetDisp displacement from start of window to target buffer
568+
* @param targetCount number of entries in target buffer
569+
* @param targetType datatype of each entry in target buffer
570+
* @param op reduce operation
571+
* @return RMA request
572+
* @throws MPIException
573+
*/
574+
public Request rAccumulate(Buffer origin, int orgCount, Datatype orgType,
575+
int targetRank, int targetDisp, int targetCount,
576+
Datatype targetType, Op op)
577+
throws MPIException
578+
{
579+
MPI.check();
580+
581+
if(!origin.isDirect())
582+
throw new IllegalArgumentException("The origin must be direct buffer.");
583+
584+
return new Request(rAccumulate(handle, origin, orgCount, orgType.handle,
585+
targetRank, targetDisp, targetCount, targetType.handle,
586+
op, op.handle, getBaseType(orgType, targetType)));
587+
}
588+
589+
private native long rAccumulate(
590+
long win, Buffer origin, int orgCount, long orgType,
591+
int targetRank, int targetDisp, int targetCount, long targetType,
592+
Op jOp, long hOp, int baseType) throws MPIException;
593+
594+
/**
595+
* Java binding of {@code MPI_GET_ACCUMULATE}.
596+
* @param origin origin buffer
597+
* @param orgCount number of entries in origin buffer
598+
* @param orgType datatype of each entry in origin buffer
599+
* @param resultAddr result buffer
600+
* @param resultCount number of entries in result buffer
601+
* @param resultType datatype of each entry in result buffer
602+
* @param targetRank rank of target
603+
* @param targetDisp displacement from start of window to target buffer
604+
* @param targetCount number of entries in target buffer
605+
* @param targetType datatype of each entry in target buffer
606+
* @param op reduce operation
607+
* @throws MPIException
608+
*/
609+
610+
public void getAccumulate(Buffer origin, int orgCount, Datatype orgType,
611+
Buffer resultAddr, int resultCount, Datatype resultType,
612+
int targetRank, int targetDisp, int targetCount,
613+
Datatype targetType, Op op)
614+
throws MPIException
615+
{
616+
MPI.check();
617+
618+
if(!origin.isDirect())
619+
throw new IllegalArgumentException("The origin must be direct buffer.");
620+
621+
getAccumulate(handle, origin, orgCount, orgType.handle,
622+
resultAddr, resultCount, resultType.handle,
623+
targetRank, targetDisp, targetCount, targetType.handle,
624+
op, op.handle, getBaseType(orgType, targetType));
625+
}
626+
627+
private native void getAccumulate(
628+
long win, Buffer origin, int orgCount, long orgType,
629+
Buffer resultAddr, int resultCount, long resultType,
630+
int targetRank, int targetDisp, int targetCount, long targetType,
631+
Op jOp, long hOp, int baseType) throws MPIException;
632+
633+
/**
634+
* Java binding of {@code MPI_RGET_ACCUMULATE}.
635+
* @param origin origin buffer
636+
* @param orgCount number of entries in origin buffer
637+
* @param orgType datatype of each entry in origin buffer
638+
* @param resultAddr result buffer
639+
* @param resultCount number of entries in result buffer
640+
* @param resultType datatype of each entry in result buffer
641+
* @param targetRank rank of target
642+
* @param targetDisp displacement from start of window to target buffer
643+
* @param targetCount number of entries in target buffer
644+
* @param targetType datatype of each entry in target buffer
645+
* @param op reduce operation
646+
* @return RMA request
647+
* @throws MPIException
648+
*/
649+
650+
public Request rGetAccumulate(Buffer origin, int orgCount, Datatype orgType,
651+
Buffer resultAddr, int resultCount, Datatype resultType,
652+
int targetRank, int targetDisp, int targetCount,
653+
Datatype targetType, Op op)
654+
throws MPIException
655+
{
656+
MPI.check();
657+
658+
if(!origin.isDirect())
659+
throw new IllegalArgumentException("The origin must be direct buffer.");
660+
661+
return new Request(rGetAccumulate(handle, origin, orgCount, orgType.handle,
662+
resultAddr, resultCount, resultType.handle,
663+
targetRank, targetDisp, targetCount, targetType.handle,
664+
op, op.handle, getBaseType(orgType, targetType)));
665+
}
666+
667+
private native long rGetAccumulate(
668+
long win, Buffer origin, int orgCount, long orgType,
669+
Buffer resultAddr, int resultCount, long resultType,
670+
int targetRank, int targetDisp, int targetCount, long targetType,
671+
Op jOp, long hOp, int baseType) throws MPIException;
672+
673+
/**
674+
* Java binding of the MPI operation {@code MPI_WIN_LOCK_ALL}.
675+
* @param assertion program assertion
676+
* @throws MPIException
677+
*/
678+
public void lockAll(int assertion) throws MPIException
679+
{
680+
MPI.check();
681+
lockAll(handle, assertion);
682+
}
683+
684+
private native void lockAll(long win, int assertion)
685+
throws MPIException;
686+
687+
/**
688+
* Java binding of the MPI operation {@code MPI_WIN_UNLOCK_ALL}.
689+
* @throws MPIException
690+
*/
691+
public void unlockAll() throws MPIException
692+
{
693+
MPI.check();
694+
unlockAll(handle);
695+
}
696+
697+
private native void unlockAll(long win) throws MPIException;
698+
699+
/**
700+
* Java binding of the MPI operation {@code MPI_WIN_SYNC}.
701+
* @throws MPIException
702+
*/
703+
public void sync() throws MPIException
704+
{
705+
MPI.check();
706+
sync(handle);
707+
}
708+
709+
private native void sync(long win) throws MPIException;
710+
711+
/**
712+
* Java binding of the MPI operation {@code MPI_WIN_FLUSH}.
713+
* @param targetRank rank of target window
714+
* @throws MPIException
715+
*/
716+
public void flush(int targetRank) throws MPIException
717+
{
718+
MPI.check();
719+
flush(handle, targetRank);
720+
}
721+
722+
private native void flush(long win, int targetRank) throws MPIException;
723+
724+
/**
725+
* Java binding of the MPI operation {@code MPI_WIN_FLUSH_ALL}.
726+
* @throws MPIException
727+
*/
728+
public void flushAll() throws MPIException
729+
{
730+
MPI.check();
731+
flushAll(handle);
732+
}
733+
734+
private native void flushAll(long win) throws MPIException;
735+
736+
/**
737+
* Java binding of {@code MPI_COMPARE_AND_SWAP}.
738+
* @param origin origin buffer
739+
* @param compareAddr compare buffer
740+
* @param resultAddr result buffer
741+
* @param targetType datatype of each entry in target buffer
742+
* @param targetRank rank of target
743+
* @param targetDisp displacement from start of window to target buffer
744+
* @throws MPIException
745+
*/
746+
747+
public void compareAndSwap(Buffer origin, Buffer compareAddr, Buffer resultAddr,
748+
Datatype targetType, int targetRank, int targetDisp)
749+
throws MPIException
750+
{
751+
MPI.check();
752+
753+
if(!origin.isDirect())
754+
throw new IllegalArgumentException("The origin must be direct buffer.");
755+
756+
compareAndSwap(handle, origin, compareAddr, resultAddr,
757+
targetType.handle, targetRank, targetDisp);
758+
}
759+
760+
private native void compareAndSwap(
761+
long win, Buffer origin, Buffer compareAddr, Buffer resultAddr,
762+
long targetType, int targetRank, int targetDisp) throws MPIException;
763+
764+
/**
765+
* Java binding of {@code MPI_FETCH_AND_OP}.
766+
* @param origin origin buffer
767+
* @param resultAddr result buffer
768+
* @param dataType datatype of entry in origin, result, and target buffers
769+
* @param targetRank rank of target
770+
* @param targetDisp displacement from start of window to target buffer
771+
* @param op reduce operation
772+
* @throws MPIException
773+
*/
774+
775+
public void fetchAndOp(Buffer origin, Buffer resultAddr, Datatype dataType,
776+
int targetRank, int targetDisp, Op op)
777+
throws MPIException
778+
{
779+
MPI.check();
780+
781+
if(!origin.isDirect())
782+
throw new IllegalArgumentException("The origin must be direct buffer.");
783+
784+
fetchAndOp(handle, origin, resultAddr, dataType.handle, targetRank,
785+
targetDisp, op, op.handle, getBaseType(dataType, dataType)); //neccessary?
786+
}
787+
788+
private native void fetchAndOp(
789+
long win, Buffer origin, Buffer resultAddr, long targetType, int targetRank,
790+
int targetDisp, Op jOp, long hOp, int baseType) throws MPIException;
791+
561792
} // Win

0 commit comments

Comments
 (0)