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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:38:07+00:00 2026-06-17T22:38:07+00:00

First method (parallelize inner loop): for(j=0; j<LATTICE_VW; ++j) { x = j*DX + LATTICE_W;

  • 0

First method (parallelize inner loop):

for(j=0; j<LATTICE_VW; ++j) {
    x = j*DX + LATTICE_W;
    #pragma omp parallel for ordered private(y, prob)
        for(i=0; i<LATTICE_VH; ++i) {
            y = i*DY + LATTICE_S;
            prob = psi[i][j].norm();

            #pragma omp ordered
                out << x << " " << y << " " << prob << endl;
        }
}

Second method (parallelize outer loop):

#pragma omp parallel for ordered private(x, y, prob)
    for(j=0; j<LATTICE_VW; ++j) {
        x = j*DX + LATTICE_W;
        for(i=0; i<LATTICE_VH; ++i) {
            y = i*DY + LATTICE_S;
            prob = psi[i][j].norm();

            #pragma omp ordered
                out << x << " " << y << " " << prob << endl;
        }
    }

Third method (parallelize collapsed loops)

#pragma omp parallel for collapse(2) ordered private(x, y, prob)
    for(j=0; j<LATTICE_VW; ++j) {
        for(i=0; i<LATTICE_VH; ++i) {
            x = j*DX + LATTICE_W;
            y = i*DY + LATTICE_S;
            prob = psi[i][j].norm();

            #pragma omp ordered
                out << x << " " << y << " " << prob << endl;
        }
    }

If I was going to guess I would say that method 3 should be the fastest.

However method 1 is the fastest, while both the second and third take about the same ammount of time as if there was no parallelization. Why does this happens?

  • 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-17T22:38:09+00:00Added an answer on June 17, 2026 at 10:38 pm

    Look with this:

    for(int x = 0; x < 4; ++x)
      #pragma omp parallel for ordered
      for(int y = 0; y < 4; ++y)
        #pragma omp ordered
        cout << x << ',' << y << " (by thread " << omp_get_thread_num() << ')' << endl;
    

    you have:

    0,0 (by thread 0)
    0,1 (by thread 1)
    0,2 (by thread 2)
    0,3 (by thread 3)
    1,0 (by thread 0)
    1,1 (by thread 1)
    1,2 (by thread 2)
    1,3 (by thread 3)
    

    Each thread just has to wait for some cout all the work before can be done in parallel.
    But with:

    #pragma omp parallel for ordered
    for(int x = 0; x < 4; ++x)
      for(int y = 0; y < 4; ++y)
        #pragma omp ordered
        cout << x << ',' << y << " (by thread " << omp_get_thread_num() << ')' << endl;
    

    and

    #pragma omp parallel for collapse(2) ordered
    for(int x = 0; x < 4; ++x)
      for(int y = 0; y < 4; ++y)
        #pragma omp ordered
        cout << x << ',' << y << " (by thread " << omp_get_thread_num() << ')' << endl;
    

    the situations is:

    0,0 (by thread 0)
    0,1 (by thread 0)
    0,2 (by thread 0)
    0,3 (by thread 0)
    1,0 (by thread 1)
    1,1 (by thread 1)
    1,2 (by thread 1)
    1,3 (by thread 1)
    2,0 (by thread 2)
    2,1 (by thread 2)
    2,2 (by thread 2)
    2,3 (by thread 2)
    3,0 (by thread 3)
    3,1 (by thread 3)
    3,2 (by thread 3)
    3,3 (by thread 3)
    

    So thread 1 has to wait for thread 0 to finish all its work, before it can cout the first time, and nearly nothing can be done in parallel.

    Try adding schedule(static,1) to the collapse-version and it should perform at least as good as the first version does.

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

Sidebar

Related Questions

I have a SortedSet holding my ordered data. I use the .first() method to
Imagine a method like this ( in Win Forms): //First method private void buttonStart_Click(object
I want to change the first method to a while and for loop. I
In the first method listed below, the use method, it looks to me like
I wrap my project in OSGi bundle(just call my first start method from Activator.start()).
First time I am using the persist() method in a project. With JPA I
The first time I made a method to read data from my chat server,
First, I'm speaking about the default hashCode() method here and not something overridden. When
At first I was confused why both of the method calls in the constructor
What is the proper method to set the focus onload to first field in

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.