2

私は現在、時間のかかる MATLAB 関数を複数回並行して実行する必要があるプロジェクトに取り組んでいます。この質問の目的のために、関数を と呼びましょうmyfunc

myfuncMEX ファイルを使用し、最終的に 3 時間ごとにランダムなセグメンテーション違反が発生します。自分でコーディングしていない適切な API に起因するため、セグメンテーション違反を診断できません。ただし、これが MEX ファイル内で発生することはわかっています。また、変更可能な設定とは決定論的に関連していないこともわかっています。

セグメンテーション違反を回避したいと考えています。理想的には、MATLAB で parfor 関数を引き続き使用したいと考えています。今の私の考えは、次のように parfor ループ内で try catch ループを使用することです。

    %create an output cell to store nreps of output from 'myfunc'
    output = cell(1,nreps) 

    %create a vector to keep track of how many runs finish successfully without the error
    successfulrun = zeros(1,nreps);

    % run myfunc in parallel
    parfor i = 1:nreps
       try
        output{i}
        successfulrun(i) = true
       end
    end

    %rerun experiments that did not end up successfully
    while sum(successulruns) < nreps

      %count number of experiments to rerun and initialize variables to hold those results
      reps_to_rerun = find(successfulruns == 0);
      nreps_to_rerun = sum(reps_to_rerun);
      newoutput = cell(1,nreps_to_rerun);
      newsuccessfulrun = zeros(1,nreps_to_rerun)

      %rerun experiments
      parfor i = 1:nreps_to_rerun
         try
          newoutput{i};  
          newsuccessfulrun = true;  
         end  
      end

     %transfer contents to larger loop
     for i = 1:nreps_to_rerun

        rerun_index =  reps_to_rerun(i);
        successfulrun(rerun_index) = newsuccessfulrun(i)

        if newsuccessfulrun(i)
            output{i} = newoutput{i};
        end 
    end
end

私の質問は次のとおりです。

  1. MEX ファイル内にセグメンテーション違反があったとしても、このような反復をさらに実行し続けてよいでしょうか? または、メモリをクリアするか、matlabpool を再起動する必要がありますか? セグメンテーション違反は C にあったため、これは問題にはならないと思います。

  2. parfor ループから「抜け出す」方法はありますか?

4

1 に答える 1

0

シリアルで実行されていないため、parforループから抜け出すことはできません。このため、parforループをネストすることはできません。^ 1

スペースが不足している場合は、JVMのメモリ割り当て制限を増やす必要があります。^ 2

引用された作品:

  1. https://docs.google.com/viewer?a=v&q=cache:MinlgB0S8fsJ:its2.unc.edu/divisions/rc/training/scientific/short_courses/ParallelGPUMATLAB.pptx+&hl=en&gl=us&pid=bl&srcid=ADGEEShtEaahOf7u01kO0v Asy8itHNzuo4xocdoM5kiAuSCWlHZlKKb-W3Lvftpd6HJJAeyp6Lt-ofaBVH1uG049DFuAzdiu4ElNCtiTeFfYYbSGsJN5JF4S-AKjmWnmIpWIRNHHnR&sig=AHI
  2. http://www.mathworks.com/help/distcomp/parfor.html
于 2013-02-14T04:33:47.940 に答える