Skip to content

Commit

Permalink
#10 - code clean
Browse files Browse the repository at this point in the history
  • Loading branch information
obriensystems committed Jan 4, 2025
1 parent 80284bb commit 33abafe
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/**
* 20250101
* Michael O'Brien michael at obrienlabs.dev
* https://github.com/ObrienlabsDev/performance
*
* Architecture
* map the search space by interleaved UOW (1,3,5,7) - to 4 threads
Expand Down Expand Up @@ -56,15 +57,13 @@ public boolean isCollatzMax(long oddSearchCurrent, long secondsStart) {
+ (System.currentTimeMillis() - secondsLast) + " dur: " + ((System.currentTimeMillis() - secondsStart) / 1000));
secondsLast = System.currentTimeMillis();
result = true;
//result = Long.valueOf(current);
}
if (path > globalMaxPath.get()) {
globalMaxPath.set(path);
System.out.println("mp: " + oddSearchCurrent + " p: " + path + " m: " + (maxValue << 1) + " ms: "
+ (System.currentTimeMillis() - secondsLast) + " dur: " + ((System.currentTimeMillis() - secondsStart) / 1000));
secondsLast = System.currentTimeMillis();
result = true;
//result = Long.valueOf(current);
}

break;
Expand Down Expand Up @@ -107,16 +106,11 @@ public static void main(String[] args) {
System.out.println("Collatz multithreaded 2025 michael at obrienlabs.dev");
Collatz collatz = new Collatz();

//long oddSearchStart = 1L; // must be odd
//long oddSearchEnd = 4294967295L; //18446744073709551615 // must be odd
//long oddSearchIncrement = 2L;
long oddSearchCurrent = 1L;
long secondsStart = System.currentTimeMillis();

collatz.searchCollatzParallel(oddSearchCurrent, secondsStart);
/*for(oddSearchCurrent = oddSearchStart; oddSearchCurrent < oddSearchEnd; oddSearchCurrent += oddSearchIncrement) {
collatz.searchCollatzParallel(oddSearchCurrent, secondsStart);
}*/

System.out.println("completed: " + (System.currentTimeMillis() - secondsStart));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,13 @@ public boolean isCollatzMax(ULong128 oddSearchCurrent, long secondsStart) {
+ (System.currentTimeMillis() - secondsLast) + " dur: " + ((System.currentTimeMillis() - secondsStart) / 1000));
secondsLast = System.currentTimeMillis();
result = true;
//result = Long.valueOf(current);
}
if (path > globalMaxPath) {
globalMaxPath = path;
System.out.println("mp: " + oddSearchCurrent + " p: " + path + " m: " + maxValue.shiftLeft(1) + " ms: "
+ (System.currentTimeMillis() - secondsLast) + " dur: " + ((System.currentTimeMillis() - secondsStart) / 1000));
secondsLast = System.currentTimeMillis();
result = true;
//result = Long.valueOf(current);
}

break;
Expand All @@ -103,15 +101,12 @@ public void searchCollatzParallel(long oddSearchCurrent, long secondsStart, long
.rangeClosed(1L + (part * threads), ((1 + part) * threads) - 1)
.filter(x -> x % 2 != 0) // TODO: find a way to avoid this filter using range above
.boxed()
//.map(n -> ULong128Impl.ONE)
.map(ULong128Impl::new)
.collect(Collectors.toList());

// filter on max value or path
List<ULong128> results = oddNumbers
.parallelStream()
//.map(n -> ULong128)

.parallelStream()
.filter(num -> isCollatzMax(num, secondsStart))
.collect(Collectors.toList());

Expand All @@ -132,7 +127,6 @@ public static void main(String[] args) {
batchBits = Long.parseLong(args[1]);
}


Collatz128bit collatz = new Collatz128bit();

long oddSearchCurrent = 1L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/**
* 20250101
* Michael O'Brien michael at obrienlabs.dev
* https://github.com/ObrienlabsDev/performance
*
* Architecture
* map the search space by interleaved UOW (1,3,5,7) - to 4 threads
Expand Down

0 comments on commit 33abafe

Please sign in to comment.