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 / vecblklen.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2014 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include "mpi.h"
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include "mpitest.h"
11
12 /* Inspired by the Intel MPI_Type_vector_blklen test.
13    Added to include a test of a dataloop optimization that failed.
14 */
15 int main(int argc, char *argv[])
16 {
17     MPI_Datatype ot, ot2, newtype;
18     int position, psize, insize, outsize;
19     char *inbuf = 0, *outbuf = 0, *pbuf = 0, *p;
20     int i, j, k;
21     int errs = 0;
22     int veccount = 16, stride = 16;
23
24     MTest_Init(&argc, &argv);
25     /*
26      * Create a type with some padding
27      */
28     MPI_Type_contiguous(59, MPI_CHAR, &ot);
29     MPI_Type_create_resized(ot, 0, 64, &ot2);
30     /*
31      * Use a vector type with a block size equal to the stride - thus
32      * tiling the target memory with copies of old type.  This is not
33      * a contiguous copy since oldtype has a gap at the end.
34      */
35     MPI_Type_vector(veccount, stride, stride, ot2, &newtype);
36     MPI_Type_commit(&newtype);
37
38     insize = veccount * stride * 64;
39     outsize = insize;
40     inbuf = (char *) malloc(insize);
41     outbuf = (char *) malloc(outsize);
42     for (i = 0; i < outsize; i++) {
43         inbuf[i] = i % 64;
44         outbuf[i] = -1;
45     }
46
47     MPI_Pack_size(1, newtype, MPI_COMM_WORLD, &psize);
48     pbuf = (char *) malloc(psize);
49
50     position = 0;
51     MPI_Pack(inbuf, 1, newtype, pbuf, psize, &position, MPI_COMM_WORLD);
52     psize = position;
53     position = 0;
54     MPI_Unpack(pbuf, psize, &position, outbuf, 1, newtype, MPI_COMM_WORLD);
55
56
57     /* Check the output */
58     p = outbuf;
59     for (i = 0; i < veccount; i++) {
60         for (j = 0; j < stride; j++) {
61             for (k = 0; k < 59; k++) {
62                 if (*p != k % 64) {
63                     errs++;
64                     fprintf(stderr, "[%d,%d,%d]expected %d but saw %d\n", i, j, k, (k % 64), *p);
65                 }
66                 p++;
67             }
68             for (k = 59; k < 64; k++) {
69                 if (*p != -1) {
70                     errs++;
71                     fprintf(stderr, "[%d,%d,%d]expected -1 but saw %d\n", i, j, k, *p);
72                 }
73                 p++;
74             }
75         }
76     }
77
78     free(pbuf);
79     free(inbuf);
80     free(outbuf);
81
82     MPI_Type_free(&ot);
83     MPI_Type_free(&ot2);
84     MPI_Type_free(&newtype);
85     MTest_Finalize(errs);
86     MPI_Finalize();
87
88     return 0;
89 }