Parallel Computing in C when using Matlab Coder (parpool and gpuArray)
Show older comments
Hello,
In Matlab I'm able to run my code parallel either with utilizing "parpool" or "gpuArray".
Now, with the help of Matlab Coder I'm able to convert my code in C by generating a dynamic library, which I can access and run via Visual Studio.
Still, I have no clue how to run the generated code in Visual Studio parallel.
My thought was:
Using parpool and gpuArray in Matlab
-> Converting via Matlab Coder in dynamic library
-> Running in Visual Studio parallelized Code
I'm aware that Matlab is multi-processing and C is multi-threading, but I hope there is a possibility to tell Matlab during the convertation to get "multi-processing in multi-threading".
Thank you for any help in advance!
Accepted Answer
More Answers (1)
Joss Knight
on 13 Jan 2024
1 vote
GPU Coder will generate CUDA code for you. It can even automatically vectorize for loops. For a multithreaded parallel for loop, you're probably better off generating code for an ordinary for loop and then annotating it for appropriate OpenMP or TBB extensions. parfor is not supported for code generation.
3 Comments
Wladimir Plotnikov
on 14 Jan 2024
Joss Knight
on 15 Jan 2024
- GPU Coder and Parallel Computing Toolbox have different licenses. Maybe you have one and not the other. However, to generate or use GPU mex functions, GPU Coder requires a Parallel Computing Toolbox license.
- GPU Coder requires a compiler to be installed and MinGW does not work.
- The workflow is different. If you want to use Coder for desktop computation you have to first compile and then integrate a mex function into your MATLAB code. You would need to separately maintain the mex function code and the code using it.
- GPU Coder can vectorize for loops for you.
- Coder generates CUDA kernels that you can subsequently edit.
- There will be differences in performance and precise answers, since the implementations are not the same.
Wladimir Plotnikov
on 16 Jan 2024
Categories
Find more on Get Started with GPU Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!