Output discrepancy while using Boost, STLs and OpenMP

General OpenMP discussion

Output discrepancy while using Boost, STLs and OpenMP

Postby sarthakp » Fri Aug 16, 2013 11:41 pm

I am facing issues in my code where I use C++ STLs (vector, queue & map ) and Boost Graph Library. Parallelization is implemented by basic compiler #pragmas.

The outline of the program is as follows :
Code: Select all
fileList = getListOfAllFiles(directory);   
#pragma omp parallel shared(fileList, inpName, outName)
#pragma omp for schedule(dynamic)
   for (int i=0;i<fileList.size();++i)
      vector<double> params(getParams(fileList[i])));                     //Reads the file and returns a vector
      result=func(fileList[i]);                                           //func description is given below      
      outFileName=replace_string(fileList[i], inpName, outName);       //inpName, outName are some constant strings      
      outputResult(result, outFileName);                               //File write operaion

}//end  parallel for
}//end parallel region

ResultType func (param)
   //This function calls multiple subroutines of Boost Graph Library (non-parallel version)
   (viz. MST, DIJKSTRA etc.)
    Moreover, this function is STL-heavy.   

I have no shared variable except the ones mentioned and I am not using any global/static variable in my code. Still the output that I am obtaining using -fopenmp switch while compiling (parallel version) is not same as the one that I am getting without using the switch (sequential version).

I read that operations like std::vector push_back is not thread-safe; but all the variables I am using are local to the function, hence should be private. (Am I missing something? )
Does the dynamic memory allocations (using new and std::vector push_back) inside the function func create any issue?

Any kind of insights will be helpful.
Posts: 1
Joined: Fri Aug 16, 2013 11:26 pm

Re: Output discrepancy while using Boost, STLs and OpenMP

Postby MarkB » Tue Aug 20, 2013 2:33 am

Hi there,

I presume result and outFileName are declared outside the parallel region somewhere? If so, they are shared by default, so need to be listed in the private clause to avoid race conditions.

Hope that helps,
Posts: 719
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot] and 4 guests