Open
Description
TODO
- verify CopyOnWriteArrayList usage - ok
- ConcurrentHashMap (not needed) - ok
- AtomicLong - ok
- however no concurrency artifact issues seen so far
- verify expected BigInteger 9x slowdown - see Java 64 bit native long vs BigInteger performance - expected 9x slowdown but seeing 50x slowdown specific to IA64 over ARM64 #24
option 1: custom 16-32 thread pool
option 2: Java 7 level ForkJoinPool
option 3: Java 8 lambda/streams parallelization
public void searchCollatzParallel(long oddSearchCurrent, long secondsStart) {
long batchBits = 5; // adjust this based on the chip architecture
long searchBits = 32;
long batches = 1 << batchBits;
long threadBits = searchBits - batchBits;
long threads = 1 << threadBits;
for (long part = 0; part < (batches + 1) ; part++) {
// generate a limited collection for the search space - 32 is a good
System.out.println("Searching: " + searchBits + " space, batch " + part + " of "
+ batches + " with " + threadBits +" bits of " + threads + " threads" );
List<Long> oddNumbers = LongStream
.range(1L + (part * threads), ((1 + part) * threads) - 1)
.filter(x -> x % 2 != 0) // TODO: find a way to avoid this filter using range above
.boxed()
.collect(Collectors.toList());
// filter on max value or path
List<Long> results = oddNumbers
.parallelStream()
.filter(num -> isCollatzMax(num.longValue(), secondsStart))
.collect(Collectors.toList());
results.stream().sorted().forEach(x -> System.out.println(x));
}
System.out.println("last number: " + ((1 + (batches) * threads) - 1));
}
m4pro 972 batch 13
64330