diff --git a/src/main/java/nom/bdezonia/zorbage/misc/ThreadingUtils.java b/src/main/java/nom/bdezonia/zorbage/misc/ThreadingUtils.java index cab679902..4b69d3945 100644 --- a/src/main/java/nom/bdezonia/zorbage/misc/ThreadingUtils.java +++ b/src/main/java/nom/bdezonia/zorbage/misc/ThreadingUtils.java @@ -89,9 +89,10 @@ public static Tuple2 arrange(int numThreads, long numElems, boolea numThreads--; } - numThreads++; + if (numThreads * minElemSlice != numElems) + numThreads++; - return new Tuple2<>(numThreads, elemsPerThread+1); + return new Tuple2<>(numThreads, minElemSlice); } } } diff --git a/src/test/java/nom/bdezonia/zorbage/misc/ThreadingUtilsTest.java b/src/test/java/nom/bdezonia/zorbage/misc/ThreadingUtilsTest.java index a9ca3aa6d..8a5749022 100644 --- a/src/test/java/nom/bdezonia/zorbage/misc/ThreadingUtilsTest.java +++ b/src/test/java/nom/bdezonia/zorbage/misc/ThreadingUtilsTest.java @@ -82,14 +82,14 @@ public void test() { numThreads = tuple.a(); numElems = tuple.b(); assertTrue(numThreads * numElems >= 51); - assertEquals(400, numThreads); + assertEquals(51, numThreads); assertEquals(1, numElems); tuple = ThreadingUtils.arrange(400, 451, false); numThreads = tuple.a(); numElems = tuple.b(); assertTrue(numThreads * numElems >= 451); - assertEquals(400, numThreads); + assertEquals(226, numThreads); assertEquals(2, numElems); tuple = ThreadingUtils.arrange(10, 501, false);