Pergunta

I have a little parfor test script which gives the warning in the title. The code is this

out = zeros(10, 1);
in = rand(5e8, 10);
tic
parfor i = 1:10
    for j = 1:5e8
        p = floor(rand(1,1)*5e8);
        out(i) = out(i) + in(p, i);
    end
end
toc
tot = sum(out)

the warning comes out on line 7 regarding how variable in is accessed. I don't understand why, slicing should be trivial. Just send each column of in to each worker. If I change the code to

out = zeros(10, 1);
in = rand(5e8, 10);
tic
parfor i = 1:10
    a = in(:,i);
    for j = 1:5e8
        p = floor(rand(1,1)*5e8);
        out(i) = out(i) + a(p);
    end
end
toc
tot = sum(out)

the warning disappears but I don't like that assignment to a. The code was explicitly designed to mess up the cache memory.

Foi útil?

Solução

Unfortunately, as explained here http://www.mathworks.com/help/distcomp/advanced-topics.html#bq_of7_-1 , MATLAB does not understand how to slice in, hence the code analyser warning. You have to read that page fairly closely to understand why it cannot be sliced. The relevant paragraph is:

Form of Indexing. Within the list of indices for a sliced variable, one of these indices is of the form i, i+k, i-k, k+i, or k-i, where i is the loop variable and k is a constant or a simple (nonindexed) broadcast variable; and every other index is a scalar constant, a simple broadcast variable, colon, or end.

The clause in bold type at the end is the relevant one - in your case, p does not match this constraint.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top