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;
17 int blockindexed_contig_test(void);
18 int blockindexed_vector_test(void);
20 /* helper functions */
21 int parse_args(int argc, char **argv);
22 static int pack_and_unpack(char *typebuf,
24 MPI_Datatype datatype,
27 int main(int argc, char **argv)
31 MPI_Init(&argc, &argv); /* MPI-1.2 doesn't allow for MPI_Init(0,0) */
32 parse_args(argc, argv);
34 /* To improve reporting of problems about operations, we
35 change the error handler to errors return */
36 MPI_Comm_set_errhandler( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
38 /* perform some tests */
39 err = blockindexed_contig_test();
40 if (err && verbose) fprintf(stderr, "%d errors in blockindexed test.\n",
44 err = blockindexed_vector_test();
45 if (err && verbose) fprintf(stderr, "%d errors in blockindexed vector test.\n",
49 /* print message and exit */
51 fprintf(stderr, "Found %d errors\n", errs);
54 printf(" No Errors\n");
60 /* blockindexed_contig_test()
62 * Tests behavior with a blockindexed that can be converted to a
63 * contig easily. This is specifically for coverage.
65 * Returns the number of errors encountered.
67 int blockindexed_contig_test(void)
69 int buf[4] = {7, -1, -2, -3};
79 err = MPI_Type_create_indexed_block(count,
84 if (err != MPI_SUCCESS) {
87 "error creating struct type in blockindexed_contig_test()\n");
92 MPI_Type_size(MPI_INT, &int_size);
94 err = MPI_Type_size(newtype, &size);
95 if (err != MPI_SUCCESS) {
98 "error obtaining type size in blockindexed_contig_test()\n");
103 if (size != int_size) {
106 "error: size != int_size in blockindexed_contig_test()\n");
111 err = MPI_Type_extent(newtype, &extent);
112 if (err != MPI_SUCCESS) {
115 "error obtaining type extent in blockindexed_contig_test()\n");
120 if (extent != int_size) {
123 "error: extent != int_size in blockindexed_contig_test()\n");
128 MPI_Type_commit(&newtype);
130 err = pack_and_unpack((char *) buf, 1, newtype, 4 * sizeof(int));
134 "error packing/unpacking in blockindexed_contig_test()\n");
139 for (i=0; i < 4; i++) {
147 goodval = 0; /* pack_and_unpack() zeros before unpack */
150 if (buf[i] != goodval) {
152 if (verbose) fprintf(stderr, "buf[%d] = %d; should be %d\n",
157 MPI_Type_free( &newtype );
162 /* blockindexed_vector_test()
164 * Tests behavior with a blockindexed of some vector types;
165 * this shouldn't be easily convertable into anything else.
167 * Returns the number of errors encountered.
169 int blockindexed_vector_test(void)
172 int buf[NELT] = { -1, -1, -1,
178 int expected[NELT] = {
188 int disp[] = {1, 4, 5};
189 MPI_Datatype vectype, newtype;
193 /* create a vector type of 2 ints, skipping one in between */
194 err = MPI_Type_vector(2, 1, 2, MPI_INT, &vectype);
195 if (err != MPI_SUCCESS) {
198 "error creating vector type in blockindexed_contig_test()\n");
203 err = MPI_Type_create_indexed_block(count,
208 if (err != MPI_SUCCESS) {
211 "error creating blockindexed type in blockindexed_contig_test()\n");
216 MPI_Type_size(MPI_INT, &int_size);
218 err = MPI_Type_size(newtype, &size);
219 if (err != MPI_SUCCESS) {
222 "error obtaining type size in blockindexed_contig_test()\n");
227 if (size != 6 * int_size) {
230 "error: size != 6 * int_size in blockindexed_contig_test()\n");
235 MPI_Type_commit(&newtype);
237 err = pack_and_unpack((char *) buf, 1, newtype, NELT * sizeof(int));
241 "error packing/unpacking in blockindexed_vector_test()\n");
246 for (i=0; i < NELT; i++) {
247 if (buf[i] != expected[i]) {
249 if (verbose) fprintf(stderr, "buf[%d] = %d; should be %d\n",
250 i, buf[i], expected[i]);
254 MPI_Type_free( &vectype );
255 MPI_Type_free( &newtype );
262 * Perform packing and unpacking of a buffer for the purposes of checking
263 * to see if we are processing a type correctly. Zeros the buffer between
264 * these two operations, so the data described by the type should be in
265 * place upon return but all other regions of the buffer should be zero.
268 * typebuf - pointer to buffer described by datatype and count that
269 * will be packed and then unpacked into
270 * count, datatype - description of typebuf
271 * typebufsz - size of typebuf; used specifically to zero the buffer
272 * between the pack and unpack steps
275 static int pack_and_unpack(char *typebuf,
277 MPI_Datatype datatype,
281 int err, errs = 0, pack_size, type_size, position;
283 err = MPI_Type_size(datatype, &type_size);
284 if (err != MPI_SUCCESS) {
288 "error in MPI_Type_size call; aborting after %d errors\n",
296 err = MPI_Pack_size(count, datatype, MPI_COMM_SELF, &pack_size);
297 if (err != MPI_SUCCESS) {
301 "error in MPI_Pack_size call; aborting after %d errors\n",
306 packbuf = (char *) malloc(pack_size);
307 if (packbuf == NULL) {
311 "error in malloc call; aborting after %d errors\n",
318 err = MPI_Pack(typebuf,
326 if (position != type_size) {
328 if (verbose) fprintf(stderr, "position = %d; should be %d (pack)\n",
329 position, type_size);
332 memset(typebuf, 0, typebufsz);
334 err = MPI_Unpack(packbuf,
341 if (err != MPI_SUCCESS) {
345 "error in MPI_Unpack call; aborting after %d errors\n",
352 if (position != type_size) {
354 if (verbose) fprintf(stderr, "position = %d; should be %d (unpack)\n",
355 position, type_size);
361 int parse_args(int argc, char **argv)
366 while ((ret = getopt(argc, argv, "v")) >= 0)
375 if (argc > 1 && strcmp(argv[1], "-v") == 0)