Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7809091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:19:11+00:00 2026-06-02T03:19:11+00:00

I am optimizing some code with OpenMP. If NO_VALUE is met in a loop,

  • 0

I am optimizing some code with OpenMP. If NO_VALUE is met in a loop, I would like it to break. However, compiler tells me this is not allowed with openMP. How could I handle this?

#pragma omp parallel
{
     #pragma omp for  reduction(+:functionEvaluation)   schedule(dynamic)   nowait
     for (int j=m_colStart;j<m_colEnd+1;j++)
          {
               double d = command_->execute().toDouble();
               if(d==NO_VALUE)
               {
                    functionEvaluation  = NO_VALUE;
                                                   break;
                }
                else
                {
                    functionEvaluation += d;
                }
                delete command_;
            }
 }

How could I work around? thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:19:12+00:00Added an answer on June 2, 2026 at 3:19 am

    There is no problem with Qt.
    you cannot have a break in a loop that has been parallelized using openMP.

    Reasoning behind this :
    Lets say you have a loop with 10 iterations.
    Now, you want to break the loop at iteration 5. You say,

    if (iteration==5) 
        break;
    

    Now come to the parallel context, you have created 10 threads and each do their respective iteration in parallel. So when thread5 reaches certain condition you want all other threads to

    1. determine this
    2. undo their output
    3. Do not process anymore iterations
    4. do this dynamically and for all different scheduling policies.

    as you can see, this is not possible/practical in most circumstances. Hence OpenMP has disallowed the use of break in a parallel for loop.

    Now, say you know that a certain condition for breaking is very rare in your loop and you are hell bent on having a break in your parallel loop.

    Thread i 
    Check input condition
    If input leads to breaking flag a marker break_loop
    ******** barrier across all threads *************
    if flag break_loop is true
    then
       discontinue this operation
       mark a variable
       discontinue all the remaining iterations
    endif
    do your normal work
    

    This is just a framework. You will have to look at corner cases, locks, etc.
    For this you can have each thread check their input before iteration. If their input condition leads to breaking of loop, they set a con

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that runs fairly well, but I would like to make
I'm optimizing some instrumentation for my project (Linux,ICC,pthreads), and would like some feedback on
I use MSVC++ 2005 x64. Some code work incorrectly in release optimizing mode. So,
So I'm optimizing some code by unrolling some loops (yes, I know that I
I need some help optimizing a section of math heavy code. I've done the
I'm optimizing C code for OpenRISC and I want to manually prereserve some computed
I found several patterns for optimizing Bitmaps handling in WPF. I do not, however,
If I have some code that looks something like: typedef struct { bool some_flag;
I'm optimizing some frequently run Perl code (once per day per file). Do comments
nowadays i am optimizing some js code. there is a function named appendXYZ,and it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.