Class with static variables in parallel global optimization algorithm

3 ビュー (過去 30 日間)
Omar Kamel
Omar Kamel 2019 年 2 月 8 日
編集済み: Matt J 2019 年 3 月 21 日
Hello,
I have a global optimization program dealing with large matrices (several gigabytes of data), so in order to save memory, a class with static variables was implemented similar to the implementation in Static Data, and then one object of this class is created, initialized and passed as an argument to a function handle acting as the objective function of global multistage optimization algorithm (Particle Swarm + Pattern Search). When parallelization in optimoptions is true:
optimoptions( ...
'UseParallel', true);
The optimization always yields false results, but when parallelization is turned off, it works correctly.
Thanks in advance!

回答 (2 件)

Matt J
Matt J 2019 年 2 月 8 日
編集済み: Matt J 2019 年 2 月 8 日
All variables are cloned when parallelization is used. Each parallel worker operates with an independent copy of any variable sent to it.
  5 件のコメント
Matt J
Matt J 2019 年 2 月 8 日
Okay, but we also need to see how it is used in the optimization.
Omar Kamel
Omar Kamel 2019 年 2 月 14 日
編集済み: Omar Kamel 2019 年 2 月 14 日
Sorry for the late reply.
%create object and initialize
dampingModelDataObject = cDampingConstData; %create object of type cDampingConstData
dampingModelDataObject.setget_delta_A_to_delta_d(delta_A_to_delta_d); %initialize object with fields
dampingModelDataObject.setget_A_0_0(A_0_0); %initialize object with fields
dampingModelDataObject.setget_states_num(A_0_0); %initialize object with fields
%objective function handler, object is passed to it with another constant inputs and d as variable
fun = @(d) DampIT.SumModalDamping_sparse_oo(reshape(d,1,1,num_damping_coefficients), dampingModelDataObject,targetModalDamping);
%optimization options
options = optimoptions('particleswarm', 'Display', 'iter', ...
'HybridFcn', {@patternsearch, patternsearch_hybrid_options}, ... %hybrid optimization
'MaxTime', obj.settings.pp_swarm_maxTime, ...
'MaxIterations', obj.settings.pp_swarm_maxIter, ...
'FunctionTolerance', obj.settings.pp_swarm_tolFun, ...
'PlotFcn', { @pswplotbestf}, ...
'SwarmSize', obj.settings.pp_swarm_swarmSize, ...
'OutputFcn', memLog_swarm, ...
'UseParallel', useparallel_flag, ... %true
'UseVectorized', false, ...
'MaxStallIterations', obj.settings.pp_swarm_maxStallIter, ...
'InitialSwarmMatrix', InitialSwarmMatrix);
%problem settings
problem.solver = 'particleswarm';
problem.objective = fun;
problem.nvars = num_damping_coefficients;
problem.lb = x_start;
problem.ub = x_end;
problem.options = options;
%start optimization
[d_optimized, fval, exitflag, output] = particleswarm(problem);

サインインしてコメントする。


Walter Roberson
Walter Roberson 2019 年 2 月 14 日
Look again at the link you provided . Notice the point about static data not being saved with an object . The process of sending variables to parallel workers involves save and load.
  3 件のコメント
Walter Roberson
Walter Roberson 2019 年 3 月 21 日
However, that saves the matrix once per worker, not "only 1 time in the memory". If you strictly need "only 1 time in the memory" then you should look in the File Exchange for https://www.mathworks.com/matlabcentral/fileexchange/28572-sharedmatrix which uses operating system shared memory.
Matt J
Matt J 2019 年 3 月 21 日
編集済み: Matt J 2019 年 3 月 21 日
Interesting.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSurrogate Optimization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by