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) goto err_return;
43 mpi_err = MPI_Type_commit(&type);
44 if (mpi_err != MPI_SUCCESS) goto err_return;
46 /* allocate window of size 2 integers*/
47 mpi_err = MPI_Alloc_mem(2*sizeof(int), MPI_INFO_NULL, &array);
48 if (mpi_err != MPI_SUCCESS) goto err_return;
50 /* create window object */
51 mpi_err = MPI_Win_create(array, 2*sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_SELF, &win);
52 if (mpi_err != MPI_SUCCESS) goto err_return;
54 /* initialize array */
60 /* To improve reporting of problems about operations, we
61 change the error handler to errors return */
62 MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN );
64 mpi_err = MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win);
65 if (mpi_err != MPI_SUCCESS) goto err_return;
67 /* get the current value of element array[1] */
68 mpi_err = MPI_Get(&getval, 1, MPI_INT, 0, 0, 1, type, win);
69 if (mpi_err != MPI_SUCCESS) goto err_return;
71 mpi_err = MPI_Win_unlock(0, win);
72 if (mpi_err != MPI_SUCCESS) goto err_return;
74 /* getval should contain the value of array[1] */
75 if (getval != array[1]) {
77 printf("getval=%d, should be %d\n", getval, array[1]);
90 printf("MPI function error returned an error\n");
91 MTestPrintError( mpi_err );