I have tried some simple examples regarding implementing boost::python in OpenMP. Here is the one:
#include <omp.h>
#include <iostream>
#include <boost/python.hpp>
namespace p = boost::python;
int main() {
Py_Initialize();
p::object glob = p::import("glob");
// glob.glob list more than 7000 files
p::object paths = glob.attr("glob")("C:\\path\\to\\the\\dir\\location");
#pragma omp parallel for default(shared) schedule(dynamic)
for (int i = 0; i < p::len(paths); i++) {
std::cout << p::extract<const char *>(p::str(paths[i])) << std::endl;
}
std::cout << "finished: " << p::len(paths) << std::endl;
return 0;
}
The code has worked if not using OpenMP. However, I have an error of 139 if using it. I also have tried using Python API (PyObject *), but it was still getting the same problem. I have pointed out that the problem is while we imported the Python modules.
Therefore, is there any possibility that we can use parallel programming on either boost::python or Python C API, especially while we use the Python modules on C++?