From a1b47a333a54701be89bdd226b3ccedaa477a27e Mon Sep 17 00:00:00 2001 From: Nathaniel Graham Date: Thu, 23 Jul 2015 14:52:01 -0600 Subject: [PATCH] Java Environment Variable Bindings Added the bindings for MPI_GET_VERSION and MPI_GET_LIBRARY_VERSION. Signed-off-by: Nathaniel Graham --- ompi/mpi/java/c/mpiJava.h | 2 + ompi/mpi/java/c/mpi_MPI.c | 27 +++++++++++++ ompi/mpi/java/java/MPI.java | 25 ++++++++++++ ompi/mpi/java/java/Makefile.am | 4 ++ ompi/mpi/java/java/Version.java | 68 +++++++++++++++++++++++++++++++++ 5 files changed, 126 insertions(+) create mode 100644 ompi/mpi/java/java/Version.java diff --git a/ompi/mpi/java/c/mpiJava.h b/ompi/mpi/java/c/mpiJava.h index 4f98a9db62..ecd139bb56 100644 --- a/ompi/mpi/java/c/mpiJava.h +++ b/ompi/mpi/java/c/mpiJava.h @@ -31,6 +31,8 @@ typedef struct { jmethodID CartParmsInit; jclass ShiftParmsClass; jmethodID ShiftParmsInit; + jclass VersionClass; + jmethodID VersionInit; jclass GraphParmsClass; jmethodID GraphParmsInit; jclass DistGraphNeighborsClass; diff --git a/ompi/mpi/java/c/mpi_MPI.c b/ompi/mpi/java/c/mpi_MPI.c index 23e9dd2fec..ae153d4261 100644 --- a/ompi/mpi/java/c/mpi_MPI.c +++ b/ompi/mpi/java/c/mpi_MPI.c @@ -204,6 +204,7 @@ static void deleteClasses(JNIEnv *env) { (*env)->DeleteGlobalRef(env, ompi_java.CartParmsClass); (*env)->DeleteGlobalRef(env, ompi_java.ShiftParmsClass); + (*env)->DeleteGlobalRef(env, ompi_java.VersionClass); (*env)->DeleteGlobalRef(env, ompi_java.GraphParmsClass); (*env)->DeleteGlobalRef(env, ompi_java.DistGraphNeighborsClass); (*env)->DeleteGlobalRef(env, ompi_java.StatusClass); @@ -257,6 +258,12 @@ JNIEXPORT jobject JNICALL Java_mpi_MPI_newDoubleInt(JNIEnv *env, jclass clazz) return (*env)->NewObject(env, c, m, iOff, sizeof(int)); } +JNIEXPORT void JNICALL Java_mpi_MPI_initVersion(JNIEnv *env, jclass jthis) +{ + ompi_java.VersionClass = findClass(env, "mpi/Version"); + ompi_java.VersionInit = (*env)->GetMethodID(env, ompi_java.VersionClass, "", "(II)V"); +} + JNIEXPORT jobjectArray JNICALL Java_mpi_MPI_Init_1jni( JNIEnv *env, jclass clazz, jobjectArray argv) { @@ -353,6 +360,26 @@ JNIEXPORT void JNICALL Java_mpi_MPI_Finalize_1jni(JNIEnv *env, jclass obj) deleteClasses(env); } +JNIEXPORT jobject JNICALL Java_mpi_MPI_getVersionJNI(JNIEnv *env, jclass jthis) +{ + int version, subversion; + int rc = MPI_Get_version(&version, &subversion); + ompi_java_exceptionCheck(env, rc); + + return (*env)->NewObject(env, ompi_java.VersionClass, + ompi_java.VersionInit, version, subversion); +} + +JNIEXPORT jstring JNICALL Java_mpi_MPI_getLibVersionJNI(JNIEnv *env, jclass jthis) +{ + int length; + char version[MPI_MAX_LIBRARY_VERSION_STRING]; + int rc = MPI_Get_library_version(version, &length); + ompi_java_exceptionCheck(env, rc); + + return (*env)->NewStringUTF(env, version); +} + JNIEXPORT jint JNICALL Java_mpi_MPI_getProcessorName( JNIEnv *env, jclass obj, jbyteArray buf) { diff --git a/ompi/mpi/java/java/MPI.java b/ompi/mpi/java/java/MPI.java index 5273c913a0..d8a4ba1243 100644 --- a/ompi/mpi/java/java/MPI.java +++ b/ompi/mpi/java/java/MPI.java @@ -394,6 +394,8 @@ static ERR_WIN = c.ERR_WIN; ERR_LASTCODE = c.ERR_LASTCODE; ERR_SYSRESOURCE = c.ERR_SYSRESOURCE; + + initVersion(); } private static native Int2 newInt2(); @@ -401,6 +403,7 @@ private static native ShortInt newShortInt(); private static native LongInt newLongInt(); private static native FloatInt newFloatInt(); private static native DoubleInt newDoubleInt(); +private static native void initVersion(); private static void initCommon() throws MPIException { @@ -538,6 +541,28 @@ public static double wtick() throws MPIException private static native double wtick_jni(); +/** + * Returns a version object representing the version of MPI being used. + *

Java binding of the MPI operation {@code MPI_GET_VERSION}. + * @return A version object representing the version and subversion of MPI being used. + */ +public static Version getVersion() { + return getVersionJNI(); +} + +private static native Version getVersionJNI(); + +/** + * Returns the version of the MPI Library + *

Java binding of the MPI operation {@code MPI_GET_LIBRARY_VERSION}. + * @return A string representation of the MPI Library + */ +public static String getLibVersion() { + return getLibVersionJNI(); +} + +private static native String getLibVersionJNI(); + /** * Returns the name of the processor on which it is called. *

Java binding of the MPI operation {@code MPI_GET_PROCESSOR_NAME}. diff --git a/ompi/mpi/java/java/Makefile.am b/ompi/mpi/java/java/Makefile.am index 715a1364e3..4f62aa06c1 100644 --- a/ompi/mpi/java/java/Makefile.am +++ b/ompi/mpi/java/java/Makefile.am @@ -1,6 +1,8 @@ # -*- makefile -*- # # Copyright (c) 2011-2014 Cisco Systems, Inc. All rights reserved. +# Copyright (c) 2015 Los Alamos National Security, LLC. All rights +# reserved. # $COPYRIGHT$ # # Additional copyrights may follow @@ -56,6 +58,7 @@ JAVA_SRC_FILES = \ Status.java \ Struct.java \ UserFunction.java \ + Version.java \ Win.java EXTRA_DIST = $(JAVA_SRC_FILES) @@ -88,6 +91,7 @@ JAVA_H = \ mpi_Request.h \ mpi_ShiftParms.h \ mpi_Status.h \ + mpi_Version.h \ mpi_Win.h # A little verbosity magic; see Makefile.ompi-rules for an explanation. diff --git a/ompi/mpi/java/java/Version.java b/ompi/mpi/java/java/Version.java new file mode 100644 index 0000000000..e63911210d --- /dev/null +++ b/ompi/mpi/java/java/Version.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2015 Los Alamos National Security, LLC. All rights + * reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + * + * + * This file is almost a complete re-write for Open MPI compared to the + * original mpiJava package. Its license and copyright are listed below. + * See for more information. + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + * File : Version.java + * Author : Nathaniel Graham + * Created : Thu Jul 23 09:25 2015 + */ + +package mpi; + +/** + * Version and Subversion for MPI + */ +public final class Version +{ +private final int version; +private final int subVersion; + +protected Version(int version, int subVersion) +{ + this.version = version; + this.subVersion = subVersion; +} + +/** + * Gets the MPI version. + * @return MPI version + */ +public int getVersion() +{ + return version; +} + +/** + * Gets the MPI subversion. + * @return MPI subversion + */ +public int getSubVersion() +{ + return subVersion; +} + +} // Version