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 7642691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:15:17+00:00 2026-05-31T09:15:17+00:00

I have an OpenMP parallelized program that looks like that: […] #pragma omp parallel

  • 0

I have an OpenMP parallelized program that looks like that:

[...]
#pragma omp parallel
{
//initialize threads

#pragma omp for
for(...)
  {
  //Work is done here

  }

}

Now I’m adding MPI support. What I will need is a thread that handles the communication, in my case, calls GatherAll all the time and fills/empties a linked list for receiving/sending data from the other processes. That thread should send/receive until a flag is set. So right now there is no MPI stuff in the example, my question is about the implementation of that routine in OpenMP.
How do I implement such a thread? For example, I tried to introduce a single directive here:

[...]
int kill=0
#pragma omp parallel shared(kill)
{
//initialize threads
#pragma omp single nowait
 {
  while(!kill)
   send_receive(); 
 }
#pragma omp for
for(...)
  {
  //Work is done here

  }
kill=1

} 

but in this case the program gets stuck because the implicit barrier after the for-loop waits for the thread in the while-loop above.

Thank you, rugermini.

  • 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-31T09:15:18+00:00Added an answer on May 31, 2026 at 9:15 am

    You could try adding a nowait clause to your single construct:

    EDIT: responding to the first comment

    If you enable nested parallelism for OpenMP, you might be able to achieve what you want by making two levels of parallelism. In the top level, you have two concurrent parallel sections, one for the MPI communications, the other for local computation. This last section can itself be parallelized, which gives you a second level of parallelisation. Only threads executing this level will be affected by barriers in it.

    #include <iostream>
    #include <omp.h>
    
    int main()
    {
      int kill = 0;
    #pragma omp parallel sections
      {
    #pragma omp section
        {
          while (kill == 0){
            /* manage MPI communications */
          }
        }
    
    #pragma omp section
        {
    #pragma omp parallel
    #pragma omp for
          for (int i = 0; i < 10000 ; ++i) {
            /* your workload */
          }
          kill = 1;
        }
      }
    }
    

    However, you must be aware that your code is going to break if you don’t have at least two threads, which means you’re breaking the assumption that the sequential and parallelized versions of the code should do the same thing.

    It would be much cleaner to wrap your OpenMP kernel inside a more global MPI communication scheme (potentially using asynchronous communications to overlap communications with computations).

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

Sidebar

Related Questions

I have a loop in my C++/OpenMP code that looks like this: #pragma omp
I have an OpenMP with C++ program. There are parallel regions that contain #pragma
I have a section of a Fortran90 program that should be parallelized with OpenMP.
I have a serial application that I parallelized using OpenMP. I simply added the
I have a loop which should be nicely parallelized by insering one openmp pragma:
I have a C++ program using OpenMP, which will run on several machines that
I have moved a parallel program that was working and built in visual studio.
I want to write a code converter that takes an OpenMP based parallel program
I currently have a code (in C) with an outer loop that is OpenMP-parallelized
I have a loop that has been parallelized by OpenMP, but due to the

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.