From 7f6d141bd6e701509d5fe26866e82848caf49ea6 Mon Sep 17 00:00:00 2001 From: Nathaniel Graham Date: Thu, 9 Jul 2015 16:22:47 -0600 Subject: [PATCH] More one sided java bindings. Bindings for the MPI_WIN_FLUSH_LOCAL, MPI_WIN_FLUSH_LOCAL_ALL, MPI_WIN_ALLOCATE, MPI_WIN_ALLOCATE_SHARED, and MPI_COMM_SPLIT_TYPE. Also added several necessary constants. Signed-off-by: Nathaniel Graham ngraham@lanl.gov --- ompi/mpi/java/c/mpi_Intracomm.c | 11 +++++ ompi/mpi/java/c/mpi_Win.c | 38 +++++++++++++++ ompi/mpi/java/java/Comm.java | 3 ++ ompi/mpi/java/java/Intracomm.java | 20 ++++++++ ompi/mpi/java/java/Win.java | 79 ++++++++++++++++++++++++++++++- 5 files changed, 150 insertions(+), 1 deletion(-) diff --git a/ompi/mpi/java/c/mpi_Intracomm.c b/ompi/mpi/java/c/mpi_Intracomm.c index 6eab6cbbf0d..0e8d5b6d9b6 100644 --- a/ompi/mpi/java/c/mpi_Intracomm.c +++ b/ompi/mpi/java/c/mpi_Intracomm.c @@ -9,6 +9,8 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2015 Los Alamos National Security, LLC. All rights + * reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -66,6 +68,15 @@ JNIEXPORT jlong JNICALL Java_mpi_Intracomm_split( return (jlong)newcomm; } +JNIEXPORT jlong JNICALL Java_mpi_Intracomm_splitType( + JNIEnv *env, jobject jthis, jlong comm, jint splitType, jint key, jlong info) +{ + MPI_Comm newcomm; + int rc = MPI_Comm_split_type((MPI_Comm)comm, splitType, key, (MPI_Info)info, &newcomm); + ompi_java_exceptionCheck(env, rc); + return (jlong)newcomm; +} + JNIEXPORT jlong JNICALL Java_mpi_Intracomm_create( JNIEnv *env, jobject jthis, jlong comm, jlong group) { diff --git a/ompi/mpi/java/c/mpi_Win.c b/ompi/mpi/java/c/mpi_Win.c index e886cd40438..1645f85c5d9 100644 --- a/ompi/mpi/java/c/mpi_Win.c +++ b/ompi/mpi/java/c/mpi_Win.c @@ -45,6 +45,32 @@ JNIEXPORT jlong JNICALL Java_mpi_Win_createWin( return (jlong)win; } +JNIEXPORT jlong JNICALL Java_mpi_Win_allocateWin(JNIEnv *env, jobject jthis, + jint size, jint dispUnit, jlong info, jlong comm, jobject jBase) +{ + void *basePtr = (*env)->GetDirectBufferAddress(env, jBase); + MPI_Win win; + + int rc = MPI_Win_allocate((MPI_Aint)size, dispUnit, + (MPI_Info)info, (MPI_Comm)comm, basePtr, &win); + + ompi_java_exceptionCheck(env, rc); + return (jlong)win; +} + +JNIEXPORT jlong JNICALL Java_mpi_Win_allocateSharedWin(JNIEnv *env, jobject jthis, + jint size, jint dispUnit, jlong info, jlong comm, jobject jBase) +{ + void *basePtr = (*env)->GetDirectBufferAddress(env, jBase); + MPI_Win win; + + int rc = MPI_Win_allocate_shared((MPI_Aint)size, dispUnit, + (MPI_Info)info, (MPI_Comm)comm, basePtr, &win); + + ompi_java_exceptionCheck(env, rc); + return (jlong)win; +} + JNIEXPORT jlong JNICALL Java_mpi_Win_createDynamicWin( JNIEnv *env, jobject jthis, jlong info, jlong comm) @@ -434,3 +460,15 @@ JNIEXPORT void JNICALL Java_mpi_Win_fetchAndOp(JNIEnv *env, jobject jthis, jlong int rc = MPI_Fetch_and_op(orgPtr, resultPtr, dataType, targetRank, targetDisp, op, (MPI_Win)win); ompi_java_exceptionCheck(env, rc); } + +JNIEXPORT void JNICALL Java_mpi_Win_flushLocal(JNIEnv *env, jobject jthis, jlong win, jint targetRank) +{ + int rc = MPI_Win_flush_local(targetRank, (MPI_Win)win); + ompi_java_exceptionCheck(env, rc); +} + +JNIEXPORT void JNICALL Java_mpi_Win_flushLocalAll(JNIEnv *env, jobject jthis, jlong win) +{ + int rc = MPI_Win_flush_local_all((MPI_Win)win); + ompi_java_exceptionCheck(env, rc); +} diff --git a/ompi/mpi/java/java/Comm.java b/ompi/mpi/java/java/Comm.java index 729ffdb985d..e1ecef321b2 100644 --- a/ompi/mpi/java/java/Comm.java +++ b/ompi/mpi/java/java/Comm.java @@ -11,6 +11,8 @@ * All rights reserved. * Copyright (c) 2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. + * Copyright (c) 2015 Los Alamos National Security, LLC. All rights + * reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -65,6 +67,7 @@ */ public class Comm implements Freeable { +public final static int TYPE_SHARED = 0; protected final static int SELF = 1; protected final static int WORLD = 2; protected long handle; diff --git a/ompi/mpi/java/java/Intracomm.java b/ompi/mpi/java/java/Intracomm.java index 41a4d2b8366..e517b90181f 100644 --- a/ompi/mpi/java/java/Intracomm.java +++ b/ompi/mpi/java/java/Intracomm.java @@ -9,6 +9,8 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2015 Los Alamos National Security, LLC. All rights + * reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -139,6 +141,24 @@ public final Intracomm split(int colour, int key) throws MPIException private native long split(long comm, int colour, int key) throws MPIException; +/** + * Partition the group associated with this communicator and create + * a new communicator within each subgroup. + *

Java binding of the MPI operation {@code MPI_COMM_SPLIT_TYPE}. + * @param splitType type of processes to be grouped together + * @param key control of rank assignment + * @param info info argument + * @return new communicator + * @throws MPIException + */ +public final Intracomm splitType(int splitType, int key, Info info) throws MPIException +{ + MPI.check(); + return new Intracomm(splitType(handle, splitType, key, info.handle)); +} + +private native long splitType(long comm, int colour, int key, long info) throws MPIException; + /** * Create a new communicator. *

Java binding of the MPI operation {@code MPI_COMM_CREATE}. diff --git a/ompi/mpi/java/java/Win.java b/ompi/mpi/java/java/Win.java index 36c400a00a8..4923949eedf 100644 --- a/ompi/mpi/java/java/Win.java +++ b/ompi/mpi/java/java/Win.java @@ -30,6 +30,9 @@ public final class Win implements Freeable { private long handle; +public static final int WIN_NULL = 0; +public static final int FLAVOR_PRIVATE = 0; +public static final int FLAVOR_SHARED = 1; /** * Java binding of {@code MPI_WIN_CREATE}. @@ -69,6 +72,53 @@ private native long createWin( Buffer base, int size, int dispUnit, long info, long comm) throws MPIException; +/** + * Java binding of {@code MPI_WIN_ALLOCATE} and {@code MPI_WIN_ALLOCATE_SHARED}. + * @param size size of window (buffer elements) + * @param dispUnit local unit size for displacements (buffer elements) + * @param info info object + * @param comm communicator + * @param base initial address of window + * @param flavor FLAVOR_PRIVATE or FLAVOR_SHARED + * @throws MPIException + */ +public Win(int size, int dispUnit, Info info, Comm comm, Buffer base, int flavor) + throws MPIException +{ + if(!base.isDirect()) + throw new IllegalArgumentException("The buffer must be direct."); + + int baseSize; + + if(base instanceof ByteBuffer) + baseSize = 1; + else if(base instanceof CharBuffer || base instanceof ShortBuffer) + baseSize = 2; + else if(base instanceof IntBuffer || base instanceof FloatBuffer) + baseSize = 4; + else if(base instanceof LongBuffer || base instanceof DoubleBuffer) + baseSize = 8; + else + throw new AssertionError(); + + int sizeBytes = size * baseSize, + dispBytes = dispUnit * baseSize; + + if(flavor == 0) { + handle = allocateWin(sizeBytes, dispBytes, info.handle, comm.handle, base); + } else if(flavor == 1) { + handle = allocateSharedWin(sizeBytes, dispBytes, info.handle, comm.handle, base); + } +} + +private native long allocateWin( + int size, int dispUnit, long info, long comm, Buffer base) + throws MPIException; + +private native long allocateSharedWin( + int size, int dispUnit, long info, long comm, Buffer base) + throws MPIException; + /** * Java binding of {@code MPI_WIN_CREATE_DYNAMIC}. * @param info info object @@ -784,11 +834,38 @@ public void fetchAndOp(Buffer origin, Buffer resultAddr, Datatype dataType, throw new IllegalArgumentException("The origin must be direct buffer."); fetchAndOp(handle, origin, resultAddr, dataType.handle, targetRank, - targetDisp, op, op.handle, getBaseType(dataType, dataType)); //neccessary? + targetDisp, op, op.handle, getBaseType(dataType, dataType)); } private native void fetchAndOp( long win, Buffer origin, Buffer resultAddr, long targetType, int targetRank, int targetDisp, Op jOp, long hOp, int baseType) throws MPIException; +/** + * Java binding of the MPI operation {@code MPI_WIN_FLUSH_LOCAL}. + * @param targetRank rank of target window + * @throws MPIException + */ + +public void flushLocal(int targetRank) throws MPIException +{ + MPI.check(); + flushLocal(handle, targetRank); +} + +private native void flushLocal(long win, int targetRank) throws MPIException; + +/** + * Java binding of the MPI operation {@code MPI_WIN_FLUSH_LOCAL_ALL}. + * @throws MPIException + */ + +public void flushLocalAll() throws MPIException +{ + MPI.check(); + flushLocalAll(handle); +} + +private native void flushLocalAll(long win) throws MPIException; + } // Win