how to Parallize independent jobs
3 views (last 30 days)
Show older comments
I would like to send jobs i...j to workers i...j. In a way each worker acts as one independent matlab workspace. In other words, I would like to explictly indicate ot each worker to do one particular task and to contein the the variables in itself without sharing the variables values with other workers...
parfor is not usuful for that.
Can you give me and idea how to do it ? Thanks
1 Comment
Jeff Miller
on 30 Apr 2021
I'm not sure why parfor is unsuitable. If you call a function within the parfor loop, that function will have its own separate workspace unshared with other workers--why isn't that sufficient?
I guess in the extreme case you could open multiple instances of MATLAB on your computer and run each task in a different instance...
Answers (1)
Edric Ellis
on 4 May 2021
It's not clear why you think parfor is not suitable for this case without showing us what you tried and why it doesn't work for you. Workers in a parallel pool are separate MATLAB processes, and as such there is no sharing of data between them - so when you run a parfor loop, each worker gets copies of the necessary data.
If you really want to run fully independent MATLAB processes for each of your tasks, you can use batch to do that. Something like this:
numOutputs = 2; % number of output arguments from the function "myFunction"
inputArgs = {17, 3}; % Required input arguments for "myFunction"
j = batch(@myFunction, numOutputs, inputArgs);
wait(j)
fetchOutputs(j)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!