october 9, 2007 - pkudsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øa„...
TRANSCRIPT
![Page 1: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/1.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
热传导方程和对流方程
卢朓
Department of Science and Engineering Computing
School of Mathematics School
Peking University
October 9, 2007
![Page 2: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/2.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
热传导方程和对流方程
卢朓
Department of Science and Engineering Computing
School of Mathematics School
Peking University
October 9, 2007
![Page 3: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/3.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
框架
1 Parabolic equation
2 对流方程
3 MPI的时间函数
4 MPI 的聚合通信函数
5 Homework
6 Reference
![Page 4: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/4.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
Parabolic equation
One dimensional Parabolic Equatino: 一个例子
@u
@t= �
@2u
@x2x 2 [0; 1]; t 2 (0;+1);
u(0; t) = u(1; t) = 0
u(x; 0) = u0(x) = sin�x
精确解
u(x; t) = e��2t sin�x
![Page 5: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/5.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
三种格式
Euler Forward, O(�t;�x2)
un+1i � uni�t
= �uni+1 � 2uni + uni�1
�x2
Euler backward, O(�t;�x2)
un+1i � uni�t
= �un+1i+1 � 2un+1i + un+1i�1
�x2
Crank-Nicolson, O(�t2;�x2)
un+1i � uni�t
=�
2
uni+1 � 2uni + uni�1�x2
+
�
2
un+1i+1 � 2un+1i + un+1i�1
�x2
![Page 6: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/6.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
差分格式的稳定性
定义D = ��t�x2
Euler Forward , 要求D � 12
Euler Backward, Unconditionally stable
Crank-Nicolson, Unconditionally stable
![Page 7: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/7.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
两种不consisitent的格式
Dufort-Frankel scheme, Unconditionally stable
un+1i � un�1i
2�t= �
uni+1 ��un+1i + un�1i
�+ uni�1
�x2
Leap-frog scheme, Unconditionally stable
un+1i � un�1i
2�t= �
uni+1 � 2uni + uni�1�x2
![Page 8: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/8.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
框架
1 Parabolic equation
2 对流方程
3 MPI的时间函数
4 MPI 的聚合通信函数
5 Homework
6 Reference
![Page 9: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/9.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
对流方程
一维对流方程
@u
@t+@u
@x= 0; x 2 [0; 1]; t > 0
加上适当的初边值条件
周期初值函数+周期边界条件=简单情况
![Page 10: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/10.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
Euler-Forward/Center-Di�erence Scheme
EF/CD
un+1i � uni�t
+uni+1 � uni�1
2�x= 0
绝对不稳定
![Page 11: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/11.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
Euler-Forward/Upwind-Di�erence Scheme
EF/CD
un+1i � uni�t
=uni � uni�1
�x
条件稳定:�t
�x� 1
精度: O(�t;�x)
![Page 12: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/12.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
Lax-Friedrichs Scheme
Lax-Friedrichs
un+1j � 12
�unj+1 + unj�1
��t
=unj+1 � unj�1
2�x
Tadmor's correction, 引入C = �t�x
un+1j =
1
2
�unj+1 + u
nj�1
��
C
2
�unj+1 � u
nj�1
�+1� C2
4
�u0
j�1 � u0
j+1
�
whereu0j = MinMod
�unj+1 � unj ; u
nj � unj�1
�
MinMod[x; y] �1
2[sgn(x) + sgn(y)]Min[jxj; jyj]
![Page 13: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/13.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
Second-Order Upwind Scheme
EF/UD2
un+1j+1 = unj � C�unj � unj�1
�+
1
2C(C � 1)
�unj � 2unj�1 + unj�2
�
再次提示C � �t�x
另外,上面公式的推导要用到
ut + ux = 0) utt =@ut
@t=
@ux
@t
=@ut
@x=
ux
@x= uxx
For stability, we require that C � 2.
![Page 14: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/14.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
Lax-Wendro� Scheme (2nd order)
EF/LW
un+1j+1 = unj �C
2
�unj+1 � unj�1
�+
C2
2
�unj+1 � 2unj + unj�1
�
For stability we require that C � 1.
![Page 15: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/15.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
Adams-Bashforth/Center Di�erencingScheme(AB/CD)
2nd AB/CD
un+1j � unj
�t+
3
2�xu
nj �
1
2un�1j = 0
3rd AB/CD
un+1j � unj
�t+
23
12�xu
nj �
16
12un�1j +
5
12�xu
n�2j = 0
定义: �xunj =
unj+1�unj�12�x
![Page 16: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/16.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
Burgers equation
Burgers equation: 非线性对流方程
@u
@t+ u
@u
@x= 0
假设周期边界条件,初值
u(x; 0) =
8<:�1; x � �1
31; �1
3 < x � 13
�1; x > 13
![Page 17: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/17.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
the entropy solution
上面问题的熵解
u(x; 0) =
8>>><>>>:
�1; x+ t � �13
2 x�(�t�1=3)(t�1=3)�(�t�1=3) � 1; �t� 1
3 < x � t� 13
1; t� 13 < t < 1
3�1; x > 1
3
可以看解的动画演示burgers.gif .
![Page 18: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/18.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
框架
1 Parabolic equation
2 对流方程
3 MPI的时间函数
4 MPI 的聚合通信函数
5 Homework
6 Reference
![Page 19: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/19.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
MPI的时间函数
double MPI_Wtime(void)
返回当前墙钟时间,单位是秒。
double MPI_Wtick(void)
该函数给出MPI_Wtime 函数的时钟精度,以秒为单位。
和time.h 中的计时函数time_t clock(void) 的差别不大, 可参看我的博客。
![Page 20: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/20.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
框架
1 Parabolic equation
2 对流方程
3 MPI的时间函数
4 MPI 的聚合通信函数
5 Homework
6 Reference
![Page 21: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/21.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
MPI 的聚合通信函数 I
int MPI_Bcast(void *buffer, int count,
MPI_Datatype datatype,
int root, MPI_Comm comm)
广播。通信器comm 中进程号为root 的进程(称为根进程)将自己bu�er 中的内容发送给通信器中所有的其他进程。
int MPI_Gather(void *sendbuf, int sendcnt,
MPI_Datatype sendtype, void * recvbuf,
int recvcnt, MPI_Datatype recvtype,
int root, MPI_Comm comm)
收集相同长度的数据块。以root为根进程,所有进程(包括根进程自己)将sendbuf中的数据块发送给根进程,根进程将这些数据块按进程号的顺序依次放到recvbuf 中。参数recvbuf,recvcnt 和recvtype 仅对根进程有意义。
![Page 22: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/22.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
MPI 的聚合通信函数 II
int MPI_Allgather(void *sendbuf, int sendcnt,
MPI_Datatype sendtype, void * recvbuf,
int recvcnt, MPI_Datatype recvtype,
int root, MPI_Comm comm)
收集相同长度的数据块。相当于一个进程做了MPI_Gather后,把recvbuf 中的数据散发其他所有进程。
int MPI_Gatherv(void *sendbuf, int sendcnt,
MPI_Datatype sendtype, void * recvbuf,
int *recvcnts, int *displs,
MPI_Datatype recvtype,
int root, MPI_Comm comm)
![Page 23: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/23.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
MPI 的聚合通信函数 III
收集不同长度的数据块。与MPI_Gather 类似,但允许每个进程发送的数据块长度不同,并且根进程可以任意排放数据块在recvbuf 中位置。数据recvcnts 和displs 的元素个数等于进程数,用于置顶从每个进程接收的数据块长度和它们在recvbuf 中的位移, 都以recvtype 为单位。
int MPI_Allgatherv(void *sendbuf, int sendcnt,
MPI_Datatype sendtype, void * recvbuf,
int *recvcnts, int *displs,
MPI_Datatype recvtype,
MPI_Comm comm)
不同长度的数据块全收集。相当于先在某个进程上进行MPI_Gatherv, 然后再广播。
![Page 24: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/24.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
框架
1 Parabolic equation
2 对流方程
3 MPI的时间函数
4 MPI 的聚合通信函数
5 Homework
6 Reference
![Page 25: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/25.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
Homework I
1 求解二维Poisson方程
��
@2
@x2�
@2
@y2
�u(x; y) = f(x; y); (x; y) 2 = (0; 1)�(0; 1)
u(x; y) = 0; (x; y) 2 @
自己取定函数f(x; y),使得函数有精确解。使用均匀网格,使用二阶中心差分。N = Nx = Ny 表示在x 和y方向的差分点的个数,看你的机器上的N可以取道多大。比较计算时间和误差。编写并行程序,比较时间和结果的差别,数值验证收敛的阶。练习使用AztecOO的不同解法,比较不同解法的快慢。
![Page 26: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/26.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
Homework II
2 讲义10中有这样一种情况。n个进程,进程Pi 需要向进程Pi+1 发送数据。第一个进程仅仅给第二个进程发送数据,最后一个进程仅仅接收数据,这种情况可以用MPI_Sendrecv 函数来实现吗?如果能请给出一个例子。当然可以增加一个最后一个进程向第一个进程发送消息,这样每个进程都需要Send 和Recv 。这里想知道的是第一个进程仅仅用Send, 最后一个进程仅仅Recv, 中间的进程用Sendrecv, 这样的程序会出错吗?
3 研究讲义10中给出的并行Thomas算法的代码,写出简洁高效率的代码。要求求解Ly = q和Ux = y的过程并行处理。
4 使用讲义10中给出的四阶隐式格式离散一维Poisson方程,验证数值收敛的阶数。
![Page 27: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/27.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
框架
1 Parabolic equation
2 对流方程
3 MPI的时间函数
4 MPI 的聚合通信函数
5 Homework
6 Reference
![Page 28: October 9, 2007 - PKUdsec.pku.edu.cn/~tlu/para/lecture11-beamer-version.pdf · í ü„ „ øA„ b rabPaolic equation øA„ MPI —öôý p MPI —Z ˆ Æýp Homewrko Reference](https://reader034.vdocuments.pub/reader034/viewer/2022042201/5ea1cb99905e2523e30c556a/html5/thumbnails/28.jpg)
热传导方程和对流方程
卢朓
Parabolic
equation
对流方程
MPI的时间函数
MPI 的聚合通信函数
Homework
Reference
Reference
Parallel Scienti�c Computing in C++ and MPI, Chapter 7.
网上列出的例子