Skip to content

Commit

Permalink
#11 - collatz eventstream
Browse files Browse the repository at this point in the history
  • Loading branch information
obriensystems committed Jan 1, 2024
1 parent 94e0dc4 commit 046a2a3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
5 changes: 5 additions & 0 deletions org.obrienscience.concurrent.CollatzBeowulfSE/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

# Collatz / Hailstone numbers
## 1982+
## Links
- Eric Roosendaal http://www.ericr.nl/wondrous/pathrecs.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class Collatz {
private boolean displayIterations = false;
private BigInteger prevMaxPath = BigInteger.ZERO;
private BigInteger prevMaxValue = BigInteger.ZERO;
private BigInteger pathCount = BigInteger.ZERO;
private BigInteger heightCount = BigInteger.ZERO;


public Collatz(long aStart) {
Expand Down Expand Up @@ -100,8 +102,8 @@ private void computeSingleThreaded() {
}
}
long time = System.currentTimeMillis() - startTime;
System.out.println("start,path,max,ms");
System.out.println(start + "," + path + "," + height + "," + time);
System.out.println("pcount,hcount,start,path,max,ms");
System.out.println(pathCount + "," + heightCount + "," + start + "," + path + "," + height + "," + time);
}


Expand All @@ -120,13 +122,13 @@ public void computeRange() {
while(current.compareTo(end) < 0) {
BigInteger prev = current;
path = 0;
maxValue = BigInteger.ZERO;
maxPath = BigInteger.ZERO;
maxValue = BigInteger.ONE;
maxPath = BigInteger.ONE;
newMax = false;

while (prev.compareTo(BigInteger.ONE) > 0) {
if(prev.testBit(0)) {
prev = prev.shiftLeft(1).add(prev).add(BigInteger.ONE);
prev = prev.shiftLeft(1).add(prev).add(BigInteger.ONE); // NPE before 8528,817511
} else {
prev = prev.shiftRight(1);
}
Expand All @@ -142,15 +144,16 @@ public void computeRange() {
if(maxValue.compareTo(gmaxValue) > 0) {
gmaxValue = maxValue;
newMax = true;
heightCount = heightCount.add(BigInteger.ONE);
}

if(maxPath.compareTo(gmaxPath) > 0) {
gmaxPath = maxPath;
newMax = true;
pathCount = pathCount.add(BigInteger.ONE);
}
if(newMax) {

System.out.println("S: " + current + " M: " + maxValue + " P: " + maxPath
System.out.println("PC: " + pathCount + " HC: " + heightCount + " S: " + current + " M: " + maxValue + " P: " + maxPath
+ " T: " + (System.currentTimeMillis() - lastMaxTime));
lastMaxTime = System.currentTimeMillis();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public void compute(long pool, long threads, long uowSplit, long extent) {
BigInteger maxValue = BigInteger.ONE;
ForkJoinUnitOfWork forkJoinUOW = new ForkJoinUnitOfWork(uowSplit, 0, extent, maxPath, maxValue);
long startTime = System.currentTimeMillis();
// create a ppol of threads to the power of pool * # of (proc + ht)
// create a pool of threads to the power of pool * # of (proc + ht)
mapReducePool = new ForkJoinPool(1 << pool);//Runtime.getRuntime().availableProcessors() << pool);
mapReducePool.invoke(forkJoinUOW);
long endTime = System.currentTimeMillis();
Expand All @@ -24,7 +24,7 @@ public void compute(long pool, long threads, long uowSplit, long extent) {
}

public static void main(String[] args) {
System.out.println("ForkJoinCollatzServer forkJoinPool-power-start end runs (v 20161009)");
System.out.println("ForkJoinCollatzServer forkJoinPool-power-start end runs (v 20240101)");
long poolStart = 0;
long poolEnd = 7;
long runs = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected void computeNoFork() {
newMax = true;
}
if(newMax) {
//System.out.println("S: " + start + " N: " + current + " M: " + maxValue + " P: " + maxPath);
System.out.println("S: " + start + " N: " + current + " M: " + maxValue + " P: " + maxPath + " thread: " + Thread.currentThread().getId());
}
}

Expand Down

0 comments on commit 046a2a3

Please sign in to comment.