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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:45:09+00:00 2026-05-30T21:45:09+00:00

I want to make sure I implement a barrier correctly. Right now, amStaticThreaded starts

  • 0

I want to make sure I implement a barrier correctly. Right now, amStaticThreaded starts a ton of new threads every time it is called. In my main routine, everything after amStaticThreaded can be done by only one thread, but that part is extremely fast. Is there a better way than to have amStaticThreaded start a new set of threads every time

I have the following setup in my code:

void amStaticThreaded(int nshocks, int nstates,
                      MatrixXd& valmat, MatrixXd& EV_prev, MatrixXd& fullmat) {

  #pragma omp parallel for
  for(int i = 0; i < nshocks; i++) {

    // this does the add part    
    RowVectorXd vrow(nstates);
    vrow = EV_prev.row(i);

    fullmat.middleRows( i*nstates, nstates).rowwise() += vrow;
    valmat.row(i)   = fullmat.middleRows(i*nstates, nstates).rowwise().maxCoeff().transpose();

  }

}

int main() {

  // ...

  // ITERATION ON CONTINUATION VALUE  
  cout << "entering loop" << endl;
  while ( (err > TOL) && (itercount < MAXIT)) {

    // GET NEW EXPECTED VALUE FUNCTION
    EV_prev = (T_BIG * V_prev);
    EV_prev.array() *= beta;

    fullmat = staticmat;
    amStaticThreaded(Nshocks, nstates, V_new, EV_prev, fullmat);

    // THERE SHOULD BE A BARRIER HERE

    // FIGURE OUT THE ERROR BOUNDS
    mmdiff = (V_new.array() - V_prev.array());
    lbound = beta * double(mmdiff.minCoeff());
    ubound = beta * double(mmdiff.maxCoeff());

    // POSSIBLY ADJUST THE VALUE FUNCTION
    relres = ubound - lbound;
    if(relres < TOL) {
      V_new.array() += (ubound + lbound)/2.0;
    }
    err = relres;

    // UPDATE ITER COUNT AND VALUE FUNCTION
    cout << "i: " << itercount << ": " << err << endl;
    itercount++;
    V_prev = V_new;
  } // end while
  cout << "DONE with iteration!" << endl;
}
  • 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-30T21:45:11+00:00Added an answer on May 30, 2026 at 9:45 pm

    Your code is correct as it is. There is an implied barrier at the end of the parallel section; only the master thread executes instructions outside the parallel section.

    As for the starting of many threads every time you enter the parallel for, this is something the OpenMP implementation will take care of. Most implementations keep a pool of threads and use them when needed, instead of always creating and deleting threads.

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

Sidebar

Related Questions

I want to make sure people can't type the name of a PHP script
I want to make sure that a set of functions have the same signature
I want to make sure a file path set via query string does not
I want to make sure my local is matching the production environment closely and
I want to make sure a string has only characters in this range [a-z]
I want to make sure I'm not inserting a duplicate row into my table
I want to make sure the first 4 letters in a eight character code
I want to make sure that if any error occurs during the database processing
I want to make sure the input is A)a number and B)has at most
I want to make sure all getters of the classes in a certain package

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.