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

@ -16,11 +16,19 @@ public class JNoa {
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

@ -8,3 +8,15 @@ 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())
}
}