Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix+activate rma test
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / contig_displ.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2001 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6
7 #include <stdio.h>
8 #include <mpi.h>
9 #include "mpitest.h"
10
11 /* Run with 1 process.
12
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.
16
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.
19 */
20
21 int main(int argc, char **argv)
22 {
23     int rank, nprocs, mpi_err, *array;
24     int getval, disp, errs = 0;
25     MPI_Win win;
26     MPI_Datatype type;
27
28     MTest_Init(&argc, &argv);
29
30     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
31     MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
32
33     if (rank == 0) {
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);
37
38         /* create an indexed datatype that points to the second integer
39          * in an array (the first integer is skipped). */
40         disp = 1;
41         mpi_err = MPI_Type_create_indexed_block(1, 1, &disp, MPI_INT, &type);
42         if (mpi_err != MPI_SUCCESS)
43             goto err_return;
44         mpi_err = MPI_Type_commit(&type);
45         if (mpi_err != MPI_SUCCESS)
46             goto err_return;
47
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)
51             goto err_return;
52
53         /* create window object */
54         mpi_err =
55             MPI_Win_create(array, 2 * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_SELF, &win);
56         if (mpi_err != MPI_SUCCESS)
57             goto err_return;
58
59         /* initialize array */
60         array[0] = 100;
61         array[1] = 200;
62
63         getval = 0;
64
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);
68
69         mpi_err = MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win);
70         if (mpi_err != MPI_SUCCESS)
71             goto err_return;
72
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)
76             goto err_return;
77
78         mpi_err = MPI_Win_unlock(0, win);
79         if (mpi_err != MPI_SUCCESS)
80             goto err_return;
81
82         /* getval should contain the value of array[1] */
83         if (getval != array[1]) {
84             errs++;
85             printf("getval=%d, should be %d\n", getval, array[1]);
86         }
87
88         MPI_Free_mem(array);
89         MPI_Win_free(&win);
90         MPI_Type_free(&type);
91     }
92
93     MTest_Finalize(errs);
94     MPI_Finalize();
95     return 0;
96
97   err_return:
98     printf("MPI function error returned an error\n");
99     MTestPrintError(mpi_err);
100     errs++;
101     MTest_Finalize(errs);
102     MPI_Finalize();
103     return 1;
104 }