Solved ParallelFor vs. ParallelImage

Hi there,

I'm using maxon::ParallelFor() to process 2-dimensional grids of values. Works like a charm!

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.

Here's the original code using 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:

	// 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.

Questions:

  • Why does this happen?
  • Are there any rules I need to stick to (e.g. gridWidth or gridHeight need to be multiples of 8, or whatever, or gridWidth and gridHeight need to be dividable by tileSize)?

Thanks in advance for help!

Cheers,
Frank

www.frankwilleke.de
Only asking personal code questions here.

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.

www.frankwilleke.de
Only asking personal code questions here.

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.

parallelimage.jpg

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 🙂

Cheers,
Frank

www.frankwilleke.de
Only asking personal code questions here.