正在加载图片...
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: F1816, &"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)*WIDTH 11. FORMAT(“ ESTIMATION OF PI WITH”,16,& 12.“ INTERVALS IS”,F14,12) 13. PRINT 10.N.PI 14 END99 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
<<向上翻页
©2008-现在 cucdc.com 高等教育资讯网 版权所有