Debian Codegraph @

test/mpi/f77/rma/winscale2f.f

raw
1 C
2 C Copyright (C) by Argonne National Laboratory
3 C See COPYRIGHT in top-level directory
4 C
5
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 logical flag
19 C Include addsize defines asize as an address-sized integer
20 include 'addsize.h'
21
22 errs = 0
23 call mtest_init( ierr )
24
25 call mpi_type_size( MPI_INTEGER, intsize, ierr )
26 do while( mtestGetIntraComm( comm, 2, .false. ) )
27 asize = nrows * (ncols + 2) * intsize
28 call mpi_win_create( buf, asize, intsize * nrows,
29 & MPI_INFO_NULL, comm, win, ierr )
30
31 C Create the group for the neighbors
32 call mpi_comm_size( comm, size, ierr )
33 call mpi_comm_rank( comm, rank, ierr )
34 nneighbors = 0
35 left = rank - 1
36 if (left .lt. 0) then
37 left = MPI_PROC_NULL
38 else
39 nneighbors = nneighbors + 1
40 nbrs(nneighbors) = left
41 endif
42 right = rank + 1
43 if (right .ge. size) then
44 right = MPI_PROC_NULL
45 else
46 nneighbors = nneighbors + 1
47 nbrs(nneighbors) = right
48 endif
49 call mpi_comm_group( comm, group, ierr )
50 call mpi_group_incl( group, nneighbors, nbrs, group2, ierr )
51 call mpi_group_free( group, ierr )
52 C
53 C Initialize the buffer
54 do i=1,nrows
55 buf(i,0) = -1
56 buf(i,ncols+1) = -1
57 enddo
58 do j=1,ncols
59 do i=1,nrows
60 buf(i,j) = rank * (ncols * nrows) + i + (j-1) * nrows
61 enddo
62 enddo
63 call mpi_win_post( group2, 0, win, ierr )
64 call mpi_win_start( group2, 0, win, ierr )
65 C
66 asize = ncols+1
67 call mpi_put( buf(1,1), nrows, MPI_INTEGER, left, asize,
68 & nrows, MPI_INTEGER, win, ierr )
69 asize = 0
70 call mpi_put( buf(1,ncols), nrows, MPI_INTEGER, right, asize,
71 & nrows, MPI_INTEGER, win, ierr )
72 C
73 call mpi_win_complete( win, ierr )
74 flag = .false.
75 do while (.not. flag)
76 call mpi_win_test( win, flag, ierr )
77 enddo
78 C
79 C Check the results
80 if (left .ne. MPI_PROC_NULL) then
81 do i=1, nrows
82 ans = rank * (ncols * nrows) - nrows + i
83 if (buf(i,0) .ne. ans) then
84 errs = errs + 1
85 if (errs .le. 10) then
86 print *, ' buf(',i,',0) = ', buf(i,0),
87 & 'expected ', ans
88 endif
89 endif
90 enddo
91 endif
92 if (right .ne. MPI_PROC_NULL) then
93 do i=1, nrows
94 ans = (rank+1) * (ncols * nrows) + i
95 if (buf(i,ncols+1) .ne. ans) then
96 errs = errs + 1
97 if (errs .le. 10) then
98 print *, ' buf(',i,',',ncols+1,') = ',
99 & buf(i,ncols+1), ' expected ', ans
100 endif
101 endif
102 enddo
103 endif
104 call mpi_group_free( group2, ierr )
105 call mpi_win_free( win, ierr )
106 call mtestFreeComm( comm )
107 enddo
108
109 call mtest_finalize( errs )
110 end