Skip to content

Use LoopBuilder to multithread Modern plugins #252

Open
@mdoube

Description

@mdoube

Describe the bug
LoopBuilder is the ImgLib2 way to achieve chunked multithreading, see this for an example (specifically, the 'squared sum' example)
https://forum.image.sc/t/imglib2-split-image-into-chunks-for-multi-threaded-processing/37519/4

Modern Connectivity currently uses 8 cursors to achieve multithreading, which is a bit of a hack.

imagej/imagej-ops@6a60315#diff-d6c590f31ede52f4518dba0b4a44cf9fR261

    				final Cursor<B> octantCursor1 = Views.flatIterable(interval).cursor();
    				final Cursor<B> octantCursor2 = Views.flatIterable(interval).cursor();
    				final Cursor<B> octantCursor3 = Views.flatIterable(interval).cursor();
    				final Cursor<B> octantCursor4 = Views.flatIterable(interval).cursor();
    				final Cursor<B> octantCursor5 = Views.flatIterable(interval).cursor();
    				final Cursor<B> octantCursor6 = Views.flatIterable(interval).cursor();
    				final Cursor<B> octantCursor7 = Views.flatIterable(interval).cursor();
    				final Cursor<B> octantCursor8 = Views.flatIterable(interval).cursor();

    				octantCursor1.jumpFwd(start);
    				octantCursor2.jumpFwd(start + w);
    				octantCursor3.jumpFwd(start + 1);
    				octantCursor4.jumpFwd(start + w + 1);
    				octantCursor5.jumpFwd(start + w * h);
    				octantCursor6.jumpFwd(start + w * h + w);
    				octantCursor7.jumpFwd(start + w * h + 1);
    				octantCursor8.jumpFwd(start + w * h + w + 1);

    				for (int i = 0; i < steps; i++) {
    					boolean o1 = octantCursor1.next().get();
    					boolean o2 = octantCursor2.next().get();
    					boolean o3 = octantCursor3.next().get();
    					boolean o4 = octantCursor4.next().get();
    					boolean o5 = octantCursor5.next().get();
    					boolean o6 = octantCursor6.next().get();
    					boolean o7 = octantCursor7.next().get();
    					boolean o8 = octantCursor8.next().get();

Additional context
Any change to the code needs to be performance benchmarked and reported to @maarzt
If it works out, we might be able to improve the performance of other Modern plugins like VolumeFraction

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions