Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce the size of partial shared malloc tests.
[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), &position, MPI_COMM_WORLD);
41     pack_size = position;
42     position = 0;
43     MPI_Unpack(pack_buffer, pack_size, &position, recv_buffer, 1, type, MPI_COMM_WORLD);
44
45     /* Check that the last 40 entries of the recv_buffer have the corresponding
46      * elements from the send buffer */
47     for (i = 0; i < 20; i++) {
48         if (recv_buffer[i] != -1) {
49             errs++;
50             fprintf(stderr, "recv_buffer[%d] = %d, should = -1\n", i, recv_buffer[i]);
51         }
52     }
53     for (i = 20; i < 60; i++) {
54         if (recv_buffer[i] != i) {
55             errs++;
56             fprintf(stderr, "recv_buffer[%d] = %d, should = %d\n", i, recv_buffer[i], i);
57         }
58     }
59     MPI_Type_free(&type);
60
61     MTest_Finalize(errs);
62     MPI_Finalize();
63     return 0;
64
65 }