- 1、本文档共45页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
synchronous iteration同步迭代
To be continued… 另一个全同步迭代程序例子 用雅可比(Jacobi)迭代法解线性方程组 Solving a General System of Linear Equations by Iteration Suppose the equations are of a general form with n equations and n unknowns where the unknowns are x0, x1, x2, … xn-1 (0 = i n). 把第i个方程 This equation gives xi in terms of the other unknowns. 可以作为迭代公式计算每个未知数的逼近值。 改写成 即 Jacobi Iteration雅可比迭代法 All values of x are updated together.所有的x值同时更新 可以证明如果方程组对角线上a的绝对值大于同行中其他a的绝对值之和 (a方阵是对角占优的), 则雅可比法收敛 i.e. This condition is a sufficient but not a necessary condition. A simple, common approach. Compare values computed in one iteration to values obtained from the previous iteration. Terminate computation when all values are within given tolerance; i.e., when However, this does not guarantee the solution to that accuracy. Termination终止 前后两次结果的差异 Convergence Rate Parallel Code 每个未知数分配一个进程,每个进程迭代步数一样,进程 Pi 可写成下面的代码 x[i] = b[i]; /*initialize unknown*/ for (iteration = 0; iteration limit; iteration++) { sum = -a[i][i] * x[i]; for (j = 0; j n; j++) /* compute summation */ sum = sum + a[i][j] * x[j]; new_x[i] = (b[i] - sum) / a[i][i]; /* compute unknown */ allgather(new_x[i]); /*bcast/recv values */ global_barrier(); /* wait for all processes */ } allgather() sends the newly computed value of x[i] from process i to every other process and collects data broadcast from the other processes. Introduce a new message-passing operation - Allgather. Allgather Broadcast and gather values in one composite construction. MPI_Allgather(); MPI_Allreduce(); n = pSize; //每个进程对应一个未知数 if(!pID) input(); //根进程负责输入 MPI_Bcast(a, MAX_A, MPI_FLOAT, 0, MPI_COMM_WORLD); //广播系数 MPI_Bcast(b, MAX_N, MPI_FLOAT, 0, MPI_COMM_WORLD); //广播b for(i = 0; i n; i++) { x[i] = b[i]; new_x[i] = b[i]; } //初始化x的值 i = pID; //当前进程处理的元素为该进程的ID do{//迭代求x[i]的值 iteration++; //迭代次数加1 //将上一轮迭代的结果作为本轮迭代的起始值,并设置新的迭代结果为0 for(j
文档评论(0)