Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
functioning MPI_Comm_get_name, MPI_Comm_set_name
[simgrid.git] / teshsuite / smpi / mpich3-test / datatype / typelb.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9
10 int main(int argc, char **argv)
11 {
12     int blockcnt[2], rank;
13     MPI_Aint offsets[2], lb, ub, extent;
14     MPI_Datatype tmp_type, newtype;
15
16     MPI_Init(&argc, &argv);
17
18     /* Set some values in locations that should not be accessed */
19     blockcnt[1] = -1;
20     offsets[1] = -1;
21
22     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
23     if (rank == 0) {
24         blockcnt[0] = 1;
25         offsets[0] = 3;
26         MPI_Type_hindexed(1, blockcnt, offsets, MPI_BYTE, &tmp_type);
27         blockcnt[0] = 1;
28         offsets[0] = 1;
29         MPI_Type_hindexed(1, blockcnt, offsets, tmp_type, &newtype);
30         MPI_Type_commit(&newtype);
31
32         MPI_Type_lb(newtype, &lb);
33         MPI_Type_extent(newtype, &extent);
34         MPI_Type_ub(newtype, &ub);
35
36         /* Check that the results are correct */
37 #ifdef DEBUG
38         printf("lb=%ld, ub=%ld, extent=%ld\n", lb, ub, extent);
39         printf("Should be lb=4, ub=5, extent=1\n");
40 #endif
41         if (lb != 4 || ub != 5 || extent != 1) {
42             printf("lb = %d (should be 4), ub = %d (should be 5) extent = %d should be 1\n",
43                    (int) lb, (int) ub, (int) extent);
44         }
45         else {
46             printf(" No Errors\n");
47         }
48
49         MPI_Type_free(&tmp_type);
50         MPI_Type_free(&newtype);
51     }
52
53     MPI_Finalize();
54     return 0;
55 }