Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add f77 RMA tests
[simgrid.git] / teshsuite / smpi / mpich3-test / f77 / rma / winfencef.f
1 C -*- Mode: Fortran; -*- 
2 C
3 C  (C) 2003 by Argonne National Laboratory.
4 C      See COPYRIGHT in top-level directory.
5 C
6       program main
7       implicit none
8       include 'mpif.h'
9       integer ierr, errs
10       integer win, intsize
11       integer left, right, rank, size
12       integer nrows, ncols
13       parameter (nrows=25,ncols=10)
14       integer buf(1:nrows,0:ncols+1)
15       integer comm, ans
16       integer i, j
17       logical mtestGetIntraComm
18 C Include addsize defines asize as an address-sized integer
19       include 'addsize.h'
20       
21       errs = 0
22       call mtest_init( ierr )
23
24       call mpi_type_size( MPI_INTEGER, intsize, ierr )
25       do while( mtestGetIntraComm( comm, 2, .false. ) ) 
26          asize = nrows * (ncols + 2) * intsize
27          call mpi_win_create( buf, asize, intsize * nrows, 
28      &                        MPI_INFO_NULL, comm, win, ierr )
29          
30          call mpi_comm_size( comm, size, ierr )
31          call mpi_comm_rank( comm, rank, ierr )
32          left = rank - 1
33          if (left .lt. 0) then
34             left = MPI_PROC_NULL
35          endif
36          right = rank + 1
37          if (right .ge. size) then
38             right = MPI_PROC_NULL
39          endif
40 C
41 C Initialize the buffer 
42          do i=1,nrows
43             buf(i,0)       = -1
44             buf(i,ncols+1) = -1
45          enddo
46          do j=1,ncols
47             do i=1,nrows
48                buf(i,j) = rank * (ncols * nrows) + i + (j-1) * nrows
49             enddo
50          enddo
51          call mpi_win_fence( MPI_MODE_NOPRECEDE, win, ierr )
52 C         
53          asize = ncols+1
54          call mpi_put( buf(1,1), nrows, MPI_INTEGER, left, asize, 
55      &                 nrows, MPI_INTEGER, win, ierr )
56          asize = 0
57          call mpi_put( buf(1,ncols), nrows, MPI_INTEGER, right, asize, 
58      &                 nrows, MPI_INTEGER, win, ierr )
59 C         
60          call mpi_win_fence( MPI_MODE_NOSTORE + MPI_MODE_NOPUT + 
61      &                       MPI_MODE_NOSUCCEED, win, ierr )
62 C
63 C Check the results
64          if (left .ne. MPI_PROC_NULL) then
65             do i=1, nrows
66                ans = rank * (ncols * nrows) - nrows + i
67                if (buf(i,0) .ne. ans) then
68                   errs = errs + 1
69                   if (errs .le. 10) then
70                      print *, rank, ' buf(',i,',0) = ', buf(i,0),
71      &                    ' expected', ans
72                   endif
73                endif
74             enddo
75          endif
76          if (right .ne. MPI_PROC_NULL) then
77             do i=1, nrows
78                ans = (rank + 1)* (ncols * nrows) + i
79                if (buf(i,ncols+1) .ne. ans) then
80                   errs = errs + 1
81                   if (errs .le. 10) then
82                      print *, rank, ' buf(',i,',',ncols+1,') = ', 
83      &                         buf(i,ncols+1), ' expected ', ans
84                   endif
85                endif
86             enddo
87          endif
88          call mpi_win_free( win, ierr )
89          call mtestFreeComm( comm )
90       enddo
91
92       call mtest_finalize( errs )
93       call mpi_finalize( ierr )
94       end