parallel computing fitness function inside parallel optimization
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Rui
am 29 Aug. 2023
Kommentiert: Sam Marshalik
am 1 Sep. 2023
I have a calculation intensive fitness function to optimize in genetic optimization.
I plan to use matlab parallel server with 10 compute nodes, each on has 24core. Can I run each objFunction parallel in GA and parallel in each nodes?
Following is example code and target
- 40 poulation,
- UseParallel On in GA options
- Can assign each objFuntion evaluation to indivadual 24core compute and use another parfor inside objFunction?
- Therefore, it allowed me run 10 parallel objFunction on 10 node. Each objfunction run parallel in each node.
Thanks
% parallel on and 40 population
options = optimoptions('UseParallel',true,'PopulationSize',40);
[x,fval,exitflag,output] = gamultiobj(@objFunction,20,[],[],[],[],lb,ub,options);
%% fitness function required to run parallel
function output = objFunction(x)
a = 1:10000;
output = zeros(1,numel(a));
parfor i = 1:numel(a)
output(i) = a(i) + mean(x);
end
end
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 29 Aug. 2023
Inside a parallel worker you can vectorize, but not run anything in parallel.
You would need to run multiple matlab sessions, each taking on part of the task.
5 Kommentare
Sam Marshalik
am 1 Sep. 2023
Hey Rui,
It is a bit tricky, but you can do this.
I first wanted to make sure that gamultiobj could run in a Threaded environment. I confirmed that it is possible by startung a local Thread Pool and running an example there. This means that a MATLAB Parallel Server process worker will be able to start a Threaded pool of workers and run the optimization problem in parallel using Threads.
The next question is how to actually offload this to the cluster. Can you let me know what scheduler you are using? Depending on what scheduler you are using the answer will be different.
I think using batch jobs will be a good way forward, like the below. Each batch job will start a single process worker and then start X number of Threads. The detail to be worked out is how to request the right resources from ths scheduler. You will want to ask for a total of X + 1 cores (1 for the MATLAB Parallel Server worker and X for the Threads).
c = parcluster('myCluster');
c.NumThreads = X;
batchJob = batch(p,@optimFunc, c.NumThreads)
function optimFunc(NumThreads)
parpool("Threads", NumThreads)
rng default % For reproducibility
M = diag([-1 -1]) + randn(2)/4; % Two problem variables
fun = @(x)[(x').^2 / 30 + M*x']; % Two objectives
intcon = 2;
lb = [0 0];
ub = [100 50];
options = optimoptions("gamultiobj","PlotFcn","gaplotpareto",...
"PopulationSize",100, 'UseParallel', true);
nvars = 2;
A = [];
b = [];
Aeq = [];
beq = [];
nonlcon = [];
[x,fval] = gamultiobj(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,intcon,options);
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Parallel Computing Fundamentals 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!