Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How to Execute Parallel program through SPMD or BATCH or TASK?

Asked by PRIYANGA on 29 Jun 2012

Hi Everybody,

I need one Help From You.I want to execute my code parallel using SPMD. But not able to Run It. Already I was try to parfor Loop But I don't Know how to classify the Variable. So now I am try to run parallel through SPMD concept. But this program Run in same duration for each worker. But i want to split the work and run parallel.

This is my sample code

Otherwise how can I Run parallel program through TASK or BATCH. Thank You so much.

0 Comments

PRIYANGA

Products

No products are associated with this question.

1 Answer

Answer by Edric Ellis on 29 Jun 2012
Accepted answer

Inside an SPMD block, you need to use a for-loop over a distributed range.

In short

spmd
  for i1=drange(1:n)
    ...
  end
end

5 Comments

PRIYANGA on 13 Jul 2012

Sir, My starting prgm....

clc;
close all;
clear global oldrand;
clear global jrand;
clear all;
warning ('off','all');
spmd
    global oldrand;
    global jrand;
    tic;
    % read the image
     im1=imread('C:\Program Files\MATLAB\PIC\lena.jpg');
    c = im2uint8(im1);
    % Split the R-G-B Component
    R=c(:,:,1);
    G=c(:,:,2);
    B=c(:,:,3);
    seedval=.5;
    oldrand(55)=seedval;
    newrand=.000001;
    prevrand=seedval;
    for j=1:54
        i=floor(21*j / 55);
        k=21*j-i*55;
        oldrand(k)=newrand;
        newrand=prevrand-newrand;
        if (newrand<0.0)
            newrand=newrand+1;
        end
        prevrand=oldrand(k);
    end
    advancerandom;
    advancerandom;
    advancerandom;
    jrand=0;
end

That above code advancerandom is a function , its contain the global variable, but spmd concept not contain global variable so how can i declare the global variable in SPMD concept?

thank you sir..

Walter Roberson on 13 Jul 2012

What result are you hoping to get out in "oldrand", considering that each of the spmd blocks is trying to write in the same set of locations, oldrand(1:55) ? Are you expecting to get a series of "oldrand" arrays out, one per lab? Are you expecting that "oldrand" will be self-consistent and containing only values from the "last" lab that gets executed? Are you expecting that "oldrand" will have a frightful mess of values, depending, location by location, on exactly which of the labs happens to write to each of the locations last, a matter which will differ from location to location ?

Though perhaps I am being too harsh, as there is no evidence in what you show that you are actually using any randomization at all: your "random" values are just sequential values .000001 smaller each time, and so would be the same for all the labs. As you do exactly the same thing in every lab, you might as well remove the spmd block and just do the activity once.

PRIYANGA on 13 Jul 2012

ok sir thank you

Edric Ellis

Contact us