|
Packit |
0848f5 |
! This file created from test/mpi/f77/io/atomicityf.f with f77tof90
|
|
Packit |
0848f5 |
! -*- Mode: Fortran; -*-
|
|
Packit |
0848f5 |
!
|
|
Packit |
0848f5 |
! (C) 2004 by Argonne National Laboratory.
|
|
Packit |
0848f5 |
! See COPYRIGHT in top-level directory.
|
|
Packit |
0848f5 |
!
|
|
Packit |
0848f5 |
program main
|
|
Packit |
0848f5 |
use mpi
|
|
Packit |
0848f5 |
integer (kind=MPI_OFFSET_KIND) disp
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
! tests whether atomicity semantics are satisfied for overlapping accesses
|
|
Packit |
0848f5 |
! in atomic mode. The probability of detecting errors is higher if you run
|
|
Packit |
0848f5 |
! it on 8 or more processes.
|
|
Packit |
0848f5 |
! This is a version of the test in romio/test/atomicity.c .
|
|
Packit |
0848f5 |
integer BUFSIZE
|
|
Packit |
0848f5 |
parameter (BUFSIZE=10000)
|
|
Packit |
0848f5 |
integer writebuf(BUFSIZE), readbuf(BUFSIZE)
|
|
Packit |
0848f5 |
integer i, mynod, nprocs, len, ierr, errs, toterrs
|
|
Packit |
0848f5 |
character*50 filename
|
|
Packit |
0848f5 |
integer newtype, fh, info, status(MPI_STATUS_SIZE)
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
errs = 0
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
call MPI_Init(ierr)
|
|
Packit |
0848f5 |
call MPI_Comm_rank(MPI_COMM_WORLD, mynod, ierr )
|
|
Packit |
0848f5 |
call MPI_Comm_size(MPI_COMM_WORLD, nprocs, ierr )
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
! Unlike the C version, we fix the filename because of the difficulties
|
|
Packit |
0848f5 |
! in accessing the command line from different Fortran environments
|
|
Packit |
0848f5 |
filename = "testfile.txt"
|
|
Packit |
0848f5 |
! test atomicity of contiguous accesses
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
! initialize file to all zeros
|
|
Packit |
0848f5 |
if (mynod .eq. 0) then
|
|
Packit |
0848f5 |
call MPI_File_delete(filename, MPI_INFO_NULL, ierr )
|
|
Packit |
0848f5 |
call MPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_CREATE + &
|
|
Packit |
0848f5 |
& MPI_MODE_RDWR, MPI_INFO_NULL, fh, ierr )
|
|
Packit |
0848f5 |
do i=1, BUFSIZE
|
|
Packit |
0848f5 |
writebuf(i) = 0
|
|
Packit |
0848f5 |
enddo
|
|
Packit |
0848f5 |
call MPI_File_write(fh, writebuf, BUFSIZE, MPI_INTEGER, status, &
|
|
Packit |
0848f5 |
& ierr)
|
|
Packit |
0848f5 |
call MPI_File_close(fh, ierr )
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
call MPI_Barrier(MPI_COMM_WORLD, ierr )
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
do i=1, BUFSIZE
|
|
Packit |
0848f5 |
writebuf(i) = 10
|
|
Packit |
0848f5 |
readbuf(i) = 20
|
|
Packit |
0848f5 |
enddo
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
call MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE + &
|
|
Packit |
0848f5 |
& MPI_MODE_RDWR, MPI_INFO_NULL, fh, ierr )
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
! set atomicity to true
|
|
Packit |
0848f5 |
call MPI_File_set_atomicity(fh, .true., ierr)
|
|
Packit |
0848f5 |
if (ierr .ne. MPI_SUCCESS) then
|
|
Packit |
0848f5 |
print *, "Atomic mode not supported on this file system."
|
|
Packit |
0848f5 |
call MPI_Abort(MPI_COMM_WORLD, 1, ierr )
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
call MPI_Barrier(MPI_COMM_WORLD, ierr )
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
! process 0 writes and others concurrently read. In atomic mode,
|
|
Packit |
0848f5 |
! the data read must be either all old values or all new values; nothing
|
|
Packit |
0848f5 |
! in between.
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
if (mynod .eq. 0) then
|
|
Packit |
0848f5 |
call MPI_File_write(fh, writebuf, BUFSIZE, MPI_INTEGER, status, &
|
|
Packit |
0848f5 |
& ierr)
|
|
Packit |
0848f5 |
else
|
|
Packit |
0848f5 |
call MPI_File_read(fh, readbuf, BUFSIZE, MPI_INTEGER, status, &
|
|
Packit |
0848f5 |
& ierr )
|
|
Packit |
0848f5 |
if (ierr .eq. MPI_SUCCESS) then
|
|
Packit |
0848f5 |
if (readbuf(1) .eq. 0) then
|
|
Packit |
0848f5 |
! the rest must also be 0
|
|
Packit |
0848f5 |
do i=2, BUFSIZE
|
|
Packit |
0848f5 |
if (readbuf(i) .ne. 0) then
|
|
Packit |
0848f5 |
errs = errs + 1
|
|
Packit |
0848f5 |
print *, "(contig)Process ", mynod, ": readbuf(", i &
|
|
Packit |
0848f5 |
& ,") is ", readbuf(i), ", should be 0"
|
|
Packit |
0848f5 |
call MPI_Abort(MPI_COMM_WORLD, 1, ierr )
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
enddo
|
|
Packit |
0848f5 |
else if (readbuf(1) .eq. 10) then
|
|
Packit |
0848f5 |
! the rest must also be 10
|
|
Packit |
0848f5 |
do i=2, BUFSIZE
|
|
Packit |
0848f5 |
if (readbuf(i) .ne. 10) then
|
|
Packit |
0848f5 |
errs = errs + 1
|
|
Packit |
0848f5 |
print *, "(contig)Process ", mynod, ": readbuf(", i &
|
|
Packit |
0848f5 |
& ,") is ", readbuf(i), ", should be 10"
|
|
Packit |
0848f5 |
call MPI_Abort(MPI_COMM_WORLD, 1, ierr )
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
enddo
|
|
Packit |
0848f5 |
else
|
|
Packit |
0848f5 |
errs = errs + 1
|
|
Packit |
0848f5 |
print *, "(contig)Process ", mynod, ": readbuf(1) is ", &
|
|
Packit |
0848f5 |
& readbuf(1), ", should be either 0 or 10"
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
call MPI_File_close( fh, ierr )
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
call MPI_Barrier( MPI_COMM_WORLD, ierr )
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
! repeat the same test with a noncontiguous filetype
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
call MPI_Type_vector(BUFSIZE, 1, 2, MPI_INTEGER, newtype, ierr)
|
|
Packit |
0848f5 |
call MPI_Type_commit(newtype, ierr )
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
call MPI_Info_create(info, ierr )
|
|
Packit |
0848f5 |
! I am setting these info values for testing purposes only. It is
|
|
Packit |
0848f5 |
! better to use the default values in practice. */
|
|
Packit |
0848f5 |
call MPI_Info_set(info, "ind_rd_buffer_size", "1209", ierr )
|
|
Packit |
0848f5 |
call MPI_Info_set(info, "ind_wr_buffer_size", "1107", ierr )
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
if (mynod .eq. 0) then
|
|
Packit |
0848f5 |
call MPI_File_delete(filename, MPI_INFO_NULL, ierr )
|
|
Packit |
0848f5 |
call MPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_CREATE + &
|
|
Packit |
0848f5 |
& MPI_MODE_RDWR, info, fh, ierr )
|
|
Packit |
0848f5 |
do i=1, BUFSIZE
|
|
Packit |
0848f5 |
writebuf(i) = 0
|
|
Packit |
0848f5 |
enddo
|
|
Packit |
0848f5 |
disp = 0
|
|
Packit |
0848f5 |
call MPI_File_set_view(fh, disp, MPI_INTEGER, newtype, "native" &
|
|
Packit |
0848f5 |
& ,info, ierr)
|
|
Packit |
0848f5 |
call MPI_File_write(fh, writebuf, BUFSIZE, MPI_INTEGER, status, &
|
|
Packit |
0848f5 |
& ierr )
|
|
Packit |
0848f5 |
call MPI_File_close( fh, ierr )
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
call MPI_Barrier( MPI_COMM_WORLD, ierr )
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
do i=1, BUFSIZE
|
|
Packit |
0848f5 |
writebuf(i) = 10
|
|
Packit |
0848f5 |
readbuf(i) = 20
|
|
Packit |
0848f5 |
enddo
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
call MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE + &
|
|
Packit |
0848f5 |
& MPI_MODE_RDWR, info, fh, ierr )
|
|
Packit |
0848f5 |
call MPI_File_set_atomicity(fh, .true., ierr)
|
|
Packit |
0848f5 |
disp = 0
|
|
Packit |
0848f5 |
call MPI_File_set_view(fh, disp, MPI_INTEGER, newtype, "native", &
|
|
Packit |
0848f5 |
& info, ierr )
|
|
Packit |
0848f5 |
call MPI_Barrier(MPI_COMM_WORLD, ierr )
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
if (mynod .eq. 0) then
|
|
Packit |
0848f5 |
call MPI_File_write(fh, writebuf, BUFSIZE, MPI_INTEGER, status, &
|
|
Packit |
0848f5 |
& ierr )
|
|
Packit |
0848f5 |
else
|
|
Packit |
0848f5 |
call MPI_File_read(fh, readbuf, BUFSIZE, MPI_INTEGER, status, &
|
|
Packit |
0848f5 |
& ierr )
|
|
Packit |
0848f5 |
if (ierr .eq. MPI_SUCCESS) then
|
|
Packit |
0848f5 |
if (readbuf(1) .eq. 0) then
|
|
Packit |
0848f5 |
do i=2, BUFSIZE
|
|
Packit |
0848f5 |
if (readbuf(i) .ne. 0) then
|
|
Packit |
0848f5 |
errs = errs + 1
|
|
Packit |
0848f5 |
print *, "(noncontig)Process ", mynod, ": readbuf(" &
|
|
Packit |
0848f5 |
& , i,") is ", readbuf(i), ", should be 0"
|
|
Packit |
0848f5 |
call MPI_Abort(MPI_COMM_WORLD, 1, ierr )
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
enddo
|
|
Packit |
0848f5 |
else if (readbuf(1) .eq. 10) then
|
|
Packit |
0848f5 |
do i=2, BUFSIZE
|
|
Packit |
0848f5 |
if (readbuf(i) .ne. 10) then
|
|
Packit |
0848f5 |
errs = errs + 1
|
|
Packit |
0848f5 |
print *, "(noncontig)Process ", mynod, ": readbuf(" &
|
|
Packit |
0848f5 |
& , i,") is ", readbuf(i), ", should be 10"
|
|
Packit |
0848f5 |
call MPI_Abort(MPI_COMM_WORLD, 1, ierr )
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
enddo
|
|
Packit |
0848f5 |
else
|
|
Packit |
0848f5 |
errs = errs + 1
|
|
Packit |
0848f5 |
print *, "(noncontig)Process ", mynod, ": readbuf(1) is " &
|
|
Packit |
0848f5 |
& ,readbuf(1), ", should be either 0 or 10"
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
call MPI_File_close( fh, ierr )
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
call MPI_Barrier(MPI_COMM_WORLD, ierr )
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
call MPI_Allreduce( errs, toterrs, 1, MPI_INTEGER, MPI_SUM, &
|
|
Packit |
0848f5 |
& MPI_COMM_WORLD, ierr )
|
|
Packit |
0848f5 |
if (mynod .eq. 0) then
|
|
Packit |
0848f5 |
if( toterrs .gt. 0) then
|
|
Packit |
0848f5 |
print *, "Found ", toterrs, " errors"
|
|
Packit |
0848f5 |
else
|
|
Packit |
0848f5 |
print *, " No Errors"
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
endif
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
call MPI_Type_free(newtype, ierr )
|
|
Packit |
0848f5 |
call MPI_Info_free(info, ierr )
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
call MPI_Finalize(ierr)
|
|
Packit |
0848f5 |
end
|