并行计算在矩阵中的应用
2017-09-18王涛赵映诚刘鑫源
王涛 赵映诚 刘鑫源
摘 要: 在解决许多实际问题时,经常需要计算一些高阶矩阵。然而传统的串行计算方法往往效率比较低。因此,需将串行程序并行化来提高计算效率。文章分别研究了Windows API、OpenMP、MPI、PPL这四种并行计算方法在矩阵乘法并行化中的应用。通过测试不同规模的矩阵,根据加速比衡量并行化的加速效果,对这四种并行化方法的加速效果进行了对比。结果表明,这四种方法都可以提高计算效率,其中MPI的加速效果最好。
关键词: 计算效率; 串行计算; 并行化; 加速比
中图分类号:TP338.6 文献标志码:A 文章编号:1006-8228(2017)09-33-04
Abstract: In solving many practical problems, some high-order matrices often need to be calculated. However, the traditional serial computing methods are often inefficient. Therefore, serial programs need to be parallelized to improve computational efficiency. In this paper, four parallel computing methods, Windows, API, OpenMP, MPI and PPL, are studied on their application in matrix multiplication. By testing the matrices of different size, and measuring the acceleration effect of parallelization according to the acceleration ratio, the acceleration effect is compared. The results show that all the four methods can improve the computational efficiency, and the acceleration effect of MPI is the best.
Key words: computational efficiency; serial computing; parallelization; acceleration ratio
0 引言
在实际应用中,很多问题往往归结于矩阵运算方面的应用[1]。为了解决传统的串行计算方法在运算高阶矩阵时效率低下的问题,考虑将串行程序并行化[2]。并行计算是指将顺序执行的计算任务分成同时执行的子任务,并行地执行这些子任务,从而完成整个计算任务。由于在矩阵乘法运算过程中元素之间没有数据依赖性和数据竞争的问题,可以充分使用计算机资源,因此很适合并行化。本文分别对Windows API、MPI[3]、OpenMP[4]和PPL这四种多核并行计算方法在矩阵乘法的并行化做了详细的研究。
1 矩阵并行化模型的建立
1.1 矩阵乘法的并行化
以为例,由矩阵乘法運算规则,可以将A矩阵按行、B矩阵按列分为若干块,每个矩阵子块作相应的乘法运算,最后再将运算得到的矩阵块组合就能得到矩阵相乘的结果C。现在假设一个并行系统,含有n个处理机,每个处理机计算一个矩阵子块的乘积。……
