Parfor with COMSOL object

19 Ansichten (letzte 30 Tage)
christober
christober am 4 Nov. 2015
Kommentiert: christober am 5 Nov. 2015
Dear Concerned,
I have been reading through parallel processing toolbox lately to integrate COMSOL with matlab parallel processing and i am new to parallel processing with matlab aswell.
However i am struggling with the below problem.
In a parfor loop in am forced to load a COMSOL model object like the one below: "model = mphload('LIB_9AH_1D.mph');"
parfor i = 1:2
comsolPort=[2036 2037];
t = getCurrentTask();
labit=t.ID;
mphstart(comsolPort(labit))
import('com.comsol.model.*');
import('com.comsol.model.util.*');
model = mphload('LIB_9AH_1D.mph');
end
Later i want to refer the 'model' object outside the parfor loop. I am doing this to invoke two COMSOL process in parallel to work with matlab.
However i get an error saying "Temporary variable model is used after the parfor loop,but its value is not available after the loop"
How to make a object value available after the parfor loop?. Any ways to approach this problem will be really helpful.
Matlab version and details:
MATLAB Version: 8.2.0.701 (R2013b) MATLAB License Number: 595731 Operating System: Microsoft Windows 7 Version 6.1 (Build 7601: Service Pack 1)

Akzeptierte Antwort

Edric Ellis
Edric Ellis am 4 Nov. 2015
Outputs from a parfor loop need to be either sliced outputs, or reductions. In this case, a sliced output is probably most appropriate. You could put the model into a cell array:
parfor i = 1:2
...
model{i} = ...;
end
  1 Kommentar
christober
christober am 5 Nov. 2015
Dear Edric,
Thank you for the solution. I am able to access the model object this way inside the parfor loop
parfor i = 1:2
model{i} = mphload('LIB_9AH_1D.mph');
model{i}.variable('var8').set('D1_neg',D1_N{i}, 'Diffus');
end
However i am not able to access the model object outside parfor.
parfor i = 1:2
model{i} = mphload('LIB_9AH_1D.mph');
model{i}.variable('var8').set('D1_neg',D1_N{i}, 'Diffus');
end
check_model = model{1};
In the above case 'check_model' is a empty matrix. The reason for doing this is the above code segment is inside a objective function and when each time the function is called the model gets loaded. However i wish to load the model once in the main file and pass it as a parameter to the objective function (to reduce the execution time).
I have accepted the above answer as it partly solved my problem.
Thank a lot.
Kind regards,
Chris

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Parallel for-Loops (parfor) finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by