Skip to content

Commit f95ed2e

Browse files
committed
Merge pull request open-mpi#410 from nrgraham23/more_one_sided_java_bindings
More one sided java bindings.
2 parents 918650a + 5fab513 commit f95ed2e

File tree

5 files changed

+202
-1
lines changed

5 files changed

+202
-1
lines changed

ompi/mpi/java/c/mpi_Intracomm.c

Lines changed: 11 additions & 0 deletions
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,6 +70,15 @@ JNIEXPORT jlong JNICALL Java_mpi_Intracomm_split(
6870
return (jlong)newcomm;
6971
}
7072

73+
JNIEXPORT jlong JNICALL Java_mpi_Intracomm_splitType(
74+
JNIEnv *env, jobject jthis, jlong comm, jint splitType, jint key, jlong info)
75+
{
76+
MPI_Comm newcomm;
77+
int rc = MPI_Comm_split_type((MPI_Comm)comm, splitType, key, (MPI_Info)info, &newcomm);
78+
ompi_java_exceptionCheck(env, rc);
79+
return (jlong)newcomm;
80+
}
81+
7182
JNIEXPORT jlong JNICALL Java_mpi_Intracomm_create(
7283
JNIEnv *env, jobject jthis, jlong comm, jlong group)
7384
{

ompi/mpi/java/c/mpi_Win.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,66 @@ JNIEXPORT jlong JNICALL Java_mpi_Win_createWin(
4141
return (jlong)win;
4242
}
4343

44+
JNIEXPORT jlong JNICALL Java_mpi_Win_allocateWin(JNIEnv *env, jobject jthis,
45+
jint size, jint dispUnit, jlong info, jlong comm, jobject jBase)
46+
{
47+
void *basePtr = (*env)->GetDirectBufferAddress(env, jBase);
48+
MPI_Win win;
49+
50+
int rc = MPI_Win_allocate((MPI_Aint)size, dispUnit,
51+
(MPI_Info)info, (MPI_Comm)comm, basePtr, &win);
52+
53+
ompi_java_exceptionCheck(env, rc);
54+
return (jlong)win;
55+
}
56+
57+
JNIEXPORT jlong JNICALL Java_mpi_Win_allocateSharedWin(JNIEnv *env, jobject jthis,
58+
jint size, jint dispUnit, jlong info, jlong comm, jobject jBase)
59+
{
60+
void *basePtr = (*env)->GetDirectBufferAddress(env, jBase);
61+
MPI_Win win;
62+
63+
int rc = MPI_Win_allocate_shared((MPI_Aint)size, dispUnit,
64+
(MPI_Info)info, (MPI_Comm)comm, basePtr, &win);
65+
66+
ompi_java_exceptionCheck(env, rc);
67+
return (jlong)win;
68+
}
69+
70+
JNIEXPORT jlong JNICALL Java_mpi_Win_createDynamicWin(
71+
JNIEnv *env, jobject jthis,
72+
jlong info, jlong comm)
73+
{
74+
MPI_Win win;
75+
76+
int rc = MPI_Win_create_dynamic(
77+
(MPI_Info)info, (MPI_Comm)comm, &win);
78+
79+
ompi_java_exceptionCheck(env, rc);
80+
return (jlong)win;
81+
}
82+
83+
JNIEXPORT void JNICALL Java_mpi_Win_attach(
84+
JNIEnv *env, jobject jthis, jlong win, jobject jBase,
85+
jint size)
86+
{
87+
void *base = (*env)->GetDirectBufferAddress(env, jBase);
88+
89+
int rc = MPI_Win_attach((MPI_Win)win, base, (MPI_Aint)size);
90+
91+
ompi_java_exceptionCheck(env, rc);
92+
}
93+
94+
JNIEXPORT void JNICALL Java_mpi_Win_detach(
95+
JNIEnv *env, jobject jthis, jlong win, jobject jBase)
96+
{
97+
void *base = (*env)->GetDirectBufferAddress(env, jBase);
98+
99+
int rc = MPI_Win_detach((MPI_Win)win, base);
100+
101+
ompi_java_exceptionCheck(env, rc);
102+
}
103+
44104
JNIEXPORT jlong JNICALL Java_mpi_Win_getGroup(
45105
JNIEnv *env, jobject jthis, jlong win)
46106
{
@@ -396,3 +456,15 @@ JNIEXPORT void JNICALL Java_mpi_Win_fetchAndOp(JNIEnv *env, jobject jthis, jlong
396456
int rc = MPI_Fetch_and_op(orgPtr, resultPtr, dataType, targetRank, targetDisp, op, (MPI_Win)win);
397457
ompi_java_exceptionCheck(env, rc);
398458
}
459+
460+
JNIEXPORT void JNICALL Java_mpi_Win_flushLocal(JNIEnv *env, jobject jthis, jlong win, jint targetRank)
461+
{
462+
int rc = MPI_Win_flush_local(targetRank, (MPI_Win)win);
463+
ompi_java_exceptionCheck(env, rc);
464+
}
465+
466+
JNIEXPORT void JNICALL Java_mpi_Win_flushLocalAll(JNIEnv *env, jobject jthis, jlong win)
467+
{
468+
int rc = MPI_Win_flush_local_all((MPI_Win)win);
469+
ompi_java_exceptionCheck(env, rc);
470+
}

ompi/mpi/java/java/Comm.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
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 Research Organization for Information Science
13+
* and Technology (RIST). All rights reserved.
14+
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
15+
* reserved.
1216
* $COPYRIGHT$
1317
*
1418
* Additional copyrights may follow
@@ -63,6 +67,7 @@
6367
*/
6468
public class Comm implements Freeable
6569
{
70+
public final static int TYPE_SHARED = 0;
6671
protected final static int SELF = 1;
6772
protected final static int WORLD = 2;
6873
protected long handle;

ompi/mpi/java/java/Intracomm.java

Lines changed: 20 additions & 0 deletions
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
@@ -139,6 +141,24 @@ public final Intracomm split(int colour, int key) throws MPIException
139141

140142
private native long split(long comm, int colour, int key) throws MPIException;
141143

144+
/**
145+
* Partition the group associated with this communicator and create
146+
* a new communicator within each subgroup.
147+
* <p>Java binding of the MPI operation {@code MPI_COMM_SPLIT_TYPE}.
148+
* @param splitType type of processes to be grouped together
149+
* @param key control of rank assignment
150+
* @param info info argument
151+
* @return new communicator
152+
* @throws MPIException
153+
*/
154+
public final Intracomm splitType(int splitType, int key, Info info) throws MPIException
155+
{
156+
MPI.check();
157+
return new Intracomm(splitType(handle, splitType, key, info.handle));
158+
}
159+
160+
private native long splitType(long comm, int colour, int key, long info) throws MPIException;
161+
142162
/**
143163
* Create a new communicator.
144164
* <p>Java binding of the MPI operation {@code MPI_COMM_CREATE}.

ompi/mpi/java/java/Win.java

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
public final class Win implements Freeable
2727
{
2828
private long handle;
29+
public static final int WIN_NULL = 0;
30+
public static final int FLAVOR_PRIVATE = 0;
31+
public static final int FLAVOR_SHARED = 1;
2932

3033
/**
3134
* Java binding of {@code MPI_WIN_CREATE}.
@@ -65,6 +68,69 @@ private native long createWin(
6568
Buffer base, int size, int dispUnit, long info, long comm)
6669
throws MPIException;
6770

71+
/**
72+
* Java binding of {@code MPI_WIN_ALLOCATE} and {@code MPI_WIN_ALLOCATE_SHARED}.
73+
* @param size size of window (buffer elements)
74+
* @param dispUnit local unit size for displacements (buffer elements)
75+
* @param info info object
76+
* @param comm communicator
77+
* @param base initial address of window
78+
* @param flavor FLAVOR_PRIVATE or FLAVOR_SHARED
79+
* @throws MPIException
80+
*/
81+
public Win(int size, int dispUnit, Info info, Comm comm, Buffer base, int flavor)
82+
throws MPIException
83+
{
84+
if(!base.isDirect())
85+
throw new IllegalArgumentException("The buffer must be direct.");
86+
87+
int baseSize;
88+
89+
if(base instanceof ByteBuffer)
90+
baseSize = 1;
91+
else if(base instanceof CharBuffer || base instanceof ShortBuffer)
92+
baseSize = 2;
93+
else if(base instanceof IntBuffer || base instanceof FloatBuffer)
94+
baseSize = 4;
95+
else if(base instanceof LongBuffer || base instanceof DoubleBuffer)
96+
baseSize = 8;
97+
else
98+
throw new AssertionError();
99+
100+
int sizeBytes = size * baseSize,
101+
dispBytes = dispUnit * baseSize;
102+
103+
if(flavor == 0) {
104+
handle = allocateWin(sizeBytes, dispBytes, info.handle, comm.handle, base);
105+
} else if(flavor == 1) {
106+
handle = allocateSharedWin(sizeBytes, dispBytes, info.handle, comm.handle, base);
107+
}
108+
}
109+
110+
private native long allocateWin(
111+
int size, int dispUnit, long info, long comm, Buffer base)
112+
throws MPIException;
113+
114+
private native long allocateSharedWin(
115+
int size, int dispUnit, long info, long comm, Buffer base)
116+
throws MPIException;
117+
118+
/**
119+
* Java binding of {@code MPI_WIN_CREATE_DYNAMIC}.
120+
* @param info info object
121+
* @param comm communicator
122+
* @throws MPIException
123+
*/
124+
public Win(Info info, Comm comm)
125+
throws MPIException
126+
{
127+
handle = createDynamicWin(info.handle, comm.handle);
128+
}
129+
130+
private native long createDynamicWin(
131+
long info, long comm)
132+
throws MPIException;
133+
68134
private int getBaseType(Datatype orgType, Datatype targetType)
69135
{
70136
int baseType = orgType.baseType;
@@ -718,11 +784,38 @@ public void fetchAndOp(Buffer origin, Buffer resultAddr, Datatype dataType,
718784
throw new IllegalArgumentException("The origin must be direct buffer.");
719785

720786
fetchAndOp(handle, origin, resultAddr, dataType.handle, targetRank,
721-
targetDisp, op, op.handle, getBaseType(dataType, dataType)); //neccessary?
787+
targetDisp, op, op.handle, getBaseType(dataType, dataType));
722788
}
723789

724790
private native void fetchAndOp(
725791
long win, Buffer origin, Buffer resultAddr, long targetType, int targetRank,
726792
int targetDisp, Op jOp, long hOp, int baseType) throws MPIException;
727793

794+
/**
795+
* Java binding of the MPI operation {@code MPI_WIN_FLUSH_LOCAL}.
796+
* @param targetRank rank of target window
797+
* @throws MPIException
798+
*/
799+
800+
public void flushLocal(int targetRank) throws MPIException
801+
{
802+
MPI.check();
803+
flushLocal(handle, targetRank);
804+
}
805+
806+
private native void flushLocal(long win, int targetRank) throws MPIException;
807+
808+
/**
809+
* Java binding of the MPI operation {@code MPI_WIN_FLUSH_LOCAL_ALL}.
810+
* @throws MPIException
811+
*/
812+
813+
public void flushLocalAll() throws MPIException
814+
{
815+
MPI.check();
816+
flushLocalAll(handle);
817+
}
818+
819+
private native void flushLocalAll(long win) throws MPIException;
820+
728821
} // Win

0 commit comments

Comments
 (0)