Open
Description
Many of the implementations in imglib2-algorithm have an int numThreads
parameter for controlling how many threads to spawn. Others take an ExecutorService
. Accepting an ExecutorService
is more flexible and would mesh better with SciJava Common’s ThreadService
and therefore ImageJ Ops. See also imagej/imagej-ops#599. On the other hand, an ExecutorService
alone is not enough to identify the intended number of threads to use when partitioning the task.
Note that currently, we often infer numTasks
from Runtime.availableProcessors()
by default, which is not a good practice in general because multiple tasks may be ongoing simultaneously, which can result in more threads than processors.
@tpietzsch points out:
- In
ForkJoinPool
there is a "parallelism level" that corresponds to this roughly. We should consider using ForkJoinPool throughout. ForkJoinPool
extendsExecutorService
, so it would at least be backwards compatible in some ways.ForkJoinPool.getParallelism()
could replace / augmentnumTasks
.ForkJoinPool
supports work-stealing which would be important if submitted task spawn new subtasks for whose completion they wait. This allows handing down pool through algorithms that parallelise in chunks and for each chunk call another algorithm that parallelizes internally. (With handing down ExecutorService that wouldn't work.)- Also there is the common
ForkJoinPool.commonPool()
that is used by streams etc. We could fall back to this there is no user-provided pool.
Based on a chat in gitter.
Metadata
Metadata
Assignees
Labels
No labels