# Run Python function in parallel on GPU

**URL:** <https://discuss.ray.io/t/run-python-function-in-parallel-on-gpu/4788>\
**Category:** Ray Core\
**Created:** [January 26, 2022, 1:52am UTC](https://discuss.ray.io/t/run-python-function-in-parallel-on-gpu/4788 "2022-01-26T01:52:19Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![LoveRay](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/loveray/32/1450_2.png) [@LoveRay](https://discuss.ray.io/u/LoveRay)\
**Post date:** [January 28, 2022, 1:04pm UTC](https://discuss.ray.io/t/run-python-function-in-parallel-on-gpu/4788/11 "2022-01-28T13:04:59Z")

</div>

Hi, Matthew. Thanks for the reply. I understand your concern. I tried to run it myself. But using the simulator running on the ray worker requires a CUDA context. In normal multiprocessing, I can just use:

```auto
context=mp.get_context('spawn')#NOTE: without spawn context will fail as it uses CUDA!
self.ps = context.Process(target=worker, args=(...))

```

And if not specifying context like above, I would receive errors like follows:

```auto
#can be solved with 'spawn' context
 CUDA error at /root/liuwj/Skeletal-Fluid/src/MeshLoad/MeshDatatGPUKernel.cu:37 code=101(cudaErrorInvalidDevice) "cudaGetLastError()"

```

When I replace `multiprocessing` with `ray`, I found the exact same error message is produced. Thus I was not able to test that with ray workers. I guess it might be the problem of the context, but I was not able to finish my test. Thus I raised a new thread [here](https://discuss.ray.io/t/specifying-multiprocessing-context-in-ray-worker/4791).

---

_[View the full topic](https://discuss.ray.io/t/run-python-function-in-parallel-on-gpu/4788)._
