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.