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: TestBreak()

    Cinema 4D SDK
    c++ r20 r21
    3
    7
    668
    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

      Hello,

      I'm successfully using the Parallel stuff from the API.

      What I didn't understand yet is how to check for a user break within a ParallelFor worker lambda. I'm thinking the BreakContext has something to do with it, but I couldn't figure out yet how to do it.

      With the old C4DThreads, we could simply do it like this:

      // Check for user break every 64 iterations
      if (thread && !(x & 63))
      {
      	if (thread->TestBreak())
      		break;
      }
      

      How does this work with the new Parallel functions?

      Cheers,
      Frank

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

      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by

        hi,
        sorry for the late reply.

        you have to use the BreakContext in the template of the parrallelFor.

        And pass your thread to the lamba function as a reference. In the lambda function you call the Break function if needed.

        there are other context you can use

                maxon::Result<void> errReturn;
        	auto worker = [&escThread]
        	(maxon::Int32 y , maxon::ParallelFor::BreakContext& context) -> maxon::Result < void >
        	{
        		
        		for (maxon::Int32 loop = 0; loop < 10000; loop++)
        		{
        			if (MAXON_UNLIKELY(escThread->TestBreak()))
        				context.Break(maxon::UnexpectedError(MAXON_SOURCE_LOCATION));
        			continue;
        		}
        		return maxon::OK;
        	};
        
        	errReturn = maxon::ParallelFor::Dynamic<maxon::ParallelFor::BreakContext>(0, 100000, worker, numThreads, maxon::PARALLELFOR_DEFAULTGRANULARITY );
        	
        	if (errReturn == maxon::OK)
        		ApplicationOutput("we didn't got stoped");
        	else if (errReturn == maxon::FAILED)
        		ApplicationOutput("we've been stopped @", errReturn.GetError());
        
        

        Sorry i cant really provide a fully working example but that's the way to do it 🙂

        Cheers,
        Manuel

        MAXON SDK Specialist

        MAXON Registered Developer

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

          Super cool, thank you for the example code!

          Greetings,
          Frank

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

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

            Oh wait, what's escThread in your example code? Where did that come from?

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

            1 Reply Last reply Reply Quote 0
            • P
              PluginStudent
              last edited by

              I would guess that's the thread returned by GeGetEscTestThread(). See Thread Utility Manual.

              Or it is just the thread that provides the context for your call.

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

                That makes sense. Thanks again!

                Cheers,
                Frank

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

                1 Reply Last reply Reply Quote 0
                • ManuelM
                  Manuel
                  last edited by

                  hi,

                  as @PluginStudent said i was using GeGetEscTestThread and by the way, it's not really working 😃

                  But that's the same question with your code.
                  You test the thread that have been provided to you or your own thread. For that you pass that thread as a reference to the lambda function.

                  Cheers,
                  Manuel

                  MAXON SDK Specialist

                  MAXON Registered Developer

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