1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2001 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
11 /* Run with 1 process.
13 This program does an MPI_Get with an indexed datatype. The datatype
14 comprises a single integer at an initial displacement of 1 integer.
15 That is, the first integer in the array is to be skipped.
17 This program found a bug in IBM's MPI in which MPI_Get ignored the
18 displacement and got the first integer instead of the second.
21 int main(int argc, char **argv)
23 int rank, nprocs, mpi_err, *array;
24 int getval, disp, errs = 0;
28 MTest_Init(&argc, &argv);
30 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
31 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
34 /* To improve reporting of problems about operations, we
35 * change the error handler to errors return */
36 MPI_Comm_set_errhandler(MPI_COMM_SELF, MPI_ERRORS_RETURN);
38 /* create an indexed datatype that points to the second integer
39 * in an array (the first integer is skipped). */
41 mpi_err = MPI_Type_create_indexed_block(1, 1, &disp, MPI_INT, &type);
42 if (mpi_err != MPI_SUCCESS)
44 mpi_err = MPI_Type_commit(&type);
45 if (mpi_err != MPI_SUCCESS)
48 /* allocate window of size 2 integers */
49 mpi_err = MPI_Alloc_mem(2 * sizeof(int), MPI_INFO_NULL, &array);
50 if (mpi_err != MPI_SUCCESS)
53 /* create window object */
55 MPI_Win_create(array, 2 * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_SELF, &win);
56 if (mpi_err != MPI_SUCCESS)
59 /* initialize array */
65 /* To improve reporting of problems about operations, we
66 * change the error handler to errors return */
67 MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN);
69 mpi_err = MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win);
70 if (mpi_err != MPI_SUCCESS)
73 /* get the current value of element array[1] */
74 mpi_err = MPI_Get(&getval, 1, MPI_INT, 0, 0, 1, type, win);
75 if (mpi_err != MPI_SUCCESS)
78 mpi_err = MPI_Win_unlock(0, win);
79 if (mpi_err != MPI_SUCCESS)
82 /* getval should contain the value of array[1] */
83 if (getval != array[1]) {
85 printf("getval=%d, should be %d\n", getval, array[1]);
98 printf("MPI function error returned an error\n");
99 MTestPrintError(mpi_err);
101 MTest_Finalize(errs);