Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 function 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

like image 480
Eagle Avatar asked Nov 14 '22 20:11

Eagle


1 Answers

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.

like image 67
Constantinius Avatar answered Dec 20 '22 05:12

Constantinius