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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:47:11+00:00 2026-05-26T11:47:11+00:00

My program contains a for() loop that processes some raw image data, line by

  • 0

My program contains a for() loop that processes some raw image data, line by line, which I want to parallelize using OpenMP like this:

...
#if defined(_OPENMP)
        int const  threads = 8;
        omp_set_num_threads( threads );
        omp_set_dynamic( threads );
#endif
        int line = 0;
#pragma omp parallel private( line )
        {
            // tell the compiler to parallelize the next for() loop using static
            // scheduling (i.e. balance workload evenly among threads),
            // while letting each thread process exactly one line in a single run
#pragma omp for schedule( static, 1 )
            for( line = 0 ; line < max; ++line ) {
                // some processing-heavy code in need of a buffer
            }
        } // end of parallel section
....

The question is this:

Is it possible to provide an individual (preallocated) buffer (pointer) to each thread of the team executing my loop using a standard OpenMP pragma/function (thus eliminating the need to allocate a fresh buffer with each loop)?

Thanks in advance.

Bjoern

  • 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-26T11:47:12+00:00Added an answer on May 26, 2026 at 11:47 am

    I may be understanding you wrong, but I think this should do it:

    #pragma omp parallel 
    {
        unsigned char buffer[1024]; // private
    
        // while letting each thread process exactly one line in a single run
        #pragma omp for // ... etc
        for(int line = 0; line < max; ++line ) {
              //...
        }
    }
    

    If you really meant you want to share the same buffer for different parallell blocks, you’ll have to resort to thread-local storage. (Boost as well as C++11 have facilities for making that easier to do (more portably too) than directly using TlsAlloc and friends).

    Note that this approach replaces some of the thread-safety checking burden back on the programmer because it is perfectly possible to have different omp parallel sections running at the same time, especially when they are being nested.

    Consider that parallel blocks could be nesting at runtime, even though they are not lexically nested. In practice that is usually not good style – and often results in poor performance. However, it is something you need to be aware of when doing this).

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

Sidebar

Related Questions

Two Delphi programs need to load foo.dll, which contains some code that injects a
In a program I'm reading in some data files, part of which are formatted
Sometimes, I'll run a program that accidentally contains an infinite loop or something. Eclipse
I'm writing a program that contains a generational garbage collector. There are just two
Upon loading into a C++ program a Prolog program that contains the command 'send'
I've got a list in a Python program that contains a series of numbers,
Let's say I am writing installation script for the program which contains executable file
I have a program with a class that contains a public enum, as follows:
I have a table that contains log entries for a program I'm writing. I'm
I have to write a program that read from a file that contains the

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.