Can matlab automatically make my code parallel

조회 수: 2 (최근 30일)
Xinyi Shen
Xinyi Shen 2015년 2월 15일
답변: John D'Errico 2015년 2월 15일
My department in UCONN has purchased a MDCS license that will be delivered soon to run our hydrologic model parallel. Before it is delivered, I have a question regarding the parallelism of matlab. Our model runs in a time series form. In time domain, each iteration depends on its previous one. Therefore, the for loop with regard to time cannot be parallelized. However, since it is also spatially distributed, we are looking for parallelize it spatially between grid-cells.
With in each iteration, the code has been already fully vectorized, which means we do not loop over grid-cells. All computational steps include only basic arithmetic, logical operation and the accumarray functions on all cells as input and output.
I heard rumors that matlab could automatically make your code parallel (i.e., utilize all cores a single computer and utilize all processors/cores of a cluster) if only the code is fully vectorized . For a single multi-core computer, you need to do nothing while for a cluster, you only need to set your variables as distributed array.
I doubt the authenticity of this rumor because when I run the code without parfor or spmd, matlab does not use all my cores and the CPU occupation is 1/n of 100% where n is the number of cores.
Please let me know if this rumor is true. Thanks.

답변 (1개)

John D'Errico
John D'Errico 2015년 2월 15일
Even without tools like parfor, many tools in MATLAB will automatically start using multiple processors, but only when the problem is big enough to warrant it. Because of overhead, using two processors is not fully twice as fast as the use of one. In fact, it may be slower.
I do often see MATLAB using multiple cores on some problems. But it needs to be something sufficiently big.
This for example, is sufficient to utilize 5 of 8 cores on my CPU:
n = 9000;A = randn(n)*randn(n);
With some effort, at times I've seen almost all 8 cores running nearly flat out.

카테고리

Help CenterFile Exchange에서 Parallel Computing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by