threads setting

This commit is contained in:
Roland Grinis 2021-07-06 19:10:13 +01:00
parent e17fe32ae2
commit cadcb9916f
4 changed files with 54 additions and 3 deletions

View File

@ -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);
}

View File

@ -7,4 +7,16 @@ package space.kscience.kmath.noa
public fun cudaAvailable(): Boolean {
return JNoa.cudaIsAvailable()
}
}
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)
}

View File

@ -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

View File

@ -19,4 +19,11 @@ class TestUtils {
}
assertEquals(i, 10)
}
@Test
fun settingNumThreads(){
val numThreads = 2
setNumThreads(numThreads)
assertEquals(numThreads, getNumThreads())
}
}