Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. MATLAB のホームタブで、並列メニューを選択します。[クラスタの作成と管理]を選択します。

  2. クラスタプロファイルの追加 > MATLAB Job Scheduler をクリックします。

  3. プロファイル名をダブルクリックして、MATLAB Job Scheduler プロファイルの名前を変更します。
    今回はMJSProfile1

  4. プロファイルを選択し、ツールバーの[編集]をクリックして編集します。

    Image RemovedImage Added

  5. [完了]をクリックします。二枚目の画像は、設定後のMATLAB Job Schedulerクラスタ・プロファイルを示します。

  6. [規定に設定] を選択して、このプロファイルをデフォルトにします。

  7. クラスタープロファイルの検証をクリックします。その後、ユーザー名とパスワードが聞かれます。
    クラスタの検証が成功すると、以下のようになります。

    Image RemovedImage Added

演習

  • 準備:Coding files>Block Process On Large Imageファイルのinput_img.ngをC:\Users\ユーザー名\Documents\MATLABに移す。

  • localとサーバーの切り替えは、クラスタープロファイルマネージャーでの既定の設定を切り替えることで可能。

    Image RemovedImage Added
  • 並列処理ありとなしの切り替えは、コマンドにおける'UseParallel',trueを'UseParallel',falseに書き換える。

...

  1. 並列処理ありの場合

    Code Block
    tic % Start stopwatch timer
    % Input image
    input_img = "input_img.jpg"; % Add image path
    % Initialize Edge detection function
    fun = @(block_struct) edge(block_struct.data,"canny");
    % Covert source image from RGB to GRAY
    input_image= rgb2gray(imread(input_img));
    % Perform Parallel Block Process
    result = blockproc(input_image,[25 25],fun, ...
       'UseParallel',true);
    toc % Terminate stopwatch timer 
    % Show ouput image
    imshow(result)
    Image RemovedImage Added

  2. 並列処理なしの場合

    Code Block
    tic % Start stopwatch timer
    % Input image
    input_img = "input_img.jpg"; % Add image path
    % Initialize Edge detection function
    fun = @(block_struct) edge(block_struct.data,"canny");
    % Covert source image from RGB to GRAY
    input_image= rgb2gray(imread(input_img));
    % Perform Parallel Block Process
    result = blockproc(input_image,[25 25],fun, ...
       'UseParallel',false);
    toc % Terminate stopwatch timer 
    % Show ouput image
    imshow(result

...

  1. 単一の GPU の使用

    Code Block
    N = 1000;
    r = gpuArray.linspace(0,4,N);
    x = rand(1,N,"gpuArray");
    numIterations = 1000;
    for n=1:numIterations
        x = r.*x.*(1-x);
    end
    plot(r,x,'.');

    経過時間を計測

    Code Block
    N = 1000;
    r = gpuArray.linspace(0,4,N);
    x = rand(1,N,"gpuArray");
    numIterations = 1000;
    for n=1:numIterations
        x = r.*x.*(1-x);
    end
    plot(r,x,'.');

  2. parfor による複数の GPU の使用

    Code Block
    numGPUs = gpuDeviceCount("available");
    parpool(numGPUs);
    numSimulations = 100;
    X = zeros(numSimulations,N,"gpuArray");
    parfor i = 1:numSimulations
        X(i,:) = rand(1,N,"gpuArray");
        for n=1:numIterations
            X(i,:) = r.*X(i,:).*(1-X(i,:));
        end
    end
    figure
    plot(r,X,'.');

    サポートされているGPUデバイスがないため、numGPUsは1に変更
    経過時間を計測

    Code Block
    parpool(1);
    numSimulations = 100;
    numIterations = 1000;
    N = 1000;
    r = gpuArray.linspace(0,4,N);
    X = zeros(numSimulations,N,"gpuArray");
    tic;
    parfor i = 1:numSimulations
        X(i,:) = rand(1,N,"gpuArray");
        for n=1:numIterations
            X(i,:) = r.X(i,:).(1-X(i,:));
        end
    end
    toc;
    figure
    plot(r,X,'.');
    

  3. parfeval による複数 GPU の非同期の使用

    Code Block
    f(numSimulations) = parallel.FevalFuture;
    type myParallelFcn
    for i=1:numSimulations
        f(i) = parfeval(@myParallelFcn,1,r);
    end
    figure
    hold on
    afterEach(f,@(x) plot(r,x,'.'),0);

...