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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:54:04+00:00 2026-06-12T12:54:04+00:00

To optimize the execution of some libraries I am making, I have to parallelize

  • 0

To optimize the execution of some libraries I am making, I have to parallelize some calculations.
Unfortunately, I can not use openmp for that, so I am trying to do some similar alternative using boost::thread.
Anyone knows of some implementation like this?
I have special problems with the sharing of variables between threads (to define variables as ‘shared’ and ‘pribate’ of openmp). Any sugestions?

  • 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-12T12:54:06+00:00Added an answer on June 12, 2026 at 12:54 pm

    As far as I know you’ll have to do that explicitly with anything other than OpenMP.

    As an example if we have a parallelized loop in OpenMP

    int i;
    size_t length = 10000;
    int someArray[] = new int[length];
    
    #pragma omp parallel private(i)
    {
    
        #pragma omp for schedule(dynamic, 8)
        for (i = 0; i < length; ++i) {
    
            someArray[i] = i*i;
    
        }
    }
    

    You’ll have to factor out the logic into a “generic” loop that can work on a sub-range of your problem, and then explicitly schedule the threads. Each thread will then work on a chunk of the whole problem. In that way you explicitly declare the “private” variables- the ones that go into the subProblem function.

    void subProblem(int* someArray, size_t startIndex, size_t subLength) {
        size_t end = startIndex+subLength;
    
        for (size_t i = startIndex; i < end; ++i) {
            someArray[i] = i*i;         
        }
    }
    
    void algorithm() {
    
        size_t i;
        size_t length = 10000;
        int someArray[] = new int[length];
        int numThreads = 4; // how to subdivide
        int thread = 0;
    
        // a vector of all threads working on the problem
        std::vector<boost::thread> threadVector;
    
        for(thread = 0; thread < numThreads; ++thread) {
            // size of subproblem
            size_t subLength = length / numThreads;
            size_t startIndex = subLength*thread;
    
            // use move semantics to create a thread in the vector
            // requires c++11. If you can't use c++11,
            // perhaps look at boost::move?
            threadVector.emplace(boost::bind(subProblem, someArray, startIndex, subLength));            
        }
        // threads are now working on subproblems
    
        // now go through the thread vector and join with the threads.
        // left as an exercise :P
    
    }
    

    The above is one of many scheduling algorithms- it just cuts the problem into as many chunks as you have threads.

    The OpenMP way is more complicated- it cuts the problem into many small sized chunks (of 8 in my example), and then uses work-stealing scheduling to give these chunks to threads in a thread pool. The difficulty of implementing the OpenMP way, is that you need “persistent” threads that wait for work ( a thread pool ). Hope this makes sense.

    An even simpler way would be to do async on every iteration (scheduling a piece of work for each iteration). This can work, if the each iteration is very expensive and takes a long time. However, if it’s small pieces of work with MANY iterations, most of the overhead will go into the scheduling and thread creation, rendering the parallelization useless.

    In conclusion, depending on your problem, there are be many ways to schedule the work, it’s up to you to find out what works best for your problem.

    TL;DR:
    Try Intel Threading Building Blocks (or Microsoft PPL) which schedule for you, provided you give the “sub-range” function:

    http://cache-www.intel.com/cd/00/00/30/11/301132_301132.pdf#page=14

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

Sidebar

Related Questions

I have read that some of the JVMs out there can optimize code execution
I have some procedures which are not optimized . I want to analyse that
I'm trying to optimize my code using Neon intrinsics. I have a 24-bit rotation
I'm trying to optimize the size of my Delphi classes so that they take
I have some queries that run for a quite long (20-30 minutes). If a
I am trying to optimize this query as good as possible,but still i am
I try to optimize my pages by putting some async attributes on my scripts.
I want to optimize images with the help of some external programs. The programs
How can I optimize below SQL (simplified view of my complex query.) Ideally, I
I'm trying to optimize the memory usage of an iOS app, and I'd like

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.