Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
Hi there,
I'm using maxon::ParallelFor() to process 2-dimensional grids of values. Works like a charm!
maxon::ParallelFor()
After noticing maxon::ParallelImage in the documentation, I thought it might be worth a try to use that. After all, images are but 2-dimensional grids, too.
maxon::ParallelImage
Here's the original code using ParallelFor:
ParallelFor
// Worker lambda to build the grid const UInt gridWidth = gridRef.GetWidth(); const UInt gridHeight = gridRef.GetHeight(); auto worker = [&gridRef, &myObj, gridWidth, someParameter] (UInt y) { for (Uint x = 0; x < gridWidth; ++x) gridRef(x, y) = myObj->Calculate(x, y, someParameter); }; // Execute worker maxon::ParallelFor::Dynamic(0, gridHeight, worker);
Here's the code using ParallelImage:
ParallelImage
// Worker lambda to build the grid const UInt gridWidth = gridRef.GetWidth(); const UInt gridHeight = gridRef.GetHeight(); auto worker = [&gridRef, &myObj, someParameter] (maxon::Int x, maxon::Int y) { gridRef(x, y) = myObj->Calculate(x, y, someParameter); }; // Execute worker maxon::ParallelImage::Process(gridWidth, gridHeight, 10, worker);
The strange thing is that, while ParallelFor() works perfectly, ParallelImage() never calculates the last line and column of the grid. I tried calling Process() with gridWidth + 1, gridHeight + 1, and experimented with different tile sizes, with no success whatsoever.
ParallelFor()
ParallelImage()
Process()
gridWidth + 1
gridHeight + 1
Questions:
gridWidth
gridHeight
tileSize
Thanks in advance for help!
Cheers, Frank
Don't know if it makes a difference, but the example uses float values for the dimensions.
Only for calculations internal to the worker lambda. The Process() call, as well as the bitmap->SetPixel() call in the worker use the integer ones.
bitmap->SetPixel()
Hi after some investigation
gridWidth and gridHeight need to be dividable by tileSize with a remainder of 0.
So if you take the example provided in ParallelImage Manual This leads to 4 pixels missing in both the weight and the height since1024 % 30 == 4.
1024 % 30 == 4
In any case, I contacted the development team to know if it's a bug, or by design (and in this case a lack of documentation).
Cheers, Maxime
So this is by design and thought to be run on tiles only.
However, I filled an idea to the development team.
Cheers, Maxime.
Thanks a lot! That helps