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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:48:24+00:00 2026-06-05T20:48:24+00:00

Below is a portion of code parallelized via openMP. Arrays, ap[] and sc[] ,

  • 0

Below is a portion of code parallelized via openMP. Arrays, ap[] and sc[], are emposed to addition assignment so, I decided to make them shared and then put them in critical clause section since reduction clause does not accept arrays. But it gives a different result than its serial counterpart. Where is the problem?

Vector PN, Pf, Nf; // Vector is user-defined structure
Vector NNp, PPp;
Vector gradFu, gradFv, gradFw;
float dynVis_eff, SGSf; 
float Xf_U, Xf_H;
float mf_P, mf_N;
float an_diff, an_conv_P, an_conv_N, an_trans;  
float sc_cd, sc_pres, sc_trans, sc_SGS, sc_conv_P, sc_conv_N;   
float ap_trans;

#pragma omp parallel for
for (int e=0; e<nElm; ++e)
{
    ap[e] = 0.f;
    sc[e] = 0.f;
}

#pragma omp parallel for shared(ap,sc)
for (int f=0; f<nFaces; ++f)
{
    PN = cntE[face_N[f]] - cntE[face_P[f]];
    Pf = cntF[f] - cntE[face_P[f]];
    Nf = cntF[f] - cntE[face_N[f]];
    PPp = Pf - (Pf|norm(PN))*norm(PN);
    NNp = Nf - (Nf|norm(PN))*norm(PN);

    mf_P = mf[f];
    mf_N = -mf[f];

    SGSf = (1.f-ifac[f]) * SGSvis[face_P[f]]
         +      ifac[f]  * SGSvis[face_N[f]];

    dynVis_eff = dynVis + SGSf;

    an_diff = dynVis_eff * Ad[f] / mag(PN);

    an_conv_P = -neg(mf_P);
    an_conv_N = -neg(mf_N);

    an_P[f] = an_diff + an_conv_P;
    an_N[f] = an_diff + an_conv_N;

    // cross-diffusion
    sc_cd = an_diff * ( (gradVel[face_N[f]]|NNp) - (gradVel[face_P[f]]|PPp) );

    #pragma omp critical
    {       
        ap[face_P[f]] += an_N[f];   
        ap[face_N[f]] += an_P[f];

        sc[face_P[f]] += sc_cd + sc_conv_P;
        sc[face_N[f]] += -sc_cd + sc_conv_N;
    }
  • 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-05T20:48:25+00:00Added an answer on June 5, 2026 at 8:48 pm

    You have not declared whether all the other variables in your parallel clause should be shared or not. You can do this generically with the default clause. If no default is specified, the variables are all shared, which is causing the problems in your code.

    In your case, I’m guessing you should go for

    #pragma omp parallel for default(none), shared(ap,sc,face_N,face_P,cntF,cntE,mf,ifac,Ad,an_P,an_N,SGSvis,dynVis), private(PN,Pf,Nf,PPp,NNp,mf_P,mf_N,SGSf,dynVis_eff,an_diff,an_conv_P,an_conv_N,sc_cd)
    

    I strongly recommend always using default(none) so that the compiler complains every time you don’t declare a variable explicitly and forces you to think about it explicitly.

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

Sidebar

Related Questions

Line 3 of the code below fails if I omit the => $v portion.
Below is a small portion of the source code where fclose is causing error?
I am on Linux and gcc 4.2.3. For the below code portion, lp_parm_talloc_string function
I have a portion of HTML code in R like the one below: </a>
The code below is a portion of a php file I use to update
My code is as below. Html Portion <div id=div_video> <div class=div_vol> <a href=# onclick=sound_adjustment()><img
I have the below code (only the portion that is needed) EXEC @ReturnCode =
Below is code to an inherited ComboBox. The issue is that the ComboBox is
Below is the code from internalRegister method of GCMRegistrar class static void internalRegister(Context context,
below is the code to download a txt file from internet approx 9000 lines

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.