Statistics
| Branch: | Revision:

root / synthbench / euroben-dm / mod1h / .svn / text-base / nearn_1d.f.svn-base @ 0:839f52ef7657

History | View | Annotate | Download (2.7 kB)

1
      Subroutine nearn_1d( title, me, npes, nrpt, ncases, n, tn,
2
     &                        ops )
3
! ----------------------------------------------------------------------
4
      Use            numerics
5
      Use            max_params      
6
      Implicit       None
7
      
8
      Include        'mpif.h'
9
      
10
      Character*50 :: title
11
      Integer      :: me, npes, nrpt, ncases, n
12
      Real(l_)     :: tn(maxcases), ops, timer
13
      Real(l_)     :: a(nmax), b(nmax), c(nmax)      
14
      Real(l_)     :: buffer( 8*(nmax + MPI_Bsend_Overhead/8 ))
15
      Real(l_)     :: t1, t2
16
      Integer      :: k, tag
17
      Integer      :: comm, commcart, ie, type
18
      Integer      :: status(MPI_Status_Size)
19
      Integer, Parameter :: dim = 1
20
      Integer      :: dims(dim)
21
      Integer      :: pos(dim)
22
      Logical      :: periods(dim)
23
      Integer      :: moi, myid
24
      Integer      :: west, east
25
      Integer      :: size
26
      Save            a, b, c
27
! ----------------------------------------------------------------------
28
      comm    = MPI_Comm_World
29
      type    = MPI_Real8
30
      title   = ' N PEs  <--  2N PEs; Nearst nbr 1D'
31
      nrpt    = 100
32
      ncases  = npes
33
      ops     = 2*8*n
34
      size    = 8*n 
35
      tn(1:maxcases) = 1.0e-15_l_
36
      
37
      periods = .TRUE.                        ! --- Introduce topology
38
      dims    = 0   
39
      Call MPI_Comm_Rank( comm, myid, ie)
40
      Call MPI_Dims_Create( npes, dim, dims, ie )      
41
      Call MPI_Cart_Create( comm, dim, dims, periods, .TRUE.,
42
     &                      commcart, ie )
43
      
44
! --- Get position and rank in Cartesian grid.
45
      
46
      Call MPI_Cart_Get( commcart, dim, dims, periods, pos, ie )
47
      Call MPI_Cart_Rank( commcart, pos, moi, ie )     
48
      Call MPI_Buffer_Attach(buffer, 8*(size+MPI_Bsend_Overhead), ie )
49
      
50
! --- Get rank of neighbours.
51
        
52
      Call MPI_Cart_Coords( commcart, myid, dim, dims, ie )
53
      Call MPI_Cart_Shift( commcart, 0, -1, myid, west, ie )       
54
      Call MPI_Cart_Shift( commcart, 0, 1,  myid, east, ie )
55
      Call MPI_Barrier( commcart, ie )
56
      t1 = timer()
57
      Do k = 1, nrpt
58
         tag = (k * npes * 2)
59
         Call MPI_Bsend( a, n, type, west, tag + moi,    commcart, ie )
60
         Call MPI_Bsend( a, n, type, east, tag + moi + 1,commcart, ie )
61
         Call MPI_Recv( b, n, type, west, tag + west + 1,
62
     &                  commcart, status, ie )
63
         Call MPI_Recv( c, n, type, east, tag + east,
64
     &                  commcart, status, ie )
65
      End Do
66
      t2       = timer()
67
      tn (myid+1) = Max( 1.0e-15_l_, (t2-t1) / (2*nrpt) )
68
      Call MPI_Buffer_Detach( buffer, size, ie )
69
! ----------------------------------------------------------------------
70
      End Subroutine nearn_1d