-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interface.java
95 lines (83 loc) · 3.06 KB
/
Interface.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package jfftw;
public class Interface {
protected static boolean libsLoaded = false, threadsLoaded = false;
protected static synchronized native void jfftw_cleanup();
protected static synchronized native void jfftw_cleanup_threads();
protected static synchronized native boolean jfftw_init_threads();
protected static synchronized native void jfftw_make_planner_thread_safe();
protected static synchronized native void jfftw_plan_with_nthreads(int nthreads);
protected static synchronized native void jfftw_set_timelimit(double t);
/**
* Cleans up FFTW internal state as if the program just began.
*/
public static void cleanup() {
jfftw_cleanup();
}
/**
* Use to get rid of all memory and other resources allocated internally by FFTW.
* <p>
* You must not execute any previously created plans after calling this function.
*/
public static void cleanupThreads() {
jfftw_cleanup_threads();
}
/**
* This function, which need only be called once, performs any one-time
* initialization required to use threads on your system.
* <p>
* You may also specify the name of the FFTW native library (if any) which handles
* threads. If your FFTW threads library is built in to the main FFTW library,
* you may pass `null` in for this argument.
*
* @param lib name of the FFTW native library responsible for threads
* @return true if threads loaded successfully, false otherwise
*/
public static boolean initThreads(String lib) {
if (!threadsLoaded) {
if (lib != null)
System.loadLibrary(lib);
threadsLoaded = jfftw_init_threads();
}
return threadsLoaded;
}
/**
* Installs a hook that wraps a lock (chosen by FFTW) around all planner calls.
* <p>
* This method should be used only as a last resort or in situations where you
* cannot control other programs which may be creating plans concurrently.
*/
public static void makePlannerThreadSafe() {
jfftw_make_planner_thread_safe();
}
/**
* Specifies a number of threads to use in planning.
*
* @param nthreads number of threads
*/
public static void planWithNThreads(int nthreads) {
jfftw_plan_with_nthreads(nthreads);
}
/**
* Sets a rough timelimit for planning.
*
* @param t time in seconds
*/
public static void setTimelimit(double t) {
jfftw_set_timelimit(t);
}
/**
* Loads the native FFTW and JFFTW libraries.
* <p>
* These native libraries must be in the JVM's java.library.path directory.
*
* @param fftw name of the FFTW library
* @param jfftw name of the JFFTW library
*/
public static void loadLibraries(String fftw, String jfftw) {
if (!libsLoaded) {
System.loadLibrary(fftw);
System.loadLibrary(jfftw);
libsLoaded = true;
}
}
}