diff --git a/src/main/java/com/aparapi/internal/kernel/KernelRunner.java b/src/main/java/com/aparapi/internal/kernel/KernelRunner.java index 25975a2a..875abfc0 100644 --- a/src/main/java/com/aparapi/internal/kernel/KernelRunner.java +++ b/src/main/java/com/aparapi/internal/kernel/KernelRunner.java @@ -155,8 +155,10 @@ public class KernelRunner extends KernelRunnerJNI{ final private ThreadDiedHandler handler = new ThreadDiedHandler(); //Allow a thread pool per KernelRunner which will also be per Kernel instance - private final ForkJoinPool threadPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), + private ForkJoinPool threadPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), lowPriorityThreadFactory, handler, false); + private static ForkJoinPool commonPoolResource=null; + private static boolean useStaticPool = true; private static HashMap, String> openCLCache = new HashMap<>(); private static LinkedHashSet seenBinaryKeys = new LinkedHashSet<>(); @@ -781,7 +783,7 @@ public void set(KernelState kernelState, int globalGroupId, int threadId) { kernelState.setLocalBarrier(localBarrier); } - ForkJoinTask fjt = threadPool.submit( + ForkJoinTask fjt = getThreadPool().submit( // () -> { new Runnable() { public void run() { @@ -2107,6 +2109,28 @@ public boolean isExplicit() { return (explicit); } + public ForkJoinPool getThreadPool() { + if(useStaticPool) { + if(commonPoolResource==null) { + commonPoolResource=threadPool; + } + return commonPoolResource; + } + return threadPool; + } + + public void setThreadPool(ForkJoinPool threadPool) { + this.threadPool = threadPool; + } + + public static boolean isUseStaticPool() { + return useStaticPool; + } + + public static void setUseStaticPool(boolean useStaticPool) { + KernelRunner.useStaticPool = useStaticPool; + } + private static class ExecutionSettings { final KernelPreferences preferences; final KernelProfile profile;