Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix HAVE_FOOBAR flags handling
[simgrid.git] / teshsuite / smpi / mpich3-test / datatype / zeroblks.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 #include <stdio.h>
7 #include "mpi.h"
8 #include "mpitest.h"
9
10 int main( int argc, char *argv[] )
11 {
12     int errs = 0;
13     int position, pack_size, i;
14     int dis[2], blklens[2];
15     MPI_Datatype type;
16     int send_buffer[60];
17     int recv_buffer[60];
18     int pack_buffer[1000];
19
20     MTest_Init( &argc, &argv );
21
22     /* Initialize data in the buffers */
23     for (i=0; i<60; i++) {
24         send_buffer[i] = i;
25         recv_buffer[i] = -1;
26         pack_buffer[i] = -2;
27     }
28
29     /* Create an indexed type with an empty first block */
30     dis[0] = 0;
31     dis[1] = 20;
32
33     blklens[0] = 0;
34     blklens[1] = 40;
35
36     MPI_Type_indexed(2, blklens, dis, MPI_INT, &type);
37     MPI_Type_commit(&type);
38
39     position = 0;
40     MPI_Pack( send_buffer, 1, type, pack_buffer, sizeof(pack_buffer), 
41               &position, MPI_COMM_WORLD );
42     pack_size = position;
43     position = 0;
44     MPI_Unpack( pack_buffer, pack_size, &position, recv_buffer, 1, type, 
45                 MPI_COMM_WORLD );
46
47     /* Check that the last 40 entries of the recv_buffer have the corresponding
48        elements from the send buffer */
49     for (i=0; i<20; i++) {
50         if (recv_buffer[i] != -1) {
51             errs++;
52             fprintf( stderr, "recv_buffer[%d] = %d, should = -1\n", i, 
53                      recv_buffer[i] );
54         }
55     }
56     for (i=20; i<60; i++) {
57         if (recv_buffer[i] != i) {
58             errs++;
59             fprintf( stderr, "recv_buffer[%d] = %d, should = %d\n", i, 
60                      recv_buffer[i], i );
61         }
62     }
63     MPI_Type_free( &type );
64
65     MTest_Finalize( errs );
66     MPI_Finalize();
67     return 0;
68
69 }