Markou moment

This commit is contained in:
Chloe Fontenot 🏳️‍⚧️ 2024-02-19 09:58:49 -06:00
parent 8fb402c420
commit e74ed9dbca

View File

@ -14,7 +14,7 @@ public class ParallelMax
public static void main(String[] args) public static void main(String[] args)
{ {
// Create a list // Create a list
final int N = 200000000; final int N = 20;
int[] list = new int[N]; int[] list = new int[N];
for (int i = 0; i < list.length; i++) for (int i = 0; i < list.length; i++)
list[i] = i; list[i] = i;
@ -51,7 +51,7 @@ public class ParallelMax
extends RecursiveTask<Integer> extends RecursiveTask<Integer>
{ {
private final static int THRESHOLD = 25000; private final static int THRESHOLD = 3;
private int[] list; private int[] list;
@ -81,8 +81,12 @@ public class ParallelMax
{ {
int mid = (low + high) / 2; int mid = (low + high) / 2;
RecursiveTask<Integer> left = new MaxTask(list, low, mid); RecursiveTask<Integer> left = new MaxTask(list, low, mid);
System.out.println("left: " + low +", " + high);
RecursiveTask<Integer> right = new MaxTask(list, mid+1, high); RecursiveTask<Integer> right = new MaxTask(list, mid+1, high);
System.out.println("right: " + (mid + 1) +", " + high);
System.out.println("fork right");
right.fork(); right.fork();
System.out.println("fork left");
left.fork(); left.fork();
return new Integer(Math.max( left.join().intValue(), return new Integer(Math.max( left.join().intValue(),
right.join().intValue()) right.join().intValue())