1 ! -*- Mode
: Fortran
; -*-
3 ! (C
) 2001 by Argonne National Laboratory
.
4 ! See COPYRIGHT in top
-level directory
.
12 ! Fortran equivalent of coll_test
.c
15 parameter (FILESIZE
=32*32*32*4)
17 ! A
32^
3 array
. For other array sizes
, change FILESIZE above and
18 ! array_of_gsizes below
.
20 ! Uses collective I
/O
. Writes a
3D block
-distributed array
to a file
21 ! corresponding
to the global array in row
-major
(C
) order
, reads it
22 ! back
, and checks that the data
read is correct
.
24 ! Note that the file access pattern is noncontiguous
.
26 integer newtype
, i
, ndims
, array_of_gsizes
(3)
27 integer order
, intsize
, nprocs
, j
, array_of_distribs
(3)
28 integer array_of_dargs
(3), array_of_psizes
(3)
29 integer readbuf
(FILESIZE
), writebuf
(FILESIZE
), bufcount
30 integer mynod
, tmpbuf
(FILESIZE
), array_size
, argc
, iargc
31 integer fh
, status
(MPI_STATUS_SIZE
), request
, ierr
32 character*1024 str
! used
to store the filename
34 @FORTRAN_MPI_OFFSET@ disp
39 call MPI_COMM_SIZE
(MPI_COMM_WORLD
, nprocs
, ierr
)
40 call MPI_COMM_RANK
(MPI_COMM_WORLD
, mynod
, ierr
)
42 ! process
0 takes the file name as a command
-line argument and
43 ! broadcasts it
to other processes
45 if (mynod
.eq
. 0) then
49 do while ((i
.lt
. argc
) .and
. (str
.ne
. '-fname'))
55 print
*, '*# Usage: fcoll_test -fname filename'
57 call MPI_ABORT
(MPI_COMM_WORLD
, 1, ierr
)
62 call MPI_BCAST
(str
, 1024, MPI_CHARACTER
, 0, &
63 & MPI_COMM_WORLD
, ierr
)
65 call MPI_BCAST
(str
, 1024, MPI_CHARACTER
, 0, &
66 & MPI_COMM_WORLD
, ierr
)
70 ! create the distributed array filetype
73 order
= MPI_ORDER_FORTRAN
75 array_of_gsizes
(1) = 32
76 array_of_gsizes
(2) = 32
77 array_of_gsizes
(3) = 32
79 array_of_distribs
(1) = MPI_DISTRIBUTE_BLOCK
80 array_of_distribs
(2) = MPI_DISTRIBUTE_BLOCK
81 array_of_distribs
(3) = MPI_DISTRIBUTE_BLOCK
83 array_of_dargs
(1) = MPI_DISTRIBUTE_DFLT_DARG
84 array_of_dargs
(2) = MPI_DISTRIBUTE_DFLT_DARG
85 array_of_dargs
(3) = MPI_DISTRIBUTE_DFLT_DARG
88 array_of_psizes
(i
) = 0
91 call MPI_DIMS_CREATE
(nprocs
, ndims
, array_of_psizes
, ierr
)
93 call MPI_TYPE_CREATE_DARRAY
(nprocs
, mynod
, ndims
, &
94 & array_of_gsizes
, array_of_distribs
, array_of_dargs
, &
95 & array_of_psizes
, order
, MPI_INTEGER
, newtype
, ierr
)
97 call MPI_TYPE_COMMIT
(newtype
, ierr
)
101 call MPI_TYPE_SIZE
(newtype
, bufcount
, ierr
)
102 call MPI_TYPE_SIZE
(MPI_INTEGER
, intsize
, ierr
)
103 bufcount
= bufcount
/intsize
112 call MPI_IRECV
(tmpbuf
, 1, newtype
, mynod
, 10, MPI_COMM_WORLD
, &
114 call MPI_SEND
(writebuf
, bufcount
, MPI_INTEGER
, mynod
, 10, &
115 & MPI_COMM_WORLD
, ierr
)
116 call MPI_WAIT
(request
, status
, ierr
)
119 array_size
= array_of_gsizes
(1) * array_of_gsizes
(2) * &
122 if (tmpbuf
(i
) .ne
. 0) then
128 ! end of initialization
130 ! write the array
to the file
132 call MPI_FILE_OPEN
(MPI_COMM_WORLD
, str
, &
133 & MPI_MODE_CREATE
+MPI_MODE_RDWR
, MPI_INFO_NULL
, fh
, ierr
)
136 call MPI_FILE_SET_VIEW
(fh
, disp
, MPI_INTEGER
, newtype
, "native", &
137 & MPI_INFO_NULL
, ierr
)
138 call MPI_FILE_WRITE_ALL
(fh
, writebuf
, bufcount
, MPI_INTEGER
, &
140 call MPI_FILE_CLOSE
(fh
, ierr
)
144 call MPI_FILE_OPEN
(MPI_COMM_WORLD
, str
, &
145 & MPI_MODE_CREATE
+MPI_MODE_RDWR
, MPI_INFO_NULL
, fh
, ierr
)
147 call MPI_FILE_SET_VIEW
(fh
, disp
, MPI_INTEGER
, newtype
, "native", &
148 & MPI_INFO_NULL
, ierr
)
149 call MPI_FILE_READ_ALL
(fh
, readbuf
, bufcount
, MPI_INTEGER
, &
151 call MPI_FILE_CLOSE
(fh
, ierr
)
153 ! check the data
read
155 if (readbuf
(i
) .ne
. writebuf
(i
)) then
157 print
*, 'Node ', mynod
, ' readbuf ', readbuf
(i
), &
158 & ' writebuf ', writebuf
(i
), ' i', i
162 call MPI_TYPE_FREE
(newtype
, ierr
)
163 call MPI_Allreduce
( errs
, toterrs
, 1, MPI_INTEGER
, MPI_SUM
, &
164 $ MPI_COMM_WORLD
, ierr
)
165 if (mynod
.eq
. 0) then
166 if( toterrs
.gt
. 0 ) then
167 print
*, 'Found ', toterrs
, ' errors'
169 print
*, ' No Errors'
173 call MPI_FINALIZE
(ierr
)