Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    ParallelFor vs. ParallelImage

    Cinema 4D SDK
    c++ r20 sdk macos
    3
    6
    631
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • fwilleke80F
      fwilleke80
      last edited by fwilleke80

      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.

      1 Reply Last reply Reply Quote 0
      • M
        mp5gosu
        last edited by

        Don't know if it makes a difference, but the example uses float values for the dimensions.

        1 Reply Last reply Reply Quote 0
        • fwilleke80F
          fwilleke80
          last edited by fwilleke80

          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.

          1 Reply Last reply Reply Quote 0
          • M
            m_adam
            last edited by r_gigante

            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

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

            1 Reply Last reply Reply Quote 0
            • M
              m_adam
              last edited by

              So this is by design and thought to be run on tiles only.

              However, I filled an idea to the development team.

              Cheers,
              Maxime.

              MAXON SDK Specialist

              Development Blog, MAXON Registered Developer

              1 Reply Last reply Reply Quote 0
              • fwilleke80F
                fwilleke80
                last edited by

                Thanks a lot! That helps 🙂

                Cheers,
                Frank

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

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post