UseParalle in Particleswarm doesn't star

조회 수: 7 (최근 30일)
Marta
Marta 2025년 2월 25일
답변: Abhishek 2025년 6월 27일
I am performing an optimization using particleSwarm (with the function implemented in MATLAB), where the goal is to minimize the error between the experimental displacements of a model and the predicted displacements from an FE model.
In the objective function passed to particleswarm, an Abaqus simulation is launched, which on average takes about one day to complete. To speed up the process and obtain an optimal result more efficiently, I would like to try using the UseParallel option of particleswarm.
However, it seems that even when setting UseParallel = true, once the code is executed, the objective function is not assigned to the specified workers, and the execution still runs sequentially instead of in parallel.
What could be the issue?
I appreciate any help on this matter.
  댓글 수: 2
Raymond Norris
Raymond Norris 2025년 2월 25일
  1. Is UseVectorized set to true or false?
  2. Do you have the Parallel Computing Toolbox?
  3. Are you running the code locally or on a remote machine/cluster?
  4. If locally, how many cores do you have?
Marta
Marta 2025년 2월 26일
  1. i set UseVectorixed to false
  2. yes, i have the toolbox
  3. i'm running my code on a remote machine beacuse it is a proget for my thesis and i have to use some programs that are on their pc
  4. i don't know exactly how many cores it has

댓글을 달려면 로그인하십시오.

답변 (1개)

Abhishek
Abhishek 2025년 6월 27일
Hi @Marta,
I understand that your Abaqus-based simulation still runs sequentially, even after setting the UseParallel’ to ‘true’. To ensure that your optimization runs efficiently in parallel when each function evaluation involves an external Abaqus simulation, a few key considerations can help set things up smoothly:
  • Activate a Parallel Pool: Ensure a parallel pool is running before you start the optimization. MATLAB will not parallelize unless a pool is available. You can do this manually by running the parpool('local');’ command in the command window.
  • Enable Parallel Evaluation in Options: Set the ‘UseParallel’ option while defining your solver configuration:
options = optimoptions('particleswarm', ...
'UseParallel', true, ...
'SwarmSize', 20, ...
'Display', 'iter');
  • Prepare Objective Function for Parallel Execution: The objective function should be written in a way that each evaluation is independent and safe to execute concurrently. A common practice when launching external solvers like Abaqus is to assign a unique working directory for each particle.
  • Verify parallel behavior: You may verify that the function is running on workers by including:
task = getCurrentTask;
if isempty(task)
disp('Running on main thread');
else
disp(['Running on worker: ' num2str(task.ID)]);
end
Hope this helps.

카테고리

Help CenterFile Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by