top of page

Parallel Jaya do loop with MATLAB & OMP

Most swarm intelligence algorithms allow parallelization when computing the objective function. Each particle can be assigned to each worker to call the solver and return the individual objective value.




The algorithm can be explained:


MATLAB parfor

function [x,f] = jaya_parallel(x,f,lb,ub,nPop,nVar,maxIt)

for it = 1:maxIt

   
    % --- Step 1: find best/worst

    [f_best, idx_best] = min(f);

    [f_worst, idx_worst] = max(f);

    x_best = x(idx_best,:);

    x_worst = x(idx_worst,:);

    newx = zeros(nPop,nVar);

    newf = zeros(nPop,1);


    % --- Step 2: parallel update

    parfor i = 1:nPop

        
        xi = x(i,:);     % read-only (safe)

        
        r1 = rand(1,nVar);

        r2 = rand(1,nVar);

        % Jaya formula

        newxi = xi + r1.*(x_best - abs(xi)) ...

                   - r2.*(x_worst - abs(xi));

        % Bound control

        newxi = max(newxi, lb);

        newxi = min(newxi, ub);

        % Evaluate objective

        newfi = objective(newxi);


        % Write to output (unique index i → safe)

        newx(i,:) = newxi;

        newf(i)   = newfi;

       
    end % parfor

    
    % --- Step 3: serial update of population

    for i = 1:nPop

        if newf(i) < f(i)

            x(i,:) = newx(i,:);

            f(i)   = newf(i);

        end

    end

end

end



Fortran OMP directives


ree


Recent Posts

See All
bottom of page