Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
play with mpich3 cmake files
[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", (int)lb, (int)ub, (int)extent) ;
43         }
44         else {
45             printf( " No Errors\n" );
46         }
47
48         MPI_Type_free(&tmp_type);
49         MPI_Type_free(&newtype);
50     }
51
52     MPI_Finalize();
53     return 0;
54 }