📄 nearn_2d.f
字号:
Subroutine nearn_2d( title, me, npes, nrpt, ncases, n, tn, & ops )! ---------------------------------------------------------------------- Use numerics Use max_params Implicit None Include 'mpif.h' Character*50 :: title Integer :: me, npes, nrpt, ncases, n Real(l_) :: tn(maxcases), ops, timer Real(l_) :: a(nmax), b(nmax), c(nmax), d(nmax), e(nmax) Real(l_) :: buffer(8*(nmax+MPI_Bsend_Overhead/8)) Real(l_) :: t1, t2 Integer :: k, tag Integer :: comm, commcart, ie, type Integer :: status(MPI_Status_Size) Integer, Parameter :: dim = 2 Integer :: dims(dim), npos(dim) Integer :: pos(dim) Logical :: periods(dim) Integer :: moi, myid Integer :: north, south, west, east Integer :: size Save a, b, c, d, e! ---------------------------------------------------------------------- comm = MPI_Comm_World type = MPI_Real8 title = ' N PEs <-- 4N PEs; Nearst nbr 2D' nrpt = 100 ncases = npes ops = 4*8*n size = 8*n tn(1:ncases) = 0.0_l_ periods = .TRUE. ! --- Introduce topology dims = 0 Call MPI_Comm_Rank( comm, myid, ie) Call MPI_Dims_Create( npes, dim, dims, ie ) Call MPI_Cart_Create( comm, dim, dims, periods, .TRUE., commcart, & ie ) ! --- Get position and rank in Cartesian grid. Call MPI_Cart_Get( commcart, dim, dims, periods, pos, ie ) Call MPI_Cart_Rank( commcart, pos, moi, ie ) Call MPI_Buffer_Attach(buffer, 8*(size+MPI_Bsend_Overhead), ie ) ! --- Get rank of neighbours. Call MPI_Cart_Coords( commcart, myid, dim, dims, ie ) Call MPI_Cart_Shift( commcart, 0, -1, myid, west, ie ) Call MPI_Cart_Shift( commcart, 0, 1, myid, east, ie ) Call MPI_Cart_Shift( commcart, 1, 1, myid, north, ie ) Call MPI_Cart_Shift( commcart, 1, -1, myid, south, ie ) t1 = timer() Do k = 1, nrpt tag = (nrpt * npes * 4) Call MPI_Bsend( a, n, type, west, tag + moi, commcart, ie ) Call MPI_Bsend( a, n, type, east, tag + moi+1, commcart, ie ) Call MPI_Bsend( a, n, type, north, tag + moi+2, commcart, ie ) Call MPI_Bsend( a, n, type, south, tag + moi+3, commcart, ie ) Call MPI_Recv( b, n, type, west, tag + west + 1, & commcart, status, ie ) Call MPI_Recv( c, n, type, east, tag + east, & commcart, status, ie ) Call MPI_Recv( d, n, type, north, tag + north + 3, & commcart, status, ie ) Call MPI_Recv( e, n, type, south, tag + south + 2, & commcart, status, ie ) End Do t2 = timer() tn (myid+1) = (t2-t1) / (2*nrpt ) Call MPI_Buffer_Detach( buffer, size, ie )! ---------------------------------------------------------------------- End Subroutine nearn_2d
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -