2015-12-18 11 views
0

我已經做了matlab中的循環parralel,但我得到警告,我的一些陣列廣播,導致不必要的通信開銷。我是matlab新手,不知道如何解決這個問題。有人會幫助我嗎? AY在此代碼廣播如何解決parloop中的廣播變量問題?

parfor k=1:length(gamma) 

    Lambda=gamma(k); 
    tmp=zeros(nfolds,Num_Tasks); 

    for p=1:length(omega) 

     OmegA= omega(p) 
     for Fold=1:size(Fold_indices,2) 
      % Creat train and test fold 
      A_Train=A(logical(Fold_indices(:,Fold)),1:end); # A is broadcasted 
      %size(A_Train) 
      Y_Train=Y(logical(Fold_indices(:,Fold)),1:Num_Tasks); # Y is broadcated 

      A_Test=A(~logical(Fold_indices(:,Fold)),1:end); 
      Y_Test=Y(~logical(Fold_indices(:,Fold)),1:Num_Tasks); 
      coff=Estimate_x(Y_Train,A_Train,Lambda,OmegA,Binding_matrix) ; 


      % Do the prediction on Kth f;old and compute the error 
      % coff 
      %sum((A_Test*coff-Y_Test).^2) ./ size(A_Test,1) 
      tmp(Fold,1:end)=sum((A_Test*coff-Y_Test).^2) ./ size(A_Test,1); 
      tmp; 
      %Coefficents{:,Fold}=coff; 
      coff 
     end 
     In_Fold_Error{1,p}=tmp; 
     %In_Fold_Error{2,k}= Lambda; 


     Coefficents{:,p}=coff; 
    end 
    CVErr_twoparam{1,k}=In_Fold_Error; 
    Coefficents_twoparam=Coefficents; 

end 
+1

請編輯您的問題並添加確切的錯誤消息或警告(逐字) – Dan

回答

0

除非你能計算A_TrainY_Train直接在parfor循環,而不是用在爲了下標從AY得到他們的價值觀,有什麼可以做。您的信息來源是獨一無二的,因此這些值將被廣播。

如果你有足夠的內存,也許這將是一個更好的主意來計算A_TrainY_Train作爲基質的細胞陣列在正常for,然後用parfor內這些順序預先計算的值。像這樣,您不會將整個矩陣AY發送給工作人員。