1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2014 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
10 /* The next is for isprint */
13 int main(int argc, char *argv[])
20 int errs = 0, toterrs;
21 int rank, size, tsize;
25 MPI_Datatype bases[2];
26 MPI_Datatype str, con;
28 int bufsize, position, insize;
30 MTest_Init(&argc, &argv);
32 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
33 MPI_Comm_size(MPI_COMM_WORLD, &size);
35 for (j = 0; j < 10; j++) {
37 s[j].c = j + rank + 'a';
40 blens[0] = blens[1] = 1;
42 disps[1] = sizeof(int);
45 MPI_Type_struct(2, blens, disps, bases, &str);
46 MPI_Type_commit(&str);
47 MPI_Type_contiguous(10, str, &con);
48 MPI_Type_commit(&con);
49 MPI_Type_size(con, &tsize);
50 MPI_Type_extent(con, &text);
53 printf("Size of MPI array is %d, extent is %d\n", tsize, text);
60 p2 = &(s[10].i); /* This statement may fail on some systems */
61 printf("C array starts at %p and ends at %p for a length of %d\n",
62 s, &(s[9].c), (char *) p2 - (char *) p1);
65 MPI_Type_extent(str, &text);
67 MPI_Type_size(str, &tsize);
68 printf("Size of MPI struct is %d, extent is %d\n", tsize, (int) text);
69 printf("Size of C struct is %d\n", sizeof(struct a));
71 if (text != sizeof(struct a)) {
72 printf("Extent of struct a (%d) does not match sizeof (%d)\n",
73 (int) text, (int) sizeof(struct a));
77 MPI_Pack_size(1, con, MPI_COMM_WORLD, &bufsize);
78 buffer = (char *) malloc(bufsize);
81 MPI_Pack(s, 1, con, buffer, bufsize, &position, MPI_COMM_WORLD);
84 MPI_Unpack(buffer, insize, &position, s1, 1, con, MPI_COMM_WORLD);
86 for (j = 0; j < 10; j++) {
88 printf("%d Sent: %d %c, Got: %d %c\n", rank, s[j].i, s[j].c, s1[j].i, s1[j].c);
90 if (s1[j].i != j + rank) {
92 printf("Got s[%d].i = %d (%x); expected %d\n", j, s1[j].i, s1[j].i, j + rank);
94 if (s1[j].c != 'a' + j + rank) {
96 /* If the character is not a printing character,
97 * this can generate an file that diff, for example,
98 * believes is a binary file */
99 if (isprint((int) (s1[j].c))) {
100 printf("Got s[%d].c = %c; expected %c\n", j, s1[j].c, j + rank + 'a');
103 printf("Got s[%d].c = %x; expected %c\n", j, (int) s1[j].c, j + rank + 'a');
111 MTest_Finalize(errs);