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, int count, MPI_Datatype datatype, int typebufsz);
22 int main(int argc, char *argv[])
26 MPI_Init(&argc, &argv); /* MPI-1.2 doesn't allow for MPI_Init(0,0) */
27 parse_args(argc, argv);
29 /* To improve reporting of problems about operations, we
30 * change the error handler to errors return */
31 MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
33 err = short_int_pack_test();
36 /* print message and exit */
38 fprintf(stderr, "Found %d errors\n", errs);
41 printf(" No Errors\n");
47 int short_int_pack_test(void)
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));
64 fprintf(stderr, "error packing/unpacking in short_int_pack_test()\n");
69 for (i = 0; i < 16; i++) {
70 if (sibuf[i].a != (short) (i * 2)) {
74 "buf[%d] has invalid short (%d); should be %d\n",
75 i, (int) sibuf[i].a, i * 2);
78 if (sibuf[i].b != i * 2 + 1) {
82 "buf[%d] has invalid int (%d); should be %d\n",
83 i, (int) sibuf[i].b, i * 2 + 1);
93 * Perform packing and unpacking of a buffer for the purposes of checking
94 * to see if we are processing a type correctly. Zeros the buffer between
95 * these two operations, so the data described by the type should be in
96 * place upon return but all other regions of the buffer should be zero.
99 * typebuf - pointer to buffer described by datatype and count that
100 * will be packed and then unpacked into
101 * count, datatype - description of typebuf
102 * typebufsz - size of typebuf; used specifically to zero the buffer
103 * between the pack and unpack steps
106 static int pack_and_unpack(char *typebuf, int count, MPI_Datatype datatype, int typebufsz)
109 int err, errs = 0, pack_size, type_size, position;
111 err = MPI_Type_size(datatype, &type_size);
112 if (err != MPI_SUCCESS) {
115 fprintf(stderr, "error in MPI_Type_size call; aborting after %d errors\n", errs);
122 err = MPI_Pack_size(count, datatype, MPI_COMM_SELF, &pack_size);
123 if (err != MPI_SUCCESS) {
126 fprintf(stderr, "error in MPI_Pack_size call; aborting after %d errors\n", errs);
130 packbuf = (char *) malloc(pack_size);
131 if (packbuf == NULL) {
134 fprintf(stderr, "error in malloc call; aborting after %d errors\n", errs);
140 err = MPI_Pack(typebuf, count, datatype, packbuf, type_size, &position, MPI_COMM_SELF);
142 if (position != type_size) {
145 fprintf(stderr, "position = %d; should be %d (pack)\n", position, type_size);
148 memset(typebuf, 0, typebufsz);
150 err = MPI_Unpack(packbuf, type_size, &position, typebuf, count, datatype, MPI_COMM_SELF);
151 if (err != MPI_SUCCESS) {
154 fprintf(stderr, "error in MPI_Unpack call; aborting after %d errors\n", errs);
160 if (position != type_size) {
163 fprintf(stderr, "position = %d; should be %d (unpack)\n", position, type_size);
169 int parse_args(int argc, char **argv)
174 * while ((ret = getopt(argc, argv, "v")) >= 0)
183 if (argc > 1 && strcmp(argv[1], "-v") == 0)