You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You’re generally better off avoiding guarded objects
Parallel Prefix Sums Algorithm
void iterativePrefixSums(long[] a) {
int gap = 1;
for (; gap < a.length; gap *= 2) {
parfor(int i = gap-1; i+gap < a.length; i += 2*gap) {
a[i+gap] = a[i] + a[i+gap];
}
}
for (; gap > 0; gap /= 2) {
parfor(int i = gap-1; i < a.length; i += 2*gap) {
a[i] = a[i] + ((i-gap >= 0) ? a[i-gap] : 0);
}
}
}
Work: O(n)
Span: O(ln n)
Fork/join in Java
For a thread or more to do some work
Join the threads to obtain the result of the work
java.util.concurrent.ForkJoinPool class
implements ExecutorService
Executes java.util.concurrent.ForkJoinTask<V> or java.util.concurrent.RecursiveTask<V> or java.util.concurrent.RecursiveAction