Skip to content Skip to sidebar Skip to footer

Pybind11: Accessing Python Object With Openmp Using For-loop

I am trying to operate a c++ function on all elements of a python dictionary. For this I use a for loop in c++ over all elements of the dictionary. In this case and as far as I und

Solution 1:

The problem is indeed accessing the python object with multiple threads. I don't know the exact reasons why, but this is simply impossible. The trick is to transform your python object into a list of python objects, which must be converted into a vector. Only then, the multiple threads access the various python objects of the vector.

In my case, I passed not the entire dictionary rather than the values of the dictionary in a list, and then converted this list into a vector of python objects.

In resumé it is something like:

error.create_seq(list(dict.values()))

and in c++:

std::vector<py::object> = dict.cast<std::vector<py::object>>();

and then the #pragma omp parallel clause can be applied

Post a Comment for "Pybind11: Accessing Python Object With Openmp Using For-loop"