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