2014-07-20 2 views
0

아래 기능에서 어떤 현상이 발생합니까?Matlab에서 이와 같은 병렬 재귀가 있습니까?

출력을 해석하면 여러 재귀가 동시에 발생하는 것처럼 보입니다. 심지어 가능합니까 (병렬로 실행될 코드를 작성하지 않았습니다)

어떻게 해결할 수 있습니까?

최상위 함수 호출 :

for i = 1:n 
     chNo = cluster.no(i); 
     %if nodeArch.node(chNo).type ~= 'J';   %if type = J ie its an CH with no path to sink   
      nodeArch.node(chNo).dest = chNo;  %default self loop 
      packetLength = nodeArch.node(chNo).data; 
      packetLength = packetLength * roundArch.aggrFactor; 
      path = num2str(i); 
      clusterModel= forwardPacket(clusterModel, packetLength, chNo, nodeArch.node(chNo).connections, path); 

      if nodeArch.node(chNo).dest == chNo 
       nodeArch.node(chNo).type = 'J';  %set node as isolated CH  
      end 
     %end 
     nodeArch.node(chNo).data = 0 ;    %clearing local data 
    end 

재귀 기능 :

function clusterModel = forwardPacket(clusterModel, packetLength, chNo, connections,path) 
    nodeArch = clusterModel.nodeArch; 
    netArch = clusterModel.netArch; 
    cluster = clusterModel.clusterNode; 



    zone = nodeArch.node(chNo).zone; 
    if zone == 1    
     distance = sqrt((nodeArch.node(chNo).x - netArch.Sink.x)^2 + (nodeArch.node(chNo).y - netArch.Sink.y)^2); 
     nodeArch.node(chNo).energy = afterTransmissionLoss(packetLength, netArch, distance, nodeArch.node(chNo).energy); 
     nodeArch.node(chNo).dest = 0; % ie sink 


     for j = 1:nodeArch.numNode 
      if connections(j) == 1; 
       netArch.Sink.connected(j) = 1; 
       %disp(num2str(j)); 
      end 
     end 

     %This is the output block 

     path = strcat(path , ' > sink');   
     disp(path); 
     disp(netArch.Sink.data); 
     netArch.Sink.data = netArch.Sink.data + 1; 
     disp(netArch.Sink.data); 

     %end of output block 


     nodeArch.node(chNo).dest = 0; 
    else 
     n = length(cluster.no); % Number of CHs 
     for i = 1:n 
      destChNo = cluster.no(i); 
      if nodeArch.node(destChNo).zone == zone-1 
       distance = sqrt((nodeArch.node(chNo).x - nodeArch.node(destChNo).x)^2 + (nodeArch.node(chNo).y - nodeArch.node(destChNo).y)^2); 
       if distance <= netArch.Yard.nodeRange %check if CH is too far to send data 
        nodeArch.node(chNo).energy = afterTransmissionLoss(packetLength, netArch, distance, nodeArch.node(chNo).energy); 
        nodeArch.node(destChNo).energy = afterReceptionLoss(packetLength, netArch, nodeArch.node(destChNo).energy); 
        nodeArch.node(chNo).dest = destChNo; 


        %disp(strcat(num2str(destChNo),'>>' , num2str(destChNo) )); 
        path = strcat(path , ' > ' ,num2str(chNo)); 
        clusterModel = forwardPacket(clusterModel, packetLength, destChNo, connections, path); 
        nodeArch.node(chNo).dest = destChNo;      
        break; 
       end 
      end 
     end 
     nodeArch.node(chNo).type = 'J';  %set node as isolated CH 
    end 
    clusterModel.netArch = netArch; 
    clusterModel.nodeArch = nodeArch; 
end 

출력 :

2 >55 > sink 
    0 

    1 

6 >72 > sink 
    0 

    1 

7 >83 > sink 
    0 

    1 

8 > sink 
    0 

    1 

10 >106 >55 > sink 
    1 

    2 

15 >186 > sink 
    1 

    2 

16 >188 >55 > sink 
    1 

    2 

17 >192 >330 > sink 
    1 

    2 

21 > sink 
    1 

    2 

22 > sink 
    2 

    3 

26 >268 > sink 
    3 

    4 

27 >271 > sink 
    3 

    4.....and so on 

답변

0

내가 무엇을 알아 낸 잘못된

자바

또는 C 쓸 때

a=b; //where b is a structure/class 

a는 b의 참조입니다.

(Matlab)

a는 b의 값으로 초기화되는 다른 구조이다.

문제가되었습니다.

관련 문제