1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2014 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
9 * This program tests MPI_Aint_add/diff in MPI-3.1.
10 * The two functions are often used in RMA code.
11 * See https://svn.mpi-forum.org/trac/mpi-forum-web/ticket/349
18 int main(int argc, char **argv)
26 MPI_Aint disp, offset;
29 MTest_Init(&argc, &argv);
31 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
32 MPI_Comm_size(MPI_COMM_WORLD, &nproc);
34 if (rank == 0 && nproc != 2) {
35 MTestError("Must run with 2 ranks\n");
38 /* Get the base address in the middle of the array */
42 MPI_Get_address(&array[512], &bases[0]);
47 MPI_Get_address(&array[512], &bases[1]);
51 MPI_Allgather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, bases, 1, MPI_AINT, MPI_COMM_WORLD);
53 MPI_Win_create_dynamic(MPI_INFO_NULL, MPI_COMM_WORLD, &win);
54 MPI_Win_attach(win, array, sizeof(int) * 1024);
56 /* Do MPI_Aint addressing arithmetic */
58 disp = sizeof(int) * 511;
59 offset = MPI_Aint_add(bases[1], disp); /* offset points to array[1023] */
62 disp = sizeof(int) * 512;
63 offset = MPI_Aint_diff(bases[0], disp); /* offset points to array[0] */
66 /* Get val and verify it */
67 MPI_Win_fence(MPI_MODE_NOPRECEDE, win);
68 MPI_Get(&val, 1, MPI_INT, target_rank, offset, 1, MPI_INT, win);
69 MPI_Win_fence(MPI_MODE_NOSUCCEED, win);
73 printf("%d -- Got %d, expected 1234\n", rank, val);
76 MPI_Win_detach(win, array);