Multithreading with C++ API
i am trying to parallel my program using OpenMP and sometimes i feels that i am reaching a dead end.
I would like to share variables in a fu开发者_Python百科nction member that i defined (and initialized) in the class. If i understood correctly, it is not possible doing #pragma omp parallel shared(foo)
of data members (e.g. int
, boost::multi_array
and std::vector
) of a class.
e.g.: using push_back() on a vector data member in the class.
updating values of a boost::multi_array
.
My question is if OpenMP is the right tools for it, or should i use boost::thread or tbb? or something else... what support C++ API
Reagrds
As the documentation states, shared
defines that an object is placed only once in the memory. For example if your foo
object contains a std::vector
of some type, it should be perfectly ok to push_back
items within the loop. But you should make sure, that your code is thread safe, either by atomic instructions or with mutex sections.
精彩评论