Explanation

A for statement within a parfor loop must be a range of sequential numbers with a step value of 1. The form of the for loop must include an explicit colon operation between the low and high values. For example, if a parfor loop contains for ii = V, you need to adjust your code, even if V resolves to a contiguous series of values in a vector array with a step value of 1.


Suggested Action

Adjust the for loop statement within the parfor loop. For example, assume your code is similar to the following, where <myArray> is an actual array, such as [2, 6, 7] :


vectorValues = [1, 4, 9, 16, 25, 36, 49; 1, 8, 27, 64, 125, 216, 343];
vectorSequence = <myArray>;
parfor ii = 1:2
    for jj = vectorSequence
        val = vectorValues(ii, jj);
        sprintf('index = %d index = %d value = %d\n', ii, jj, val)
    end
end

Change your code as follows, depending on whether the vectorSequence array is sparse. Keep in mind that MATLAB transfers data to workers once per iteration.

If the vectorSequence array is sparse, use this code which results in fewer data transfers than the original code, but incurs the cost of copying the data into vectorValueSubset.


vectorValues = [1, 4, 9, 16, 25, 36, 49; 1, 8, 27, 64, 125, 216, 343];
vectorSequence = [2, 6, 7];
vectorValueSubset = vectorValues(vectorSequence);
parfor ii = 1:2
    for jj = 1:length(vectorSequence)
        val = vectorValueSubset(ii, jj);
        sprintf('index = %d index = %d value = %d\n', ii, vectorSequence(jj), val)
    end
end

If the vectorSequence array is not sparse, use this code which results in more data transfers than the original code, but does not incur the cost of copying data. The extra transfers are computationally lightweight.


vectorValues = [1, 4, 9, 16, 25, 36, 49; 1, 8, 27, 64, 125, 216, 343];
vectorSequence = [2, 3, 5, 6, 7];
parfor ii=1:2
    for jj =min(vectorSequence):max(vectorSequence)
        if (find( vectorSequence == jj))
            val = vectorValues(ii, jj);
            sprintf('index=%d index=%d value=%d\n', ii, jj, val)
        end
    end
end