What I want
I want to work on optimization of fork/join algorithm. By optimization I mean just calculation of optimal number of threads, or if you want - calculation of SEQUENTIAL_THRESHOLD
(see code below).
// PSEUDOCODE
Result solve(Problem problem) {
if (problem.size < SEQUENTIAL_THRESHOLD)
return solveSequentially(problem);
else {
Result left, right;
INVOKE-IN-PARALLEL {
left = solve(extractLeftHalf(problem));
right = solve(extractRightHalf(problem));
}
return combine(left, right);
}
}
How do I imagine that
For example, I want to calculate the product of big array. Then I just evaluate all components and get the optimal threads amount:
SEQUENTIAL_THRESHOLD = PC * IS / MC
(just example)
PC
- number of processor cores;
IS
- constant, that indicates the optimal array size with one processor core and the simplest operation on data (for example reading);
MC
- multiply operation cost;
Suppose MC = 15; PC = 4 and IS = 10000; SEQUENTIAL_THRESHOLD = 2667
. Than if subtask-array is bigger than 2667 I'll fork it.
Broad questions
- Is it possible to make SEQUENTIAL_THRESHOLD formula in such way?
- Is it possible to accomplish the same for more complex computation: not only for operations on arrays/collections and sorting?
Narrow question:
Do already exist some investigations about calculation of SEQUENTIAL_THRESHOLD
for arrays/collections/sorting? How do they accomplish that?
Updated 07 March 2014:
- If there is no way to write a single formula for threshold calculation, can I write an util which will perform predefined tests on PC, and than gets the optimal threshold? Is that also impossible or not?
- What can Java 8 Streams API do? Can it help me? Does Java 8 Streams API eliminate a need in Fork/Join?
Executor
/scheduler to adapt to the real system’s load situation. – Koblenz