Skip to content

Commit 1631ad7

Browse files
committed
Merge pull request #740 from nrgraham23/environment_java_bindings
Java Environment Variable Bindings
2 parents 93f7a51 + a1b47a3 commit 1631ad7

File tree

5 files changed

+126
-0
lines changed

5 files changed

+126
-0
lines changed

ompi/mpi/java/c/mpiJava.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ typedef struct {
3131
jmethodID CartParmsInit;
3232
jclass ShiftParmsClass;
3333
jmethodID ShiftParmsInit;
34+
jclass VersionClass;
35+
jmethodID VersionInit;
3436
jclass GraphParmsClass;
3537
jmethodID GraphParmsInit;
3638
jclass DistGraphNeighborsClass;

ompi/mpi/java/c/mpi_MPI.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ static void deleteClasses(JNIEnv *env)
204204
{
205205
(*env)->DeleteGlobalRef(env, ompi_java.CartParmsClass);
206206
(*env)->DeleteGlobalRef(env, ompi_java.ShiftParmsClass);
207+
(*env)->DeleteGlobalRef(env, ompi_java.VersionClass);
207208
(*env)->DeleteGlobalRef(env, ompi_java.GraphParmsClass);
208209
(*env)->DeleteGlobalRef(env, ompi_java.DistGraphNeighborsClass);
209210
(*env)->DeleteGlobalRef(env, ompi_java.StatusClass);
@@ -257,6 +258,12 @@ JNIEXPORT jobject JNICALL Java_mpi_MPI_newDoubleInt(JNIEnv *env, jclass clazz)
257258
return (*env)->NewObject(env, c, m, iOff, sizeof(int));
258259
}
259260

261+
JNIEXPORT void JNICALL Java_mpi_MPI_initVersion(JNIEnv *env, jclass jthis)
262+
{
263+
ompi_java.VersionClass = findClass(env, "mpi/Version");
264+
ompi_java.VersionInit = (*env)->GetMethodID(env, ompi_java.VersionClass, "<init>", "(II)V");
265+
}
266+
260267
JNIEXPORT jobjectArray JNICALL Java_mpi_MPI_Init_1jni(
261268
JNIEnv *env, jclass clazz, jobjectArray argv)
262269
{
@@ -353,6 +360,26 @@ JNIEXPORT void JNICALL Java_mpi_MPI_Finalize_1jni(JNIEnv *env, jclass obj)
353360
deleteClasses(env);
354361
}
355362

363+
JNIEXPORT jobject JNICALL Java_mpi_MPI_getVersionJNI(JNIEnv *env, jclass jthis)
364+
{
365+
int version, subversion;
366+
int rc = MPI_Get_version(&version, &subversion);
367+
ompi_java_exceptionCheck(env, rc);
368+
369+
return (*env)->NewObject(env, ompi_java.VersionClass,
370+
ompi_java.VersionInit, version, subversion);
371+
}
372+
373+
JNIEXPORT jstring JNICALL Java_mpi_MPI_getLibVersionJNI(JNIEnv *env, jclass jthis)
374+
{
375+
int length;
376+
char version[MPI_MAX_LIBRARY_VERSION_STRING];
377+
int rc = MPI_Get_library_version(version, &length);
378+
ompi_java_exceptionCheck(env, rc);
379+
380+
return (*env)->NewStringUTF(env, version);
381+
}
382+
356383
JNIEXPORT jint JNICALL Java_mpi_MPI_getProcessorName(
357384
JNIEnv *env, jclass obj, jbyteArray buf)
358385
{

ompi/mpi/java/java/MPI.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,16 @@ public final class MPI
394394
ERR_WIN = c.ERR_WIN;
395395
ERR_LASTCODE = c.ERR_LASTCODE;
396396
ERR_SYSRESOURCE = c.ERR_SYSRESOURCE;
397+
398+
initVersion();
397399
}
398400

399401
private static native Int2 newInt2();
400402
private static native ShortInt newShortInt();
401403
private static native LongInt newLongInt();
402404
private static native FloatInt newFloatInt();
403405
private static native DoubleInt newDoubleInt();
406+
private static native void initVersion();
404407

405408
private static void initCommon() throws MPIException
406409
{
@@ -538,6 +541,28 @@ public static double wtick() throws MPIException
538541

539542
private static native double wtick_jni();
540543

544+
/**
545+
* Returns a version object representing the version of MPI being used.
546+
* <p>Java binding of the MPI operation {@code MPI_GET_VERSION}.
547+
* @return A version object representing the version and subversion of MPI being used.
548+
*/
549+
public static Version getVersion() {
550+
return getVersionJNI();
551+
}
552+
553+
private static native Version getVersionJNI();
554+
555+
/**
556+
* Returns the version of the MPI Library
557+
* <p>Java binding of the MPI operation {@code MPI_GET_LIBRARY_VERSION}.
558+
* @return A string representation of the MPI Library
559+
*/
560+
public static String getLibVersion() {
561+
return getLibVersionJNI();
562+
}
563+
564+
private static native String getLibVersionJNI();
565+
541566
/**
542567
* Returns the name of the processor on which it is called.
543568
* <p>Java binding of the MPI operation {@code MPI_GET_PROCESSOR_NAME}.

ompi/mpi/java/java/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# -*- makefile -*-
22
#
33
# Copyright (c) 2011-2014 Cisco Systems, Inc. All rights reserved.
4+
# Copyright (c) 2015 Los Alamos National Security, LLC. All rights
5+
# reserved.
46
# $COPYRIGHT$
57
#
68
# Additional copyrights may follow
@@ -56,6 +58,7 @@ JAVA_SRC_FILES = \
5658
Status.java \
5759
Struct.java \
5860
UserFunction.java \
61+
Version.java \
5962
Win.java
6063

6164
EXTRA_DIST = $(JAVA_SRC_FILES)
@@ -88,6 +91,7 @@ JAVA_H = \
8891
mpi_Request.h \
8992
mpi_ShiftParms.h \
9093
mpi_Status.h \
94+
mpi_Version.h \
9195
mpi_Win.h
9296

9397
# A little verbosity magic; see Makefile.ompi-rules for an explanation.

ompi/mpi/java/java/Version.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
3+
* reserved.
4+
* $COPYRIGHT$
5+
*
6+
* Additional copyrights may follow
7+
*
8+
* $HEADER$
9+
*
10+
*
11+
* This file is almost a complete re-write for Open MPI compared to the
12+
* original mpiJava package. Its license and copyright are listed below.
13+
* See <path to ompi/mpi/java/README> for more information.
14+
*
15+
*
16+
* Licensed under the Apache License, Version 2.0 (the "License");
17+
* you may not use this file except in compliance with the License.
18+
* You may obtain a copy of the License at
19+
*
20+
* http://www.apache.org/licenses/LICENSE-2.0
21+
*
22+
* Unless required by applicable law or agreed to in writing, software
23+
* distributed under the License is distributed on an "AS IS" BASIS,
24+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25+
* See the License for the specific language governing permissions and
26+
* limitations under the License.
27+
*
28+
*
29+
* File : Version.java
30+
* Author : Nathaniel Graham
31+
* Created : Thu Jul 23 09:25 2015
32+
*/
33+
34+
package mpi;
35+
36+
/**
37+
* Version and Subversion for MPI
38+
*/
39+
public final class Version
40+
{
41+
private final int version;
42+
private final int subVersion;
43+
44+
protected Version(int version, int subVersion)
45+
{
46+
this.version = version;
47+
this.subVersion = subVersion;
48+
}
49+
50+
/**
51+
* Gets the MPI version.
52+
* @return MPI version
53+
*/
54+
public int getVersion()
55+
{
56+
return version;
57+
}
58+
59+
/**
60+
* Gets the MPI subversion.
61+
* @return MPI subversion
62+
*/
63+
public int getSubVersion()
64+
{
65+
return subVersion;
66+
}
67+
68+
} // Version

0 commit comments

Comments
 (0)