-
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
Multi-Threaded LoopBuilder #250
Conversation
Benchmarks have shown, that for native images using the cursors is usally faster than using random access. So LoopBuilders now uses Cursors to iterate over NativeImgs.
The methods are now sorted. Public methods first. That way it becomes it should be easier to read the code.
*/ | ||
public static MultiThreadSetting single() | ||
{ | ||
return SINGLE_THREAD_SETTINGS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the plural S
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a typo, should be without the S
;)
Is it worth looking at using |
The discussion on MultiThreadSetting is planned to be held in June 2019. For now MultiThreadSetting is only used package-privately inside LoopBuilder.
@tpietzsch How do you feel about merging this PR? |
The benchmark is now simpler. It now shows a situation where cursors are faster that LoopBuilder.
7bfb634
to
0913540
Compare
…ses. LoopBuilder will use Cursors to iterate over the image if all cursors classes are in the following list: * AbstractArrayCursor * SlicingCursor * PlanarCursor * CellCursor
@tpietzsch What do you think. Can we merge this? |
Hi @maarzt, |
This increases the performance of LoopBuilder if used with many different image classes.
No, consecutive pixels are usually processed by the same thread. The PR also contains a benchmark that shows multi-threading performance: https://github.com/imglib/imglib2/blob/multithreaded-loop-builder/src/test/java/net/imglib2/loops/LoopPerformanceBenchmark.java |
Thanks, a 3.8x speed up is wonderful.
|
This PR improves the performance of
LoopBuilder
by adding two features:LoopBuilder
now supports multi-threading. This example copies an image using multiple threads:LoopBuilder
usesCursor
instead ofRandomAccess
to iterate over an image. This happens when all images areNativeImg
likeArrayImg
,PlanarImg
andCellImg
.The
multiThreaded()
method in the example above optionally accepts aMultiThreadSetting
argument:Using the
MultiThreadSetting
one can specify howLoopBuilder
does the multi-threading.MultiThreadedSettings.single()
will make the algorithm run without multi-threading, this is also the default.MultiThreadSettings.multi()
does multi-threading. It's also possible to specify theExecutorService
to be usedMultiThreadSettings.multi(16, Executors.newFixedThreadPool(8))
.MultiThreadSetting
is a very simple interface, have a look. If you wantLoopBuilder
to use a specific thread pool, an custom implementation ofMultiThreadSetting
is the solution.I think
MultiThreadSetting
can be very useful for image processing algorithms, so I'm happy to discuss it.