how to Parallize independent jobs
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
Jeff Miller
2021-4-30
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...
回答(1 个)
Edric Ellis
2021-5-4
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)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel Computing Fundamentals 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!