parfor in matlab. sliced variable and nested loop

后端 未结 1 1333
囚心锁ツ
囚心锁ツ 2020-12-02 01:09

I did my best to follow the documentation of the parallel toolbox, but still I could not avoid the problem of reusing array that was indexed in a nested loop. The problem i

相关标签:
1条回答
  • 2020-12-02 01:51

    According to the documentation you can not use different indices like you did:

    Within the first-level parenthesis or braces, the list of indices is the same for all occurrences of a given variable.

    A simple workaround is possible:

    parfor i=1:nX
       nodeSlice=node(i,:,:)
    
       for j=1:nY
    
    
        [ind,dist]=findInCircle(nodeSlice(j,:), part,r);
    
        UV=calcVelocity(part(ind,:), dist,nodeSlice(j,:)) ;
    
    
        %here matlab complains that node is not indexed properly
        nodeSlice(j,3)= UV(1);
        nodeSlice(j,4)= UV(2);
        nodeSlice(j,5)= UV(3);
    
    
    
       end
       node(i,:,:)=nodeSlice;
    
    end
    

    Get a slice from the matrix which contains all indices, work with it and then return it.

    0 讨论(0)
提交回复
热议问题