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.
13 The default behavior of the test routines should be to briefly indicate
14 the cause of any errors - in this test, that means that verbose needs
15 to be set. Verbose should turn on output that is independent of error
18 static int verbose = 1;
21 int darray_2d_c_test1(void);
22 int darray_4d_c_test1(void);
24 /* helper functions */
25 static int parse_args(int argc, char **argv);
26 static int pack_and_unpack(char *typebuf,
28 MPI_Datatype datatype,
31 int main(int argc, char **argv)
35 MTest_Init( &argc, &argv );
36 parse_args(argc, argv);
38 /* To improve reporting of problems about operations, we
39 change the error handler to errors return */
40 MPI_Comm_set_errhandler( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
42 /* perform some tests */
43 err = darray_2d_c_test1();
44 if (err && verbose) fprintf(stderr,
45 "%d errors in 2d darray c test 1.\n", err);
48 err = darray_4d_c_test1();
49 if (err && verbose) fprintf(stderr,
50 "%d errors in 4d darray c test 1.\n", err);
53 /* print message and exit */
54 /* Allow the use of more than one process - some MPI implementations
55 (including IBM's) check that the number of processes given to
56 Type_create_darray is no larger than MPI_COMM_WORLD */
58 MTest_Finalize( errs );
65 * Performs a sequence of tests building darrays with single-element
66 * blocks, running through all the various positions that the element might
69 * Returns the number of errors encountered.
71 int darray_2d_c_test1(void)
74 int array[9]; /* initialized below */
75 int array_size[2] = {3, 3};
76 int array_distrib[2] = {MPI_DISTRIBUTE_BLOCK, MPI_DISTRIBUTE_BLOCK};
77 int array_dargs[2] = {MPI_DISTRIBUTE_DFLT_DARG, MPI_DISTRIBUTE_DFLT_DARG};
78 int array_psizes[2] = {3, 3};
80 int i, rank, err, errs = 0, sizeoftype;
82 /* pretend we are each rank, one at a time */
83 for (rank=0; rank < 9; rank++) {
85 for (i=0; i < 9; i++) {
90 err = MPI_Type_create_darray(9, /* size */
100 if (err != MPI_SUCCESS) {
104 "error in MPI_Type_create_darray call; aborting after %d errors\n",
107 MTestPrintError( err );
111 MPI_Type_commit(&darray);
113 MPI_Type_size(darray, &sizeoftype);
114 if (sizeoftype != sizeof(int)) {
116 if (verbose) fprintf(stderr, "size of type = %d; should be %d\n",
117 sizeoftype, (int) sizeof(int));
121 err = pack_and_unpack((char *) array, 1, darray, 9*sizeof(int));
123 for (i=0; i < 9; i++) {
125 if ((i == rank) && (array[i] != rank)) {
127 if (verbose) fprintf(stderr, "[2d array rank=%d]:array[%d] = %d; should be %d\n",
128 rank, i, array[i], rank);
130 else if ((i != rank) && (array[i] != 0)) {
132 if (verbose) fprintf(stderr, "[2d array rank=%d]:array[%d] = %d; should be %d\n",
133 rank, i, array[i], 0);
136 MPI_Type_free(&darray);
142 /* darray_4d_c_test1()
144 * Returns the number of errors encountered.
146 int darray_4d_c_test1(void)
150 int array_size[4] = {6, 3, 2, 2};
151 int array_distrib[4] = { MPI_DISTRIBUTE_BLOCK,
152 MPI_DISTRIBUTE_BLOCK,
154 MPI_DISTRIBUTE_NONE };
155 int array_dargs[4] = { MPI_DISTRIBUTE_DFLT_DARG,
156 MPI_DISTRIBUTE_DFLT_DARG,
157 MPI_DISTRIBUTE_DFLT_DARG,
158 MPI_DISTRIBUTE_DFLT_DARG };
159 int array_psizes[4] = {6, 3, 1, 1};
161 int i, rank, err, errs = 0, sizeoftype;
163 for (rank=0; rank < 18; rank++) {
165 for (i=0; i < 72; i++) {
170 err = MPI_Type_create_darray(18, /* size */
180 if (err != MPI_SUCCESS) {
184 "error in MPI_Type_create_darray call; aborting after %d errors\n",
187 MTestPrintError( err );
191 MPI_Type_commit(&darray);
193 /* verify the size of the type */
194 MPI_Type_size(darray, &sizeoftype);
195 if (sizeoftype != 4*sizeof(int)) {
197 if (verbose) fprintf(stderr, "size of type = %d; should be %d\n",
198 sizeoftype, (int) (4*sizeof(int)));
202 /* pack and unpack the type, zero'ing out all other values */
203 err = pack_and_unpack((char *) array, 1, darray, 72*sizeof(int));
205 for (i=0; i < 4*rank; i++) {
208 if (verbose) fprintf(stderr, "[4d array rank=%d]:array[%d] = %d; should be %d\n",
209 rank, i, array[i], 0);
213 for (i=4*rank; i < 4*rank + 4; i++) {
216 if (verbose) fprintf(stderr, "[4d array rank=%d]:array[%d] = %d; should be %d\n",
217 rank, i, array[i], i);
220 for (i=4*rank+4; i < 72; i++) {
223 if (verbose) fprintf(stderr, "[4d array rank=%d]:array[%d] = %d; should be %d\n",
224 rank, i, array[i], 0);
228 MPI_Type_free(&darray);
233 /******************************************************************/
237 * Perform packing and unpacking of a buffer for the purposes of checking
238 * to see if we are processing a type correctly. Zeros the buffer between
239 * these two operations, so the data described by the type should be in
240 * place upon return but all other regions of the buffer should be zero.
243 * typebuf - pointer to buffer described by datatype and count that
244 * will be packed and then unpacked into
245 * count, datatype - description of typebuf
246 * typebufsz - size of typebuf; used specifically to zero the buffer
247 * between the pack and unpack steps
250 static int pack_and_unpack(char *typebuf,
252 MPI_Datatype datatype,
256 int err, errs = 0, pack_size, type_size, position;
258 err = MPI_Type_size(datatype, &type_size);
259 if (err != MPI_SUCCESS) {
263 "error in MPI_Type_size call; aborting after %d errors\n",
266 MTestPrintError( err );
272 err = MPI_Pack_size(count, datatype, MPI_COMM_SELF, &pack_size);
273 if (err != MPI_SUCCESS) {
277 "error in MPI_Pack_size call; aborting after %d errors\n",
280 MTestPrintError( err );
283 packbuf = (char *) malloc(pack_size);
284 if (packbuf == NULL) {
288 "error in malloc call; aborting after %d errors\n",
294 /* FIXME: the pack size returned need not be the type_size - this will
295 only be true if the pack routine simply moves the bytes but does
296 no other transformations of the data */
298 err = MPI_Pack(typebuf,
306 if (position != type_size) {
308 if (verbose) fprintf(stderr, "position = %d; should be %d (pack)\n",
309 position, type_size);
312 memset(typebuf, 0, typebufsz);
314 err = MPI_Unpack(packbuf,
321 if (err != MPI_SUCCESS) {
325 "error in MPI_Unpack call; aborting after %d errors\n",
328 MTestPrintError( err );
333 if (position != type_size) {
335 if (verbose) fprintf(stderr, "position = %d; should be %d (unpack)\n",
336 position, type_size);
342 static int parse_args(int argc, char **argv)
347 while ((ret = getopt(argc, argv, "v")) >= 0)
356 if (argc > 1 && strcmp(argv[1], "-v") == 0)