Skip to content

Commit 1fef4c1

Browse files
committed
Merge pull request open-mpi#389 from nrgraham23/more_one-sided_bindings
More one sided bindings
2 parents 41dc998 + f6bee49 commit 1fef4c1

File tree

4 files changed

+342
-2
lines changed

4 files changed

+342
-2
lines changed

ompi/mpi/java/c/mpi_Op.c

Lines changed: 3 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
@@ -69,7 +71,7 @@ JNIEXPORT void JNICALL Java_mpi_Op_getOp(JNIEnv *env, jobject jthis, jint type)
6971
static MPI_Op Ops[] = {
7072
MPI_OP_NULL, MPI_MAX, MPI_MIN, MPI_SUM,
7173
MPI_PROD, MPI_LAND, MPI_BAND, MPI_LOR, MPI_BOR, MPI_LXOR,
72-
MPI_BXOR, MPI_MINLOC, MPI_MAXLOC
74+
MPI_BXOR, MPI_MINLOC, MPI_MAXLOC, MPI_REPLACE, MPI_NO_OP
7375
};
7476
(*env)->SetLongField(env,jthis, ompi_java.OpHandle, (jlong)Ops[type]);
7577
}

ompi/mpi/java/c/mpi_Win.c

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

296+
JNIEXPORT jlong JNICALL Java_mpi_Win_rAccumulate(JNIEnv *env, jobject jthis, jlong win,
297+
jobject origin, jint orgCount, jlong orgType, jint targetRank, jint targetDisp,
298+
jint targetCount, jlong targetType, jobject jOp, jlong hOp, jint baseType)
299+
{
300+
void *orgPtr = (*env)->GetDirectBufferAddress(env, origin);
301+
MPI_Op op = ompi_java_op_getHandle(env, jOp, hOp, baseType);
302+
MPI_Request request;
303+
304+
int rc = MPI_Raccumulate(orgPtr, orgCount, (MPI_Datatype)orgType,
305+
targetRank, (MPI_Aint)targetDisp, targetCount,
306+
(MPI_Datatype)targetType, op, (MPI_Win)win, &request);
307+
308+
ompi_java_exceptionCheck(env, rc);
309+
return (jlong)request;
310+
}
311+
312+
JNIEXPORT void JNICALL Java_mpi_Win_getAccumulate(JNIEnv *env, jobject jthis, jlong win,
313+
jobject origin, jint orgCount, jlong orgType, jobject resultBuff, jint resultCount,
314+
jlong resultType, jint targetRank, jint targetDisp, jint targetCount, jlong targetType,
315+
jobject jOp, jlong hOp, jint baseType)
316+
{
317+
void *orgPtr = (*env)->GetDirectBufferAddress(env, origin);
318+
void *resultPtr = (*env)->GetDirectBufferAddress(env, resultBuff);
319+
MPI_Op op = ompi_java_op_getHandle(env, jOp, hOp, baseType);
320+
321+
int rc = MPI_Get_accumulate(orgPtr, orgCount, (MPI_Datatype)orgType,
322+
resultPtr, resultCount, (MPI_Datatype)resultType,
323+
targetRank, (MPI_Aint)targetDisp, targetCount,
324+
(MPI_Datatype)targetType, op, (MPI_Win)win);
325+
326+
ompi_java_exceptionCheck(env, rc);
327+
}
328+
329+
JNIEXPORT jlong JNICALL Java_mpi_Win_rGetAccumulate(JNIEnv *env, jobject jthis, jlong win,
330+
jobject origin, jint orgCount, jlong orgType, jobject resultBuff, jint resultCount,
331+
jlong resultType, jint targetRank, jint targetDisp, jint targetCount, jlong targetType,
332+
jobject jOp, jlong hOp, jint baseType)
333+
{
334+
void *orgPtr = (*env)->GetDirectBufferAddress(env, origin);
335+
void *resultPtr = (*env)->GetDirectBufferAddress(env, resultBuff);
336+
MPI_Op op = ompi_java_op_getHandle(env, jOp, hOp, baseType);
337+
MPI_Request request;
338+
339+
int rc = MPI_Rget_accumulate(orgPtr, orgCount, (MPI_Datatype)orgType,
340+
resultPtr, resultCount, (MPI_Datatype)resultType,
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_lockAll(JNIEnv *env, jobject jthis, jlong win, jint assertion)
349+
{
350+
int rc = MPI_Win_lock_all(assertion, (MPI_Win)win);
351+
ompi_java_exceptionCheck(env, rc);
352+
}
353+
354+
JNIEXPORT void JNICALL Java_mpi_Win_unlockAll(JNIEnv *env, jobject jthis, jlong win)
355+
{
356+
int rc = MPI_Win_unlock_all((MPI_Win)win);
357+
ompi_java_exceptionCheck(env, rc);
358+
}
359+
360+
JNIEXPORT void JNICALL Java_mpi_Win_sync(JNIEnv *env, jobject jthis, jlong win)
361+
{
362+
int rc = MPI_Win_sync((MPI_Win)win);
363+
ompi_java_exceptionCheck(env, rc);
364+
}
365+
366+
JNIEXPORT void JNICALL Java_mpi_Win_flush(JNIEnv *env, jobject jthis, jlong win, jint targetRank)
367+
{
368+
int rc = MPI_Win_flush(targetRank, (MPI_Win)win);
369+
ompi_java_exceptionCheck(env, rc);
370+
}
371+
372+
JNIEXPORT void JNICALL Java_mpi_Win_flushAll(JNIEnv *env, jobject jthis, jlong win)
373+
{
374+
int rc = MPI_Win_flush_all((MPI_Win)win);
375+
ompi_java_exceptionCheck(env, rc);
376+
}
377+
378+
JNIEXPORT void JNICALL Java_mpi_Win_compareAndSwap (JNIEnv *env, jobject jthis, jlong win, jobject origin,
379+
jobject compareAddr, jobject resultAddr, jlong dataType, jint targetRank, jint targetDisp)
380+
{
381+
void *orgPtr = (*env)->GetDirectBufferAddress(env, origin);
382+
void *compPtr = (*env)->GetDirectBufferAddress(env, compareAddr);
383+
void *resultPtr = (*env)->GetDirectBufferAddress(env, resultAddr);
384+
385+
int rc = MPI_Compare_and_swap(orgPtr, compPtr, resultPtr, dataType, targetRank, targetDisp, (MPI_Win)win);
386+
ompi_java_exceptionCheck(env, rc);
387+
}
388+
389+
JNIEXPORT void JNICALL Java_mpi_Win_fetchAndOp(JNIEnv *env, jobject jthis, jlong win, jobject origin,
390+
jobject resultAddr, jlong dataType, jint targetRank, jint targetDisp, jobject jOp, jlong hOp, jint baseType)
391+
{
392+
void *orgPtr = (*env)->GetDirectBufferAddress(env, origin);
393+
void *resultPtr = (*env)->GetDirectBufferAddress(env, resultAddr);
394+
MPI_Op op = ompi_java_op_getHandle(env, jOp, hOp, baseType);
395+
396+
int rc = MPI_Fetch_and_op(orgPtr, resultPtr, dataType, targetRank, targetDisp, op, (MPI_Win)win);
397+
ompi_java_exceptionCheck(env, rc);
398+
}

ompi/mpi/java/java/MPI.java

Lines changed: 5 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
@@ -68,7 +70,7 @@ public final class MPI
6870
public static final int ANY_SOURCE, ANY_TAG;
6971

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

7375
/**
7476
* Global minimum operator.
@@ -241,6 +243,8 @@ public final class MPI
241243
BXOR = new Op(10);
242244
MINLOC = new Op(11);
243245
MAXLOC = new Op(12);
246+
REPLACE = new Op(13);
247+
NO_OP = new Op(14);
244248

245249
GROUP_EMPTY = new Group(Group.getEmpty());
246250
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
@@ -494,4 +494,235 @@ private native long rGet(
494494
int targetRank, int targetDisp, int targetCount, long targetType,
495495
int baseType) throws MPIException;
496496

497+
/**
498+
* Java binding of {@code MPI_RACCUMULATE}.
499+
* @param origin origin buffer
500+
* @param orgCount number of entries in origin buffer
501+
* @param orgType datatype of each entry in origin buffer
502+
* @param targetRank rank of target
503+
* @param targetDisp displacement from start of window to target buffer
504+
* @param targetCount number of entries in target buffer
505+
* @param targetType datatype of each entry in target buffer
506+
* @param op reduce operation
507+
* @return RMA request
508+
* @throws MPIException
509+
*/
510+
public Request rAccumulate(Buffer origin, int orgCount, Datatype orgType,
511+
int targetRank, int targetDisp, int targetCount,
512+
Datatype targetType, Op op)
513+
throws MPIException
514+
{
515+
MPI.check();
516+
517+
if(!origin.isDirect())
518+
throw new IllegalArgumentException("The origin must be direct buffer.");
519+
520+
return new Request(rAccumulate(handle, origin, orgCount, orgType.handle,
521+
targetRank, targetDisp, targetCount, targetType.handle,
522+
op, op.handle, getBaseType(orgType, targetType)));
523+
}
524+
525+
private native long rAccumulate(
526+
long win, Buffer origin, int orgCount, long orgType,
527+
int targetRank, int targetDisp, int targetCount, long targetType,
528+
Op jOp, long hOp, int baseType) throws MPIException;
529+
530+
/**
531+
* Java binding of {@code MPI_GET_ACCUMULATE}.
532+
* @param origin origin buffer
533+
* @param orgCount number of entries in origin buffer
534+
* @param orgType datatype of each entry in origin buffer
535+
* @param resultAddr result buffer
536+
* @param resultCount number of entries in result buffer
537+
* @param resultType datatype of each entry in result buffer
538+
* @param targetRank rank of target
539+
* @param targetDisp displacement from start of window to target buffer
540+
* @param targetCount number of entries in target buffer
541+
* @param targetType datatype of each entry in target buffer
542+
* @param op reduce operation
543+
* @throws MPIException
544+
*/
545+
546+
public void getAccumulate(Buffer origin, int orgCount, Datatype orgType,
547+
Buffer resultAddr, int resultCount, Datatype resultType,
548+
int targetRank, int targetDisp, int targetCount,
549+
Datatype targetType, Op op)
550+
throws MPIException
551+
{
552+
MPI.check();
553+
554+
if(!origin.isDirect())
555+
throw new IllegalArgumentException("The origin must be direct buffer.");
556+
557+
getAccumulate(handle, origin, orgCount, orgType.handle,
558+
resultAddr, resultCount, resultType.handle,
559+
targetRank, targetDisp, targetCount, targetType.handle,
560+
op, op.handle, getBaseType(orgType, targetType));
561+
}
562+
563+
private native void getAccumulate(
564+
long win, Buffer origin, int orgCount, long orgType,
565+
Buffer resultAddr, int resultCount, long resultType,
566+
int targetRank, int targetDisp, int targetCount, long targetType,
567+
Op jOp, long hOp, int baseType) throws MPIException;
568+
569+
/**
570+
* Java binding of {@code MPI_RGET_ACCUMULATE}.
571+
* @param origin origin buffer
572+
* @param orgCount number of entries in origin buffer
573+
* @param orgType datatype of each entry in origin buffer
574+
* @param resultAddr result buffer
575+
* @param resultCount number of entries in result buffer
576+
* @param resultType datatype of each entry in result buffer
577+
* @param targetRank rank of target
578+
* @param targetDisp displacement from start of window to target buffer
579+
* @param targetCount number of entries in target buffer
580+
* @param targetType datatype of each entry in target buffer
581+
* @param op reduce operation
582+
* @return RMA request
583+
* @throws MPIException
584+
*/
585+
586+
public Request rGetAccumulate(Buffer origin, int orgCount, Datatype orgType,
587+
Buffer resultAddr, int resultCount, Datatype resultType,
588+
int targetRank, int targetDisp, int targetCount,
589+
Datatype targetType, Op op)
590+
throws MPIException
591+
{
592+
MPI.check();
593+
594+
if(!origin.isDirect())
595+
throw new IllegalArgumentException("The origin must be direct buffer.");
596+
597+
return new Request(rGetAccumulate(handle, origin, orgCount, orgType.handle,
598+
resultAddr, resultCount, resultType.handle,
599+
targetRank, targetDisp, targetCount, targetType.handle,
600+
op, op.handle, getBaseType(orgType, targetType)));
601+
}
602+
603+
private native long rGetAccumulate(
604+
long win, Buffer origin, int orgCount, long orgType,
605+
Buffer resultAddr, int resultCount, long resultType,
606+
int targetRank, int targetDisp, int targetCount, long targetType,
607+
Op jOp, long hOp, int baseType) throws MPIException;
608+
609+
/**
610+
* Java binding of the MPI operation {@code MPI_WIN_LOCK_ALL}.
611+
* @param assertion program assertion
612+
* @throws MPIException
613+
*/
614+
public void lockAll(int assertion) throws MPIException
615+
{
616+
MPI.check();
617+
lockAll(handle, assertion);
618+
}
619+
620+
private native void lockAll(long win, int assertion)
621+
throws MPIException;
622+
623+
/**
624+
* Java binding of the MPI operation {@code MPI_WIN_UNLOCK_ALL}.
625+
* @throws MPIException
626+
*/
627+
public void unlockAll() throws MPIException
628+
{
629+
MPI.check();
630+
unlockAll(handle);
631+
}
632+
633+
private native void unlockAll(long win) throws MPIException;
634+
635+
/**
636+
* Java binding of the MPI operation {@code MPI_WIN_SYNC}.
637+
* @throws MPIException
638+
*/
639+
public void sync() throws MPIException
640+
{
641+
MPI.check();
642+
sync(handle);
643+
}
644+
645+
private native void sync(long win) throws MPIException;
646+
647+
/**
648+
* Java binding of the MPI operation {@code MPI_WIN_FLUSH}.
649+
* @param targetRank rank of target window
650+
* @throws MPIException
651+
*/
652+
public void flush(int targetRank) throws MPIException
653+
{
654+
MPI.check();
655+
flush(handle, targetRank);
656+
}
657+
658+
private native void flush(long win, int targetRank) throws MPIException;
659+
660+
/**
661+
* Java binding of the MPI operation {@code MPI_WIN_FLUSH_ALL}.
662+
* @throws MPIException
663+
*/
664+
public void flushAll() throws MPIException
665+
{
666+
MPI.check();
667+
flushAll(handle);
668+
}
669+
670+
private native void flushAll(long win) throws MPIException;
671+
672+
/**
673+
* Java binding of {@code MPI_COMPARE_AND_SWAP}.
674+
* @param origin origin buffer
675+
* @param compareAddr compare buffer
676+
* @param resultAddr result buffer
677+
* @param targetType datatype of each entry in target buffer
678+
* @param targetRank rank of target
679+
* @param targetDisp displacement from start of window to target buffer
680+
* @throws MPIException
681+
*/
682+
683+
public void compareAndSwap(Buffer origin, Buffer compareAddr, Buffer resultAddr,
684+
Datatype targetType, int targetRank, int targetDisp)
685+
throws MPIException
686+
{
687+
MPI.check();
688+
689+
if(!origin.isDirect())
690+
throw new IllegalArgumentException("The origin must be direct buffer.");
691+
692+
compareAndSwap(handle, origin, compareAddr, resultAddr,
693+
targetType.handle, targetRank, targetDisp);
694+
}
695+
696+
private native void compareAndSwap(
697+
long win, Buffer origin, Buffer compareAddr, Buffer resultAddr,
698+
long targetType, int targetRank, int targetDisp) throws MPIException;
699+
700+
/**
701+
* Java binding of {@code MPI_FETCH_AND_OP}.
702+
* @param origin origin buffer
703+
* @param resultAddr result buffer
704+
* @param dataType datatype of entry in origin, result, and target buffers
705+
* @param targetRank rank of target
706+
* @param targetDisp displacement from start of window to target buffer
707+
* @param op reduce operation
708+
* @throws MPIException
709+
*/
710+
711+
public void fetchAndOp(Buffer origin, Buffer resultAddr, Datatype dataType,
712+
int targetRank, int targetDisp, Op op)
713+
throws MPIException
714+
{
715+
MPI.check();
716+
717+
if(!origin.isDirect())
718+
throw new IllegalArgumentException("The origin must be direct buffer.");
719+
720+
fetchAndOp(handle, origin, resultAddr, dataType.handle, targetRank,
721+
targetDisp, op, op.handle, getBaseType(dataType, dataType)); //neccessary?
722+
}
723+
724+
private native void fetchAndOp(
725+
long win, Buffer origin, Buffer resultAddr, long targetType, int targetRank,
726+
int targetDisp, Op jOp, long hOp, int baseType) throws MPIException;
727+
497728
} // Win

0 commit comments

Comments
 (0)