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.
8 /* The next is for isprint */
12 int main(int argc, char *argv[])
20 int rank, size, tsize;
24 MPI_Datatype bases[2];
25 MPI_Datatype str, con;
28 MTest_Init(&argc, &argv);
30 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
31 MPI_Comm_size(MPI_COMM_WORLD, &size);
33 for (j = 0; j < 10; j++) {
35 s[j].c = j + rank + 'a';
38 blens[0] = blens[1] = 1;
40 disps[1] = sizeof(int);
43 MPI_Type_struct(2, blens, disps, bases, &str);
44 MPI_Type_commit(&str);
45 MPI_Type_contiguous(10, str, &con);
46 MPI_Type_commit(&con);
47 MPI_Type_size(con, &tsize);
48 MPI_Type_extent(con, &text);
50 MTestPrintfMsg(0, "Size of MPI array is %d, extent is %d\n", tsize, text);
52 /* The following block of code is only for verbose-level output */
56 p2 = &(s[10].i); /* This statement may fail on some systems */
58 "C array starts at %p and ends at %p for a length of %d\n",
59 s, &(s[9].c), (char *) p2 - (char *) p1);
62 MPI_Type_extent(str, &text);
63 MPI_Type_size(str, &tsize);
64 MTestPrintfMsg(0, "Size of MPI struct is %d, extent is %d\n", tsize, (int) text);
65 MTestPrintfMsg(0, "Size of C struct is %d\n", sizeof(struct a));
66 if (text != sizeof(struct a)) {
68 "Extent of struct a (%d) does not match sizeof (%d)\n",
69 (int) text, (int) sizeof(struct a));
73 MPI_Send(s, 1, con, rank ^ 1, 0, MPI_COMM_WORLD);
74 MPI_Recv(s1, 1, con, rank ^ 1, 0, MPI_COMM_WORLD, &status);
76 for (j = 0; j < 10; j++) {
77 MTestPrintfMsg(0, "%d Sent: %d %c, Got: %d %c\n", rank, s[j].i, s[j].c, s1[j].i, s1[j].c);
78 if (s1[j].i != j + status.MPI_SOURCE) {
80 fprintf(stderr, "Got s[%d].i = %d; expected %d\n", j, s1[j].i, j + status.MPI_SOURCE);
82 if (s1[j].c != 'a' + j + status.MPI_SOURCE) {
84 /* If the character is not a printing character,
85 * this can generate a file that diff, for example,
86 * believes is a binary file */
87 if (isprint((int) (s1[j].c))) {
88 fprintf(stderr, "Got s[%d].c = %c; expected %c\n", j, s1[j].c, j + status.MPI_SOURCE + 'a');
91 fprintf(stderr, "Got s[%d].c = %hhx; expected %c\n", j, s1[j].c, j + status.MPI_SOURCE + 'a');