简体   繁体   English

使用MATLAB进行并行图像处理

[英]Parallel image processing with MATLAB

I have written a MATLAB program which performs calculations on a video. 我编写了一个MATLAB程序,可以对视频进行计算。 I think it is a perfect candidate to adapt to multiple cpu cores as there is a lot of averaging done. 我认为它是适应多个cpu内核的理想选择,因为要进行很多平均处理。 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. 说(为简单起见),它是一个200帧的文件。 I have read some guides and using SPMD gotten this. 我已经阅读了一些指南,并使用SPMD做到了这一点。

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). 它成功输出每个工人将在各自的部分工作(例如,实验1在1:50,实验2 50:100等)。

Now where I am stuck is how do actually make my main body of code work on each Lab's section of frames. 现在,我陷入困境的是如何真正使我的代码主体在每个Lab的框架部分上工作。 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? 现在有提示或简单的方法来编辑我的主代码,以便它根据labindex知道要处理哪些框架? Adding spmd to the loop results in an error hence my question. 将spmd添加到循环会导致错误,因此是我的问题。

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). 当然,如果这是您正在做的事情,则可能需要序列化框架写入(即,确保一次仅写入一个进程)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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