How would i determine the number of threads used to execute this code which is apparently 4,
Question:
public class ParaT2023 extends RecursiveTask {
int lo, hi, val;
int[] arr;
static final int CUT=5;
ParaT2023(int[] a, int l, int h, int v) { lo=l; hi=h; arr=a; val=v;}
protected Integer compute(){
if((hi-lo) < CUT) {
int ans = -1;
for(int i=(lo+1); i < hi; i++) {
if ( arr[i]==val) ans=i;
}
return ans;
}
else {
ParaT2023 left = new ParaT2023(arr,lo,(hi+lo)/2,val);
ParaT2023 right= new ParaT2023(arr,(hi+lo)/2,hi,val);
left.fork();
int rightAns = right.compute();
int leftAns = left.join();
if (rightAns>-1) return rightAns;
return leftAns;
}}
public static void main(String[] args) throws Exception {
int [] arr = {0,1,2,3,4,5,0,7,8,0,10,11,12,13,14,15, 0,17,18,19,20};
final ForkJoinPool fjPool = ForkJoinPool.commonPool();
int ans = fjPool.invoke(new ParaT2023(arr,0,arr.length,0));
System.out.println(ans);
}}
Income Tax Fundamentals 2019
ISBN: 9781337703062
37th Edition
Authors: Gerald E. Whittenburg, Steven Gill