Why is this simple parallel program much slower than the non-parallel version?

조회 수: 2 (최근 30일)
I have a very simple script that calls the built-in genetic algorithm function:
function test1(gen)
options = gaoptimset('UseParallel', 'always', 'Vectorized', 'off');
tic;
x = ga(@dejong5fcn, 2, [], [], [], [], [], [], [], options);
toc
end
First, I ran test1 without starting matlabpool. As expected, it runs fine but uses only one CPU core as observed with Windows Resource Monitor. It takes 4.2 seconds to run 20020 fitness evaluations. Then, I started the parallel engine with: "start matlabpool local 4" and then performed an otherwise identical run of test1. It runs and uses all four CPU cores, but takes about 90.7 seconds to perform 20020 fitness evaluations.
What am I not understanding about parallelism in Matlab R2012a (on Windows 7 64 bit)? Thanks for any help.

채택된 답변

Walter Roberson
Walter Roberson 2014년 2월 4일
  댓글 수: 4
Walter Roberson
Walter Roberson 2014년 2월 6일
Pr-allocation. When you use parfor(), MATLAB automatically pre-allocates for the outputs. If you have not pre-allocated in your code, the serial version could spend most of its time finding new memory and copying the results into it.
Andy Yancy
Andy Yancy 2014년 2월 6일
Great, thanks Walter. I appreciate you taking the time to answer my questions.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by