1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2001 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
9 #include "mpitestconf.h"
14 static int verbose = 0;
16 int short_int_pack_test(void);
18 /* helper functions */
19 int parse_args(int argc, char **argv);
20 static int pack_and_unpack(char *typebuf,
22 MPI_Datatype datatype,
25 int main(int argc, char *argv[])
29 MPI_Init(&argc, &argv); /* MPI-1.2 doesn't allow for MPI_Init(0,0) */
30 parse_args(argc, argv);
32 /* To improve reporting of problems about operations, we
33 change the error handler to errors return */
34 MPI_Comm_set_errhandler( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
36 err = short_int_pack_test();
39 /* print message and exit */
41 fprintf(stderr, "Found %d errors\n", errs);
44 printf(" No Errors\n");
50 int short_int_pack_test(void)
54 struct shortint { short a; int b; } sibuf[16];
56 for (i=0; i < 16; i++) {
57 sibuf[i].a = (short) (i * 2);
58 sibuf[i].b = i * 2 + 1;
61 err = pack_and_unpack((char *) sibuf, 16, MPI_SHORT_INT, sizeof(sibuf));
65 "error packing/unpacking in short_int_pack_test()\n");
70 for (i=0; i < 16; i++) {
71 if (sibuf[i].a != (short) (i * 2)) {
75 "buf[%d] has invalid short (%d); should be %d\n",
76 i, (int) sibuf[i].a, i * 2);
79 if (sibuf[i].b != i * 2 + 1) {
83 "buf[%d] has invalid int (%d); should be %d\n",
84 i, (int) sibuf[i].b, i * 2 + 1);
94 * Perform packing and unpacking of a buffer for the purposes of checking
95 * to see if we are processing a type correctly. Zeros the buffer between
96 * these two operations, so the data described by the type should be in
97 * place upon return but all other regions of the buffer should be zero.
100 * typebuf - pointer to buffer described by datatype and count that
101 * will be packed and then unpacked into
102 * count, datatype - description of typebuf
103 * typebufsz - size of typebuf; used specifically to zero the buffer
104 * between the pack and unpack steps
107 static int pack_and_unpack(char *typebuf,
109 MPI_Datatype datatype,
113 int err, errs = 0, pack_size, type_size, position;
115 err = MPI_Type_size(datatype, &type_size);
116 if (err != MPI_SUCCESS) {
120 "error in MPI_Type_size call; aborting after %d errors\n",
128 err = MPI_Pack_size(count, datatype, MPI_COMM_SELF, &pack_size);
129 if (err != MPI_SUCCESS) {
133 "error in MPI_Pack_size call; aborting after %d errors\n",
138 packbuf = (char *) malloc(pack_size);
139 if (packbuf == NULL) {
143 "error in malloc call; aborting after %d errors\n",
150 err = MPI_Pack(typebuf,
158 if (position != type_size) {
160 if (verbose) fprintf(stderr, "position = %d; should be %d (pack)\n",
161 position, type_size);
164 memset(typebuf, 0, typebufsz);
166 err = MPI_Unpack(packbuf,
173 if (err != MPI_SUCCESS) {
177 "error in MPI_Unpack call; aborting after %d errors\n",
184 if (position != type_size) {
186 if (verbose) fprintf(stderr, "position = %d; should be %d (unpack)\n",
187 position, type_size);
193 int parse_args(int argc, char **argv)
198 while ((ret = getopt(argc, argv, "v")) >= 0)
207 if (argc > 1 && strcmp(argv[1], "-v") == 0)