-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ImgUtil.copy for two RandomAccessibleInterval is missing the "n_threads" parameter #282
Comments
I think this goes a bit against the idea of the In your code, the public static < T extends Type< T >> void copy( final RandomAccessibleInterval< T > source, final RandomAccessibleInterval< T > destination, final int n_threads )
{
Parallelization.runWithNumThreads( n_threads, () -> copy( source, destination ) );
} At this point, to me it seems to not add enough to justify adding a new method. copy( source1, destination1, 64 );
copy( source2, destination2, 64 );
copy( source3, destination3, 64 );
copy( source4, destination4, 64 ); which would spin up a new ThreadPool every time instead of Parallelization.runWithNumThreads( 64, () -> {
copy( source2, destination2 );
copy( source1, destination1 );
copy( source3, destination3 );
copy( source4, destination4 );
} ); which would reuse the same one. If you are concerned about the lambdas in a scripting language setting, there is also imglib2/src/main/java/net/imglib2/parallel/Parallelization.java Lines 225 to 256 in 7e37c9b
@maarzt Opinions? |
The code here:
imglib2/src/main/java/net/imglib2/util/ImgUtil.java
Line 318 in 7e37c9b
... is very clean and simple, but it's missing a critical parameter: the number of threads to use.
A second
ImgUtil.copy
method would offer an additionaln_threads
parameter.The new
LoopBuilder
has amultiThreaded
method used inImgUtil.copy
but it takes aTaskExecutor
obtained from theParallelization.getTaskExecutor()
. WhileParallelization
has methods to run anAction
multithreaded, it is not obvious how to ask theParallelization
for aTaskExecutor
that uses a predetermined number of threads.Fortunately, the
TaskExecutors
class has anumThreads( int numThreads )
method that returns aTaskExecutor
.So the new method could look like this:
Any objections to adding this method, given that the current replacement
ImgUtils.copy
falls short of its original implementation with then_threads
parameter?The text was updated successfully, but these errors were encountered: