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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:50:26+00:00 2026-06-15T10:50:26+00:00

The schematic code shown below works fine if I remove the #pragma omp parallel

  • 0

The schematic code shown below works fine if I remove the #pragma omp parallel for, but with this in place the code compiles but then upon executing the binary I get errors like *** glibc detected *** ./testBin: double free or corruption (!prev): 0x0c43d8d8 *** and core dumped. I’m guessing that the reason is that multiple threads try to write to the variables omega, ell, .... or lineVec. How do I fix this? Is there a way to tell it the variables are shared? or is there just generally another way to do this loop in parallel. I am completely new to `openmp, this is the first time I have used it.

#include <omp.h>


int main( int argc , char **argv )
{ 
 vector <vector<string>> fileVec;
 //some code that reads in a CSV file lines into elements of fileVec

//variables constituting a line:
//my_float has been typedef to be a high precision class in real code
my_float omega;
my_float ell;

my_float init1Real;
my_float init1Imag;
my_float dinit1Real;
my_float dinit1Imag;

my_float init2Real;
my_float init2Imag;
my_float dinit2Real;
my_float dinit2Imag;

#pragma omp parallel for private(lineVec,fileVec,ell,omega,init1Real,init1Imag,dinit1Real,dinit1Imag,init2Real,init2Imag,dinit2Real,dinit2Imag)
 for (size_t i=0; i< fileVec.size(); i++) 
    { 

        lineVec=fileVec[i];


         ell=lineVec[0];
         omega=lineVec[1];

         init1Real=lineVec[2];
         init1Imag=lineVec[3];
         dinit1Real=lineVec[4];
         dinit1Imag=lineVec[5];
         init2Real=lineVec[6];
         init2Imag=lineVec[7];
         dinit2Real=lineVec[8];
         dinit2Imag=lineVec[9];


        // cout<<"OUTPUT ell=" << ell<< " omega=" << omega <<" init1Real="<<init1Real<<endl;

         //do some other calc involving these variables

    }     
   }
  • 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-15T10:50:27+00:00Added an answer on June 15, 2026 at 10:50 am

    Reading from a shared fileVec is thread-safe. Only the variables of type my_float should be made private or even better – declared inside the loop:

    int main(int argc, char **argv)
    {
        vector<vector<string>> fileVec;
    
        //some code that reads in a CSV file lines into elements of fileVec
    
        #pragma omp parallel for private(lineVec)
        for (size_t i = 0; i < fileVec.size(); i++)
        {
            lineVec = fileVec[i];
    
            //my_float has been typedef to be a high precision class in real code
    
            my_float ell = lineVec[0];
            my_float omega = lineVec[1];
    
            my_float init1Real = lineVec[2];
            my_float init1Imag = lineVec[3];
            my_float dinit1Real = lineVec[4];
            my_float dinit1Imag = lineVec[5];
            my_float init2Real = lineVec[6];
            my_float init2Imag = lineVec[7];
            my_float dinit2Real = lineVec[8];
            my_float dinit2Imag = lineVec[9];
    
            cout << "OUTPUT ell=" << ell << " omega=" << omega
                 << " init1Real=" << init1Real << endl;
    
            //do some other calc involving these variables
        }
    }
    

    I don’t see any races here unless my_float is not thread-safe or there is something else hidden in the //do some other calc involving these variables.

    Note that with recent OpenMP versions you can even use iterators to walk the vector, since it provides a random access iterator:

    typedef vector<vector<string>>::const_iterator iterType;
    
    #pragma omp parallel for private(lineVec)
    for (iterType it = lineVec.begin(); it != lineVec.end(); it++)
    {
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if its possible to generate vhdl code from a schematic in
This is my piece of code.Im getting all the tables names and col names
Short version: $count in the code below seems to be 0 even when it
I am creating Multimedia components using core service and everything is working fine. But
My problem is best outlined with this schematic/image which outlines how I want it
Take the following, schematic html-code: <div> <span id='1' cust-attr='' /> <span id='2' /> <span
This should be quick to an expert, but I'm relatively new at defining functions
I'm trying to use the OpenSqlFilestream Instruction but my code did not recognise it
This is a long shot, but I thought I might try before starting the
I have asked this question before and attempted to solve it multiple time but

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.