简体   繁体   中英

Parallel image processing with MATLAB

I have written a MATLAB program which performs calculations on a video. I think it is a perfect candidate to adapt to multiple cpu cores as there is a lot of averaging done. I am just sturggling with the first bit of sending each section of frames to each lab. Say (for simplicity) it is a 200 frame file. I have read some guides and using SPMD gotten this.

spmd
limitA = 1;
limitB = 200;  
a = floor(((limitB-limitA)/numlabs)*(labindex-1)+limitA);                               
b = floor((((limitB-limitA)/numlabs)*(labindex-1)+limitA)+(((limitB-limitA)/numlabs)));
fprintf (1,'Lab %d works on [%f,%f].\n',labindex,a,b); 
end

It successfully outputs that each worker will work on their respective section (Eg Lab 1 works on 1:50, Lab 2 50:100 etc).

Now where I am stuck is how do actually make my main body of code work on each Lab's section of frames. Is there a tip or an easy way to now edit my main code so it knows what frames to work on based on labindex? Adding spmd to the loop results in an error hence my question.

Thanks

Following on from what you had, don't you simply need something like this:

spmd
    % each lab has its own different values for 'a' and 'b'
    for idx = a:b
        frame = readFrame(idx); % or whatever
        newFrame = doSomethingWith(frame);
        writeFrame(idx, newFrame);
    end
end

Of course, if that's the sort of thing you're doing, you may need to serialize the frame writing (ie make sure only one process at a time is writing).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM