UseParallel + mexcuda: how to obtain CPU thread number?

I am using fsolve to solve a root-finding problem. The function evaluation component is expensive so I have written a mexcuda program to make use of GPUs. I have multiple GPUs on my system.
I would like to enable the "UseParallel" feature to compute Jacobians in parallel, with each instance of the evaluation calling a separate GPU. So my final program will look something like this:
root = fsolve(@objfun, "UseParallel", true);
function z = objfun(x)
z = GPUfunction(x, GPUdeviceToUse)
end
I would like to set the GPUdeviceToUse variable to depend on the CPU thread ID used within the "UseParallel" feature.
How can I obtain the CPU thread ID?

 Accepted Answer

I would expect that fsolve() has the same kind of initialization to verify that the function basically works, so there might be one invocation for which there is no thread . Maybe even one round to estimate the jacobian.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!