English 中文(简体)
材料平行工具箱: par平地
原标题:Matlab Parallelism toolbox : stacking loops in parfor

I m trying to use the parfor loop in the matlab parallelism package. I m having a similar problem to this guy : MATLAB parfor slicing issue? . The output matrix doesn t seem to be recognized as a sliced variable. In my specific case, I m trying to stack use other for loops inside the parfor, and I have trouble applying the solution proposed in the other thread to my problem. Here is a dummy example of what I m trying to do :

n=175;
matlabpool;

Matred=zeros(n,n);

Matx2Cell = cell(n);

parfor i=1:n
    for j=1:n
        for k=1:n

            Matred(j,k)=exp((j+i+k)/500)
        end;
    end;
    Matx2Cell{i}=Matred;

end;
matlabpool close;

P.S.,我知道,它将努力将 par子放在 k上,而不是一lo。 但是,我仍然想把它放在一路上(我认为,在我的真正方案中,这样做会更具有时间效率)。

Thanks a lot Frédéric Godin

问题回答

您可以将<条码>Matred = 零s(n); 放入教区,但这非常缓慢。 而是用<代码>Matred = 零s(n);界定职能:实际上相同,但速度更快:

function Matred = calcMatred(i,n)
Matred=zeros(n);
for j=1:n
    for k=1:n
        Matred(j,k)=exp((j+i+k)/500);
    end
end

时间比较:

matlabpool
n = 175;
Matx2Cell = cell(n,1);

tic
parfor i=1:n
    Matred=zeros(n);
    for j=1:n
        for k=1:n
            Matred(j,k)=exp((j+i+k)/500);
        end
    end
    Matx2Cell{i}=Matred;
end
toc

tic
parfor i=1:n
    Matx2Cell{i}=calcMatred(i,n);
end
toc

matlabpool close

在我的机器上,头一台需要7秒,第二次需要0.3秒。

请注意,I ve更改了<代码>Matx2Cell至cell(n,1),因为cell(n) 做了n x n 手机阵列。

你们需要把马塔德迁入 par院。 之所以需要这样做,是因为每 par一堂,都需要一份新版的马塔德。

n=175;
matlabpool;

Matx2Cell = cell(n);

parfor i=1:n
    Matred=zeros(n,n);
    for j=1:n
        for k=1:n

            Matred(j,k)=exp((j+i+k)/500)
        end;
    end;
    Matx2Cell{i}=Matred;

end;
matlabpool close;




相关问题
Memory Leak when using for(object in array) with iPhone SDK

I am running into some serious memory leaks in one of my applications I am building. I have a UINavigatonController that is inside a UITabBarview. Inside the NavView is a MKMap view. When you click an ...

PHP - Foreach loops and ressources

I m using a foreach loop to process a large set of items, unfortunately it s using alot of memory. (probably because It s doing a copy of the array). Apparently there is a way to save some memory with ...

as2 simple for loop not populating textbox

I have got an xml file that brings text into a flash movie in the form of an array, I need to population some textboxes and want to do this using a for loop. My loop look like this: for(var i=...

Weird acting loop in C#

Note: I added actual code snippets. Just scroll to end. // files is created by a OpenFileDialog. public void Function(String[] files, ...) { for(int i; i<files.Length; i++) { ...

iterating over map and array simultaneously in a for loop

I am having some trouble creating a for loop within a constructor to iterate over a map and an array at the same time. Here, it is indicated that this cannot be done with an enhanced for loop. I have ...

Are one-line if / for -statements good Python style?

Every so often on here I see someone s code and what looks to be a one-liner , that being a one line statement that performs in the standard way a traditional if statement or for loop works. I ...

Geocoding town names to their coordinates in a loop

I ve read similar posts, but still didn t find a solution for myself. Basically I have an array with countries+towns in PHP and I need to show them on the map with markers. Here is my code: function ...

热门标签