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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:35:23+00:00 2026-06-05T19:35:23+00:00

I’m writing a program that reads huge file (3×280 GB) and does a fitting

  • 0

I’m writing a program that reads huge file (3×280 GB) and does a fitting procedure to the data in the file. It’s pretty convenient to parallelise such a program, where this is easily done with OpenMP.

The thing I don’t understand is how private variables are taken in OpenMP. As we all know, fstream’s obejcts are a non-copyable, and intiuitively, that prevented me from using it as a private object. So the reader of the file was shared.

I got some problem later, and I thought of trying have fstreams as private, … and guess what? it worked!!! How could this be possible?! if the object is non-copyable, how could OpenMP use different copies of the same object for each kernel?

This is how my program looks like:

fstream dataReaderX(Dirs[0].c_str(), ios::in | ios::binary);
fstream dataReaderY(Dirs[1].c_str(), ios::in | ios::binary);
fstream dataReaderZ(Dirs[2].c_str(), ios::in | ios::binary);
#pragma omp parallel num_threads(cpus_num) shared(...) private(...,dataReaderX,dataReaderY,dataReaderZ)
{
...
}

Thank you.

  • 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-05T19:35:24+00:00Added an answer on June 5, 2026 at 7:35 pm

    firstprivate variables are copied, not private – for the latter the default constructor is called:

    Section 2.9.3.3 – private clause:

    The new list item is initialized, or has an undefined initial value, as if it had been locally declared without an initializer. The order in which any default constructors for different private variables of class type are called is unspecified. The order in which any
    C/C++ destructors for different private variables of class type are called is unspecified.

    Here is a simple demonstration code:

    #include <fstream>
    #include <stdio.h>
    #include <omp.h>
    
    int main (void)
    {
       std::fstream reader("test.txt", std::ios::in);
       printf("Main thread: reader.is_open() = %d\n", reader.is_open());
       #pragma omp parallel private(reader)
       {
          printf("Thread %d: reader.is_open() = %d\n",
                 omp_get_thread_num(), reader.is_open());
       }
       return 0;
    }
    

    And here is the output as expected:

    Main thread: reader.is_open() = 1
    Thread 1: reader.is_open() = 0
    Thread 0: reader.is_open() = 0
    Thread 3: reader.is_open() = 0
    Thread 2: reader.is_open() = 0
    

    One funny thing is that Intel C++ Compiler errs with internal error (a failed assertion) – tested with versions 11.1, 12.0 and 12.1. On the other hand GNU C++ compiler adheres to the standard (the output above is from g++). Both compilers complain when firstprivate is used instead although Intel C++ Compiler again errs with internal error.

    It may sound stupid but did you check that you have enabled OpenMP support in the particular compiler that your are using?

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a

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.