Matlab Multi-core Parallel Computing
来源:互联网 发布:人工智能硬件有哪些 编辑:程序博客网 时间:2024/05/16 17:33
Matlab parallel computing principle
Matlab parallel computing is master-slave(subordinate) distributed computing. When you initialize the parallel computing platform, your initial Matlab process automatically becomes the master node, and the slave nodes, which will execute the parfor segment, are initialized at the same time.
At the beginning of parfor
, the master node will transmit the variables outside the parfor loop to the slave nodes. The slave nodes then do the computing in parfor
while not interfering with each other.
When the computation in parfor loop is done, the results from each slave nodes will be put in the same array, and returned to the master node.
After all the parallel computing is done, the platform should be closed manually.
Initialize Matlab parallel computing platform
Matlab parallel computing is only suitable for multi-core computer to speed up.
matlabpool open
Edit your parallel computing code
To illustrate, the following shows some example to transfer ‘for loop’ to ‘parfor loop’.
eg.1 (correct)
for loop:
for i=1:nI{i}=edge(photo{i},'canny');end
parfor loop:
parfor i=1:nI{i}=edge(photo{i},'canny');end
eg.2
for loop (correct):
for i=1:nI{i}=edge(photo{i},'canny');figure,imshow(I{i});end
parfor loop (wrong):
parfor i=1:nI{i}=edge(photo{i},'canny');figure,imshow(I{i});end
In the second example, the for loop is correct while the parfor loop is wrong. It is because the parfor loop is not suitable for all functions in matlab.
eg.3
for loop (correct):
for i=1:nfor j=1:mI{i,j}=edge(photo{i,j},'canny');endend
parfor loop (wrong):
parfor i=1:nparfor j=1:mI{i,j}=edge(photo{i,j},'canny');endend
The for loop is correct while the parfor loop is wrong. It is because parfor or spmd cannot be used inside another parfor loop.
eg.4
for loop (correct):
for i=1:nI{i}=edge(photo{i,1},'canny');end
parfor loop (wrong):
parfor i=1:nI{i}=edge(photo{i,1},'canny');end
References:
[1]http://cn.mathworks.com/help/bioinfo/examples/batch-processing-of-spectra-using-sequential-and-parallel-computing.html?prodcode=DM&language=zh
- Matlab Multi-core Parallel Computing
- Parallel Computing with MATLAB
- Matlab parallel Computing
- matlab并行运算(parallel computing)
- Parallel Architecture\Multi-Core Cache Coherence
- Multi-Core and Parallel Programming Practices笔记1
- Multi-Core and Parallel Programming Practices笔记2
- Parallel Processing and Multi-Core Utilization with Java
- Introduction to Parallel Computing
- Collision Detection - Parallel Computing
- [c++]parallel computing
- Vectorization (parallel computing) from Wikipedia
- Vectorization (parallel computing) from Wikipedia
- Parallel Computing Toolbox(PCT)
- Elements of Parallel Computing.pdf
- CUDA编程手记1-parallel computing overall
- A View of the Parallel Computing Landscape
- 并行计算(Parallel Computing)初步认识
- SimpleAdapter创建ListView
- Java eclipse下 Ant build.xml实例详解 附完整项目源码
- PAT_A 1108. Finding Average (20)
- HDU 5640:King's Cake【几何】
- C++string类型转换为C数组
- Matlab Multi-core Parallel Computing
- javascript中,函数的声明与表达式
- 用Source Insight追踪Arduino的setup和loop
- Delphi 10 Seattle 编译DevExpress VCl 14.x版本源码的问题
- Unity3D 5 官方教程:标准着色器
- C—整数与浮点数笔记
- ubuntu15.10下安装opencv2.4.9&python上调用opencv库
- 基因数据处理7之BWA_MEM运行太长
- CodeForces 628BNew Skateboard-数学水题