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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:27:53+00:00 2026-06-11T14:27:53+00:00

I am using openMP to run instances of my simulation in parallel. #pragma omp

  • 0

I am using openMP to run instances of my simulation in parallel.

#pragma omp parallel for private(part) shared(P,lfcc,temp)
for (part = 0; part < P->Parts; part++)

Part of the loop checks if the output file with index number “part” already exist (so i can run the simulation for a certain value of “Parts”, and later increase it without overwriting the existing results). However, this requires the iteration to run in order. That is, for n threads, it should first run simultaneously parts (1)-(n), followed by parts (n+1)-(2n) and so on. right now (with 3 threads running in parallel, and “parts” set to N), the behaviour is different, running first parts (0),(N/3),(2N/3) followed by (1),(N/3+1),(2N/3+1) and so on.

Suppose now, i initially wanted 30 parts which were all completed. Then i decide i need more parts and change “Parts” to 45. Then the first threads gets parts (1)-(15), the second (16)-(30) and the third (31-45). The first two threads quickly find out that all their assigned parts had already been completed and will leave the last thread to work alone (if i put a barrier clause before the program terminates).

One simple solution is to let the “part” variable start not with 0 but with m+1, where m is the number of previously completed parts. But i was wondering if it was possible to force openMP to run the iteration in the order showing in bold above.

  • 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-11T14:27:54+00:00Added an answer on June 11, 2026 at 2:27 pm

    You can change the size of the iteration blocks each thread gets to 1 within the schedule clause, e.g. schedule(static,1). With 3 threads the first one would process iterations 0, 3, 6, 9 and so on, the second thread would process iterations 1, 4, 7, 10 and so on, and the third one would process iterations 2, 5, 8, 11 and so on. You still need to synchronise somewhere in the loop since there is no guarantee that threads would execute all steps at the same time and at the same speed (you can put a barrier at the end of each iteration to synchronise before the next block of iterations starts).

    Another solution is to use the OpenMP tasking construct. With it you can run a big loop in one thread, generating computational tasks. You can put checks for the existence of the output file inside this loop and create new tasks only if needed (e.g. the output file does not exist):

    #pragma omp parallel
    {
        ...
        #pragma omp single
        for (part = 0; part < P->Parts; part++)
        {
            if (!output_file_exists(part))
               #pragma omp task
               {
                  ... computation for that part ...
               }
        }
        #pragma omp taskwait
        ...
    }
    

    Hope I’ve understood your problem correctly.

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

Sidebar

Related Questions

please help me to make this code parallel using openmp this code is run
I am writing simple parallel program in C++ using OpenMP. I am working on
Say, I run a parallel program using MPI. Execution command mpirun -n 8 -npernode
I have written a library in C using a variety of the #pragma omp
I have a C++ program using OpenMP, which will run on several machines that
I've gotten stuck writing some parallel c code using OpenMP for a concurrency course.
I finally got a section of my code to run in parallel with OpenMP
In the following C code I am using OpenMP in a nested loop. Since
I have a program using OpenMP to parallelize a for-loop. Inside the loop, the
While using OpenMP threads, Each thread can declare its own set of private variables.

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.