Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill trailing whitespaces in teshsuite/smpi/{isp,mpich3-test}.
[simgrid.git] / teshsuite / smpi / mpich3-test / f77 / rma / winscale1f.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, group, group2, ans
16       integer nneighbors, nbrs(2), 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 C Create the group for the neighbors
31          call mpi_comm_size( comm, size, ierr )
32          call mpi_comm_rank( comm, rank, ierr )
33          nneighbors = 0
34          left = rank - 1
35          if (left .lt. 0) then
36             left = MPI_PROC_NULL
37          else
38             nneighbors = nneighbors + 1
39             nbrs(nneighbors) = left
40          endif
41          right = rank + 1
42          if (right .ge. size) then
43             right = MPI_PROC_NULL
44          else
45             nneighbors = nneighbors + 1
46             nbrs(nneighbors) = right
47          endif
48          call mpi_comm_group( comm, group, ierr )
49          call mpi_group_incl( group, nneighbors, nbrs, group2, ierr )
50          call mpi_group_free( group, ierr )
51 C
52 C Initialize the buffer
53          do i=1,nrows
54             buf(i,0)       = -1
55             buf(i,ncols+1) = -1
56          enddo
57          do j=1,ncols
58             do i=1,nrows
59                buf(i,j) = rank * (ncols * nrows) + i + (j-1) * nrows
60             enddo
61          enddo
62          call mpi_win_post( group2, 0, win, ierr )
63          call mpi_win_start( group2, 0, win, ierr )
64 C
65          asize = ncols+1
66          call mpi_put( buf(1,1), nrows, MPI_INTEGER, left, asize,
67      &                 nrows, MPI_INTEGER, win, ierr )
68          asize = 0
69          call mpi_put( buf(1,ncols), nrows, MPI_INTEGER, right, asize,
70      &                 nrows, MPI_INTEGER, win, ierr )
71 C
72          call mpi_win_complete( win, ierr )
73          call mpi_win_wait( win, ierr )
74 C
75 C Check the results
76          if (left .ne. MPI_PROC_NULL) then
77             do i=1, nrows
78                ans = rank *  (ncols * nrows) - nrows + i
79                if (buf(i,0) .ne. ans) then
80                   errs = errs + 1
81                   if (errs .le. 10) then
82                      print *, ' buf(',i,'0) = ', buf(i,0)
83                   endif
84                endif
85             enddo
86          endif
87          if (right .ne. MPI_PROC_NULL) then
88             do i=1, nrows
89                ans = (rank+1) * (ncols * nrows) +  i
90                if (buf(i,ncols+1) .ne. ans) then
91                   errs = errs + 1
92                   if (errs .le. 10) then
93                      print *, ' buf(',i,',',ncols+1,') = ',
94      &                          buf(i,ncols+1)
95                   endif
96                endif
97             enddo
98          endif
99          call mpi_group_free( group2, ierr )
100          call mpi_win_free( win, ierr )
101          call mtestFreeComm( comm )
102       enddo
103
104       call mtest_finalize( errs )
105       call mpi_finalize( ierr )
106       end