diff --git a/kmath-noa/src/main/java/space/kscience/kmath/noa/JNoa.java b/kmath-noa/src/main/java/space/kscience/kmath/noa/JNoa.java index a38de844e..91396285b 100644 --- a/kmath-noa/src/main/java/space/kscience/kmath/noa/JNoa.java +++ b/kmath-noa/src/main/java/space/kscience/kmath/noa/JNoa.java @@ -10,17 +10,25 @@ public class JNoa { static { String jNoaPath = System.getProperty("user.home") + "/devspace/noa/cmake-build-release/kmath/libjnoa.so"; - //"/.konan/third-party/kmath-noa-0.3.0-dev-14/cpp-build/kmath/libjnoa.so"; + //"/.konan/third-party/kmath-noa-0.3.0-dev-14/cpp-build/kmath/libjnoa.so"; try { System.load(jNoaPath); } catch (UnsatisfiedLinkError e) { System.err.println("Failed to load native NOA library from:\n" + - jNoaPath +"\n" + e); + jNoaPath + "\n" + e); System.exit(1); } } public static native int testException(int seed); + public static native boolean cudaIsAvailable(); + + public static native int getNumThreads(); + + public static native void setNumThreads(int numThreads); + + public static native void setSeed(int seed); } + diff --git a/kmath-noa/src/main/kotlin/space/kscience/kmath/noa/utils.kt b/kmath-noa/src/main/kotlin/space/kscience/kmath/noa/utils.kt index 95cebab6b..853e5debf 100644 --- a/kmath-noa/src/main/kotlin/space/kscience/kmath/noa/utils.kt +++ b/kmath-noa/src/main/kotlin/space/kscience/kmath/noa/utils.kt @@ -7,4 +7,16 @@ package space.kscience.kmath.noa public fun cudaAvailable(): Boolean { return JNoa.cudaIsAvailable() -} \ No newline at end of file +} + +public fun getNumThreads(): Int { + return JNoa.getNumThreads() +} + +public fun setNumThreads(numThreads: Int): Unit { + JNoa.setNumThreads(numThreads) +} + +public fun setSeed(seed: Int): Unit { + JNoa.setSeed(seed) +} diff --git a/kmath-noa/src/main/resources/space_kscience_kmath_noa_JNoa.h b/kmath-noa/src/main/resources/space_kscience_kmath_noa_JNoa.h index 465e67e6a..fb7480fa5 100644 --- a/kmath-noa/src/main/resources/space_kscience_kmath_noa_JNoa.h +++ b/kmath-noa/src/main/resources/space_kscience_kmath_noa_JNoa.h @@ -23,6 +23,30 @@ JNIEXPORT jint JNICALL Java_space_kscience_kmath_noa_JNoa_testException JNIEXPORT jboolean JNICALL Java_space_kscience_kmath_noa_JNoa_cudaIsAvailable (JNIEnv *, jclass); +/* + * Class: space_kscience_kmath_noa_JNoa + * Method: getNumThreads + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_space_kscience_kmath_noa_JNoa_getNumThreads + (JNIEnv *, jclass); + +/* + * Class: space_kscience_kmath_noa_JNoa + * Method: setNumThreads + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_space_kscience_kmath_noa_JNoa_setNumThreads + (JNIEnv *, jclass, jint); + +/* + * Class: space_kscience_kmath_noa_JNoa + * Method: setSeed + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_space_kscience_kmath_noa_JNoa_setSeed + (JNIEnv *, jclass, jint); + #ifdef __cplusplus } #endif diff --git a/kmath-noa/src/test/kotlin/space/kscience/kmath/noa/TestUtils.kt b/kmath-noa/src/test/kotlin/space/kscience/kmath/noa/TestUtils.kt index e5f142b3c..6b8386b8d 100644 --- a/kmath-noa/src/test/kotlin/space/kscience/kmath/noa/TestUtils.kt +++ b/kmath-noa/src/test/kotlin/space/kscience/kmath/noa/TestUtils.kt @@ -19,4 +19,11 @@ class TestUtils { } assertEquals(i, 10) } + + @Test + fun settingNumThreads(){ + val numThreads = 2 + setNumThreads(numThreads) + assertEquals(numThreads, getNumThreads()) + } } \ No newline at end of file