|
Packit Service |
c5cf8c |
! -*- Mode: Fortran; -*-
|
|
Packit Service |
c5cf8c |
!
|
|
Packit Service |
c5cf8c |
! (C) 2014 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
! See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
!
|
|
Packit Service |
c5cf8c |
program main
|
|
Packit Service |
c5cf8c |
use mpi_f08
|
|
Packit Service |
c5cf8c |
integer (kind=MPI_OFFSET_KIND) offset
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
integer errs, ierr, size, rank
|
|
Packit Service |
c5cf8c |
type(MPI_File) fh
|
|
Packit Service |
c5cf8c |
type(MPI_Comm) comm
|
|
Packit Service |
c5cf8c |
type(MPI_Status) status
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
integer buf(1024)
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
errs = 0
|
|
Packit Service |
c5cf8c |
call MTest_Init( ierr )
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
! This test reads a header then sets the view to every "size" int,
|
|
Packit Service |
c5cf8c |
! using set view and current displacement. The file is first written
|
|
Packit Service |
c5cf8c |
! using a combination of collective and ordered writes
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
comm = MPI_COMM_WORLD
|
|
Packit Service |
c5cf8c |
call MPI_File_open( comm, "test.ord", MPI_MODE_WRONLY + &
|
|
Packit Service |
c5cf8c |
& MPI_MODE_CREATE, MPI_INFO_NULL, fh, ierr )
|
|
Packit Service |
c5cf8c |
if (ierr .ne. MPI_SUCCESS) then
|
|
Packit Service |
c5cf8c |
errs = errs + 1
|
|
Packit Service |
c5cf8c |
call MTestPrintErrorMsg( "Open(1)", ierr )
|
|
Packit Service |
c5cf8c |
endif
|
|
Packit Service |
c5cf8c |
call MPI_Comm_size( comm, size, ierr )
|
|
Packit Service |
c5cf8c |
call MPI_Comm_rank( comm, rank, ierr )
|
|
Packit Service |
c5cf8c |
if (size .gt. 1024) then
|
|
Packit Service |
c5cf8c |
if (rank .eq. 0) then
|
|
Packit Service |
c5cf8c |
print *, &
|
|
Packit Service |
c5cf8c |
&"This program must be run with no more than 1024 processes"
|
|
Packit Service |
c5cf8c |
call MPI_Abort( MPI_COMM_WORLD, 1, ierr )
|
|
Packit Service |
c5cf8c |
endif
|
|
Packit Service |
c5cf8c |
endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
buf(1) = size
|
|
Packit Service |
c5cf8c |
call MPI_File_write_all( fh, buf, 1, MPI_INTEGER, status, ierr )
|
|
Packit Service |
c5cf8c |
if (ierr .ne. MPI_SUCCESS) then
|
|
Packit Service |
c5cf8c |
errs = errs + 1
|
|
Packit Service |
c5cf8c |
call MTestPrintErrorMsg( "Write_all", ierr )
|
|
Packit Service |
c5cf8c |
endif
|
|
Packit Service |
c5cf8c |
call MPI_File_get_position( fh, offset, ierr )
|
|
Packit Service |
c5cf8c |
if (ierr .ne. MPI_SUCCESS) then
|
|
Packit Service |
c5cf8c |
errs = errs + 1
|
|
Packit Service |
c5cf8c |
call MTestPrintErrorMsg( "Get_position", ierr )
|
|
Packit Service |
c5cf8c |
endif
|
|
Packit Service |
c5cf8c |
call MPI_File_seek_shared( fh, offset, MPI_SEEK_SET, ierr )
|
|
Packit Service |
c5cf8c |
if (ierr .ne. MPI_SUCCESS) then
|
|
Packit Service |
c5cf8c |
errs = errs + 1
|
|
Packit Service |
c5cf8c |
call MTestPrintErrorMsg( "Seek_shared", ierr )
|
|
Packit Service |
c5cf8c |
endif
|
|
Packit Service |
c5cf8c |
buf(1) = rank
|
|
Packit Service |
c5cf8c |
call MPI_File_write_ordered( fh, buf, 1, MPI_INTEGER, status,ierr)
|
|
Packit Service |
c5cf8c |
if (ierr .ne. MPI_SUCCESS) then
|
|
Packit Service |
c5cf8c |
errs = errs + 1
|
|
Packit Service |
c5cf8c |
call MTestPrintErrorMsg( "Write_ordered", ierr )
|
|
Packit Service |
c5cf8c |
endif
|
|
Packit Service |
c5cf8c |
call MPI_File_close( fh, ierr )
|
|
Packit Service |
c5cf8c |
if (ierr .ne. MPI_SUCCESS) then
|
|
Packit Service |
c5cf8c |
errs = errs + 1
|
|
Packit Service |
c5cf8c |
call MTestPrintErrorMsg( "Close(1)", ierr )
|
|
Packit Service |
c5cf8c |
endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
! Reopen the file as sequential
|
|
Packit Service |
c5cf8c |
call MPI_File_open( comm, "test.ord", MPI_MODE_RDONLY + &
|
|
Packit Service |
c5cf8c |
& MPI_MODE_SEQUENTIAL + MPI_MODE_DELETE_ON_CLOSE, &
|
|
Packit Service |
c5cf8c |
& MPI_INFO_NULL, fh, ierr )
|
|
Packit Service |
c5cf8c |
if (ierr .ne. MPI_SUCCESS) then
|
|
Packit Service |
c5cf8c |
errs = errs + 1
|
|
Packit Service |
c5cf8c |
call MTestPrintErrorMsg( "Open(Read)", ierr )
|
|
Packit Service |
c5cf8c |
endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (rank .eq. 0) then
|
|
Packit Service |
c5cf8c |
call MPI_File_read_shared( fh, buf, 1, MPI_INTEGER, status, &
|
|
Packit Service |
c5cf8c |
& ierr )
|
|
Packit Service |
c5cf8c |
if (ierr .ne. MPI_SUCCESS) then
|
|
Packit Service |
c5cf8c |
errs = errs + 1
|
|
Packit Service |
c5cf8c |
call MTestPrintErrorMsg( "Read_all", ierr )
|
|
Packit Service |
c5cf8c |
endif
|
|
Packit Service |
c5cf8c |
if (buf(1) .ne. size) then
|
|
Packit Service |
c5cf8c |
errs = errs + 1
|
|
Packit Service |
c5cf8c |
print *, "Unexpected value for the header = ", buf(1), &
|
|
Packit Service |
c5cf8c |
& ", should be ", size
|
|
Packit Service |
c5cf8c |
endif
|
|
Packit Service |
c5cf8c |
endif
|
|
Packit Service |
c5cf8c |
call MPI_Barrier( comm, ierr )
|
|
Packit Service |
c5cf8c |
! All processes must provide the same file view for MODE_SEQUENTIAL
|
|
Packit Service |
c5cf8c |
call MPI_File_set_view( fh, MPI_DISPLACEMENT_CURRENT, MPI_INTEGER &
|
|
Packit Service |
c5cf8c |
& ,MPI_INTEGER, "native", MPI_INFO_NULL, ierr )
|
|
Packit Service |
c5cf8c |
if (ierr .ne. MPI_SUCCESS) then
|
|
Packit Service |
c5cf8c |
errs = errs + 1
|
|
Packit Service |
c5cf8c |
call MTestPrintErrorMsg( "Set_view", ierr )
|
|
Packit Service |
c5cf8c |
endif
|
|
Packit Service |
c5cf8c |
buf(1) = -1
|
|
Packit Service |
c5cf8c |
call MPI_File_read_ordered( fh, buf, 1, MPI_INTEGER, status, ierr &
|
|
Packit Service |
c5cf8c |
& )
|
|
Packit Service |
c5cf8c |
if (ierr .ne. MPI_SUCCESS) then
|
|
Packit Service |
c5cf8c |
errs = errs + 1
|
|
Packit Service |
c5cf8c |
call MTestPrintErrorMsg( "Read_all", ierr )
|
|
Packit Service |
c5cf8c |
endif
|
|
Packit Service |
c5cf8c |
if (buf(1) .ne. rank) then
|
|
Packit Service |
c5cf8c |
errs = errs + 1
|
|
Packit Service |
c5cf8c |
print *, rank, ": buf(1) = ", buf(1)
|
|
Packit Service |
c5cf8c |
endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
call MPI_File_close( fh, ierr )
|
|
Packit Service |
c5cf8c |
if (ierr .ne. MPI_SUCCESS) then
|
|
Packit Service |
c5cf8c |
errs = errs + 1
|
|
Packit Service |
c5cf8c |
call MTestPrintErrorMsg( "Close(2)", ierr )
|
|
Packit Service |
c5cf8c |
endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
call MTest_Finalize( errs )
|
|
Packit Service |
c5cf8c |
end
|
|
Packit Service |
c5cf8c |
|