| 1 |
C |
| 2 |
C Copyright (C) by Argonne National Laboratory |
| 3 |
C See COPYRIGHT in top-level directory |
| 4 |
C |
| 5 |
|
| 6 |
C This program tests MPI_Aint_add/diff in MPI-3.1. |
| 7 |
C The two functions are often used in RMA code. |
| 8 |
C See https://svn.mpi-forum.org/trac/mpi-forum-web/ticket/349 |
| 9 |
|
| 10 |
program main |
| 11 |
implicit none |
| 12 |
include 'mpif.h' |
| 13 |
integer :: rank, nproc |
| 14 |
integer :: ierr, errs |
| 15 |
integer :: array(0:1023) |
| 16 |
integer :: val, target_rank; |
| 17 |
integer(kind=MPI_ADDRESS_KIND) :: bases(0:1), disp, offset |
| 18 |
integer(kind=MPI_ADDRESS_KIND) :: winsize |
| 19 |
integer :: win |
| 20 |
integer :: intsize |
| 21 |
|
| 22 |
errs = 0 |
| 23 |
call mtest_init(ierr); |
| 24 |
call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierr) |
| 25 |
call MPI_Comm_size(MPI_COMM_WORLD, nproc, ierr) |
| 26 |
|
| 27 |
if (rank == 0 .and. nproc /= 2) then |
| 28 |
print *, 'Must run with 2 ranks' |
| 29 |
call MPI_Abort(MPI_COMM_WORLD, 1, ierr) |
| 30 |
endif |
| 31 |
|
| 32 |
C Get the base address in the middle of the array |
| 33 |
if (rank == 0) then |
| 34 |
target_rank = 1 |
| 35 |
array(0) = 1234 |
| 36 |
call MPI_Get_address(array(512), bases(0), ierr) |
| 37 |
else if (rank == 1) then |
| 38 |
target_rank = 0 |
| 39 |
array(1023) = 1234 |
| 40 |
call MPI_Get_address(array(512), bases(1), ierr) |
| 41 |
endif |
| 42 |
|
| 43 |
C Exchange bases |
| 44 |
call MPI_Type_size(MPI_INTEGER, intsize, ierr); |
| 45 |
|
| 46 |
call MPI_Allgather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, bases, |
| 47 |
& 1, MPI_AINT, MPI_COMM_WORLD, ierr) |
| 48 |
|
| 49 |
call MPI_Win_create_dynamic(MPI_INFO_NULL, |
| 50 |
& MPI_COMM_WORLD, win, ierr) |
| 51 |
|
| 52 |
winsize = intsize*1024 |
| 53 |
call MPI_Win_attach(win, array, winsize, ierr) |
| 54 |
|
| 55 |
C Do MPI_Aint addressing arithmetic |
| 56 |
if (rank == 0) then |
| 57 |
disp = intsize*511 |
| 58 |
offset = MPI_Aint_add(bases(1), disp) |
| 59 |
else if (rank == 1) then |
| 60 |
disp = intsize*512 |
| 61 |
offset = MPI_Aint_diff(bases(0), disp) |
| 62 |
endif |
| 63 |
|
| 64 |
C Get value and verify it |
| 65 |
call MPI_Win_fence(MPI_MODE_NOPRECEDE, win, ierr) |
| 66 |
call MPI_Get(val, 1, MPI_INTEGER, target_rank, |
| 67 |
& offset, 1, MPI_INTEGER, win, ierr) |
| 68 |
call MPI_Win_fence(MPI_MODE_NOSUCCEED, win, ierr) |
| 69 |
|
| 70 |
if (val /= 1234) then |
| 71 |
errs = errs + 1 |
| 72 |
print *, rank, ' -- Got', val, 'expected 1234' |
| 73 |
endif |
| 74 |
|
| 75 |
call MPI_Win_detach(win, array, ierr) |
| 76 |
call MPI_Win_free(win, ierr) |
| 77 |
|
| 78 |
call MTest_Finalize(errs) |
| 79 |
end |