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

  • Home
  • SEARCH
  • 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 7411023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:19:21+00:00 2026-05-29T06:19:21+00:00

I am trying to use OpenMP for threading as it is cross platform. However

  • 0

I am trying to use OpenMP for threading as it is cross platform. However I can’t work out how to make the code after the parallel continue while the loop is running? It basically just executes the first loop in parallel but never gets to the second non parallel loop?

int main() {
    #pragma omp parallel 
        while(1) {
            Sleep(4000);
            printf("doing work in thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());
        }


    while (1) {
        Sleep(4000);
        printf("Hello from main %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());
    }
}
  • 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-05-29T06:19:22+00:00Added an answer on May 29, 2026 at 6:19 am

    I think you could just make one of the threads your special thread within your omp parallel block

    int main() {
        #pragma omp parallel 
            if(omp_get_thread_num()==0){
                 while(1) {
                    Sleep(4000);
                   printf("Hello from main %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());
                 }
            }else{
                 while(1) {
                    Sleep(4000);
                    printf("doing work in thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());
                 }
             }
        }
    }
    

    Weather this makes sense in your case is hard to judge without more details.

    You could also use sections. Example from here: http://bisqwit.iki.fi/story/howto/openmp/#Sections :

    #pragma omp parallel // starts a new team
    {
       //Work0(); // this function would be run by all threads.
    
       #pragma omp sections // divides the team into sections
       { 
         // everything herein is run only once.
         { Work1(); }
         #pragma omp section
         { Work2();
           Work3(); }
         #pragma omp section
         { Work4(); }
       }
    
       //Work5(); // this function would be run by all threads.
    }
    

    You can do nested renationalisation: OpenMP: What is the benefit of nesting parallelizations?

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

Sidebar

Related Questions

I'm trying to point out the difference between serial and parallel program with OpenMP.
I'm trying to learn how to use OpenMP by parallelizing a monte carlo code
I'm trying to use openmp to multithread a loop through std::set. When I write
Trying to use this code to connect the AD PrincipalContext context = new PrincipalContext(ContextType.Domain,
I'm trying to implement the distance matrix in parallel using openmp in which I
i am trying to use OpenMP in my program (i am newbie using OpenMP)
I'm trying use make a div's background transparent using a mixture of CSS3 rgba()
I got lots of error messages when trying to use openmp in a c++
I'm trying use double type in openCL, but doesn't work anyway, i want use
I am trying OpenMP on a particular code snippet. Not sure if the snippet

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.