Problems in parallel computing of COMSOL model
Ältere Kommentare anzeigen
Regarding the parallel computing of the COMSOL model, the method previously used
for j=1:1000
parfor i=1:iter
port=mphstartcomsolmphserver
mphstart(port)
model = mphload(mph);
mphsetparam(model, 'P_load1', j);
However, during execution, it was found that loading the model with mphload takes a long time, which means that every time parfor is performed, the loading model needs to be called repeatedly. Therefore, the current idea is how to only call the model once and then update the parameter mphsetparam (model, 'P_load1', j) in the parfor loop; This shortens the running time. Encountered problem 1 during the process:
spmd
if spmdIndex<= numModels port=mphstartcomsolmphservermphstart(port)
model=mphload(modelFiles{spmdIndex});
else
model = [];
end
end
Unable to locate the model, there was an index localization exception when inputting model {i}, which means the corresponding working range of the model cannot be located. When saving the model in an array or other form, there was a problem with the model (mph) not being serialized
6 Kommentare
jiangtao
am 11 Feb. 2025
You should seek help from the authorities
Walter Roberson
am 11 Feb. 2025
One problem is that spmdIndex is from 1 to the number of labs, not from 1 to the number of model files.
You cannot start spmd with an arbitrary number of labs; the number of labs created is no more than the size of the parpool .
jiangtao
am 11 Feb. 2025
I guess the code is as follows,numModels ==2
spmd
if spmdIndex<= numModels
port=mphstartcomsolmphservermphstart(port)
model=mphload(modelFiles{spmdIndex});
else
model = [];
end
end
the number of labs created is no more than the size of the parpool .parpool is10 ,numodels=2。
The core of the problem lies in the inability to locate the model by placing it in an array or model {i}。
jiangtao
am 11 Feb. 2025
Dear JIN
We are now trying to deconstruct your question. Your current concern is that you want to use model {i} to locate your COMSOL file (mph) and perform parameter operations. As far as I know, Parfor parallel computing data such as current and voltage time series data can be placed in the main workspace. That is to say, for unstructured data such as models (mph), there may be other methods to index and locate them. I suggest you go to communities like GT_Suit that also involve parallel computing with Maltba to see if there are any examples。
jiangtao
am 11 Feb. 2025
dear Walter Roberson
Do you have any suggestions or thoughts。
Antworten (1)
jiangtao
am 18 Feb. 2025
0 Stimmen
i have a solution ideas:Constant
Kategorien
Mehr zu Parallel for-Loops (parfor) finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!