当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

中国科学技术大学:《并行计算 Parallel Computing》课程教学资源(习题)第十四章 分布存储系统并行编程

资源类别:文库,文档格式:DOC,文档页数:3,文件大小:56.5KB,团购合买
点击下载完整版文档(DOC)

第十四章分布存储系统并行编程 习题例题: 1、试考虑下述代码段中通信体的使用; MPI Send(msg l, countI, MPI INT, tagl, commD); parallel fft(.) MPI Recv(msgl, countI, MPI INT, tagl, commD); )试分析上述代码段的计算功能 (2)如果在 parallel fft(..)中又包含了另一个发送程序 If(my rank ==0)MPI Send( msg2, countI, MPI INT, 1, tag2, comm2) 如果没有通信体则会发生什么情况? 2、填上空白处,使下面两代码段完全等效: l) float data[1024]」 MPI Datatype floattype MPI Type vector(10, 1, 32, MPI FLOAT, &floattype) MPI Type commit( &floattype) MPI Send(data, 1, floattype, dest, tag, MPI COMM WORLD) (2)float data[ 1024, buff 101 i++buff(]=data MPI Send( buff, MPI FLOAT 3、下面是PVM环境下的 hello程序,它是一个 host/node程序,试分析其工作过程 ∥PⅤM主机/节点编程的 hello代码段∥ /*host程序 hello.c* #include # include“pvm3.h” char buf[1001 printf("I'm t%n, pvm myido) cc= pvm span( hello other”,(char**)0,0,“”,1,&tid) if(c==1) c→ pvm recv(-1,-1) pvm bufinfo(cc, (int*)o,(int*)0, &tid); pvm upkstr(buf) printf( from t%x: %s\n,tid, buf) i else

第十四章 分布存储系统并行编程 习题例题: 1、试考虑下述代码段中通信体的使用; process 0: MPI_Send(msg1,count1,MPI_INT,tag1,comm1); parallel_fft(...); process 1: MPI_Recv(msg1,count1,MPI_INT,tag1,comm1); parallel_fft(...); ⑴试分析上述代码段的计算功能。 ⑵如果在 parallel_fft(...)中又包含了另一个发送程序: If(my_rank = = 0) MPI_Send(msg2,count1,MPI_INT,1,tag2,comm2); 如果没有通信体则会发生什么情况? 2、填上空白处,使下面两代码段完全等效: ⑴float data[1024]; MPI_Datatype floattype; MPI_Type_vector(10,1,32,MPI_FLOAT,&floattype); MPI_Type_commit(&floattype); MPI_Send(data,1,floattype,dest,tag,MPI_COMM_WORLD); MPI_Type_free(&floattype); ⑵float data[1024],buff[10]; for( ______ ; ______ ; i++) buff[i] = data [_____] MPI_Send(buff,______ , MPI_FLOAT,______ ,______ ,______ ); 3、下面是 PVM 环境下的 hello 程序,它是一个 host/node 程序,试分析其工作过程。 //*PVM 主机/节点编程的 hello 代码段*// /*host 程序 hello.c*/ #include #include “pvm3.h” main() { int cc, tid; char buf[100]; printf(“i’m t%x \n”, pvm_myid()); cc=pvm_spwan(“hello_other”, (char **)0, 0, “”, 1, &tid); if (cc = = 1) { cc=pvm_recv(-1, -1); pvm_bufinfo(cc, (int *)0, (int *)0, &tid); pvm_upkstr(buf); printf(”from t%x: %s \n”, tid, buf); } else

printf("cant start hello other \n); vm exito node程序 hello other. c* #include"pvm. h # include“ string. h ptid char buf[100] ptid=pvm parentO; strcpy (buf, "hello, world from) gethostname( buf+strlen(buf), 64) pvm initsend( PvmDataDefault) pvm pkstr(buf) pvm send(ptid, 1) pvm exito 4、计算兀可以通过MP程序。为了加深读者对MP的学习和理解,下面给出用 FORTRAN 90语言的实现版本。试分析其工作过程。 计算丌的MPI(F90)编程代码段*∥ program main ulse mpl double precision P125DT parameter(PI25DI=3.141592653589793238462643d0 double precision mypi, pi, h, sum, x, f, a integer n, myid, numprocs, i, rc function to integrate f(a)=4d0/(1.d0+aa) all MPI INIT(ierr) all MPI COMM RANK(MPI COMM WORLD id. ierr) call MPI COMM SIZE(MPI COMM WORLD, numprocs, ierr) print*, process, myid, of', numprocs, "is alive if(myid. eq O)then wite(6,98) format("Enter the number of intervals: (0 quit)) read(, 99)n

printf(“can’t start hello_other \n”); pvm_exit(); } /*node 程序 hello_other.c*/ #include “pvm3.h” #include “string.h” main() { int ptid; char buf[100]; ptid=pvm_parent(); strcpy(buf, “hello, world from”); gethostname(buf+strlen(buf), 64); pvm_initsend(PvmDataDefault); pvm_pkstr(buf); pvm_send(ptid, 1); pvm_exit(); exit(0); } 4、计算 π 可以通过 MPI 程序。为了加深读者对 MPI 的学习和理解,下面给出用 FORTRAN 90 语言的实现版本。试分析其工作过程。 //*计算 π 的 MPI(F90)编程代码段*// program main use mpi double precision PI25DT parameter (PI25DT=3.141592653589793238462643d0) double precision mypi, pi, h, sum, x, f, a integer n, myid, numprocs, i, rc ! function to integrate f(a) = 4.d0/(1.d0+a*a) call MPI_INIT(ierr) call MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierr) call MPI_COMM_SIZE(MPI_COMM_WORLD, numprocs, ierr) print *, ‘process’, myid, ‘of’, numprocs, ‘is alive’ sizetype=1 sumtype=2 do if (myid.eq.0) then write(6, 98) 98 format(‘Enter the number of intervals: (0 quit)’) read(5, 99)n

99 format(i10) call MPI BCAST(n, 1, MPI INTEGER, 0, MPI COMM WORLD, ierr) if(nle 0)exit i calculate the interval size h=1.0d0/n sum=0. Odo do i=myid+l,n x=h°(dble(i)-0.5d0) mpi=h*"sum I collect all the partial sums call MPI REdUCE(mypi, pi, I, MPI DOUBLE PRECISION, MPI SUM, 0, MPI COMM WORLD, ierr) I process 0 prints the answer if (myid. eq. O)ther write(6, 97)pi, abs(pi-Pl25DT) 97 format(pi is approximately: F18 16, &"Error is:' F18.16) endif call MPI FINALIZE(rc) 5、 Fortran90计算π的程序如下:参照它试写出计算的HPF程序:并将两者加以比较。 ∥计算π Fortran90编程代码段*∥ 1. INTEGER, PARAMETER: N=131072 2. INTEGER, PARAMETER: LONG=SELECTED REAL KIND(13, 99) 3. REAL(KIND=LONG)PI, WIDTH 4. INTEGER, DIMENSION(N): ID 5. REAL(KIND=LONG), DIMENSIONN): X,Y 6. WIDTH=L0 LONG/N 7.ID=(/(,l=1,N 8. X(ID-0.5)*WIDTH 9.Y=4.0(1.0+X*X) 10. PI=SUM(Y)"WIDTE 11. FORMAT(“ ESTIMATION OF PI WITH”,16,& 12.“ INTERVALS IS”,F14,12) 13. PRINT 10.N.PI 14 END

99 format(i10) endif call MPI_BCAST(n, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr) ! check for quit signal if (n.le.0) exit ! calculate the interval size h=1.0d0/n sum=0.0d0 do i=myid+1, n, numprocs x=h*(dble(i)-0.5d0) sum=sum+f(x) enddo mypi=h*sum ! collect all the partial sums call MPI_REDUCE(mypi, pi, 1, MPI_DOUBLE_PRECISION, MPI_SUM, 0, & MPI_COMM_WORLD, ierr) ! process 0 prints the answer if (myid.eq.0) then write (6, 97) pi, abs(pi-PI25DT) 97 format (‘pi is approximatetly :’, F18.16, & ‘Error is: ’, F18.16) endif enddo call MPI_FINALIZE(rc) stop end 5、Fortran 90 计算 π 的程序如下:参照它试写出计算 π 的 HPF 程序;并将两者加以比较。 //*计算 π Fortran 90 编程代码段*// 1. INTEGER, PARAM\ETER::N=131072 2. INTEGER, PARAMETER::LONG=SELECTED_REAL_KIND(13,99) 3. REAL(KIND=LONG)PI, WIDTH 4. INTEGER, DIMENSION(N)::ID 5. REAL(KIND=LONG), DIMENSION(N)::X,Y 6. WIDTH=1.0_LONG/N 7. ID=(/(I,I=1,N)/) 8. X=(ID-0.5)*WIDTH 9. Y=4.0/(1.0+X*X) 10. PI=SUM(Y)*WIDTH 11. FORMAT(“ESTIMATION OF PI WITH”, 16, & 12. “INTERVALS IS”, F14, 12) 13. PRINT 10,N,PI 14. END

点击下载完整版文档(DOC)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
已到末页,全文结束
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有