how to Parallize independent jobs

3 visualizzazioni (ultimi 30 giorni)
Daniel Parisi
Daniel Parisi il 30 Apr 2021
Commentato: Daniel Parisi il 4 Mag 2021
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 Commento
Jeff Miller
Jeff Miller il 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...

Accedi per commentare.

Risposte (1)

Edric Ellis
Edric Ellis il 4 Mag 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)

Categorie

Scopri di più su MATLAB Parallel Server in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by