1

I have this complex function in C++ that I'm unable to modify. It was written to take in an array, do some math, and output an array.

It is currently structured in a non-parallel way.

For ease of use, it is being exported into Python with Pybind11.

I'm trying to find ways of speeding up the processing so I've looked into things like Thread() and ProcessPoolExecutor but I'm not sure if putting a C++ function into those will then be able to take advantage of it.

Perhaps if the C++ function would take in a float and return a float, then I can cycle through the array in Python and that would be able to utilize ProcessPoolExecutor.

Is my understanding correct? Do y'all have any other ideas?

I've tried writing some C++ functions and wrapping them in Pybind11 but I'm skeptical of the benchmark times - that my efforts to parallelize them aren't really valid.

I was going to try to follow this example of image flipping but put the actual processing in C++ like in this tutorial.

This is more of a theoretical problem than a specific error message.

  • 1
    Please provide enough code so others can better understand or reproduce the problem. – Community Jun 21 '23 at 15:44
  • does it return an array or populate a passed reference? how do you know it's slow? can you pass your data in blocks to the process (perhaps approximately equal data by-cores?) or does it need all the data to work? – ti7 Jun 21 '23 at 16:15
  • If it could take chunks in, then that'd be solid cause I can use that ProcessPoolExecutor and split up the input array, right? But, I believe, if I'm reading it correctly, it needs all the data to work. – GregePorter Jun 21 '23 at 19:48
  • You can run C++ code in parallel through pybind11, but you have to tell pybind11 release the GIL. Actual throughput improvement may obviously vary based on your actual bottleneck – unddoch Jun 26 '23 at 10:48
  • Thanks, @unddoch, I'll check into that. I see [a question from a couple years ago where they discuss GIL and pybind11](https://stackoverflow.com/questions/59740219/releasing-the-gil-in-pybind11-for-multithreading-in-python-with-openmp). I'll have to check out but glancing over the thread, it seems like if I'm hoping to do some parallel processing, I'll have to either chunk the data, as ti7 mentioned, or rework the C++. – GregePorter Jun 26 '23 at 16:33

0 Answers0