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, int count, MPI_Datatype datatype, int typebufsz);
28 int main(int argc, char **argv)
32 MTest_Init(&argc, &argv);
33 parse_args(argc, argv);
35 /* To improve reporting of problems about operations, we
36 * change the error handler to errors return */
37 MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
39 /* perform some tests */
40 err = darray_2d_c_test1();
42 fprintf(stderr, "%d errors in 2d darray c test 1.\n", err);
45 err = darray_4d_c_test1();
47 fprintf(stderr, "%d errors in 4d darray c test 1.\n", err);
50 /* print message and exit */
51 /* Allow the use of more than one process - some MPI implementations
52 * (including IBM's) check that the number of processes given to
53 * Type_create_darray is no larger than MPI_COMM_WORLD */
62 * Performs a sequence of tests building darrays with single-element
63 * blocks, running through all the various positions that the element might
66 * Returns the number of errors encountered.
68 int darray_2d_c_test1(void)
71 int array[9]; /* initialized below */
72 int array_size[2] = { 3, 3 };
73 int array_distrib[2] = { MPI_DISTRIBUTE_BLOCK, MPI_DISTRIBUTE_BLOCK };
74 int array_dargs[2] = { MPI_DISTRIBUTE_DFLT_DARG, MPI_DISTRIBUTE_DFLT_DARG };
75 int array_psizes[2] = { 3, 3 };
77 int i, rank, err, errs = 0, sizeoftype;
79 /* pretend we are each rank, one at a time */
80 for (rank = 0; rank < 9; rank++) {
82 for (i = 0; i < 9; i++) {
87 err = MPI_Type_create_darray(9, /* size */
91 array_dargs, array_psizes, MPI_ORDER_C, MPI_INT, &darray);
92 if (err != MPI_SUCCESS) {
96 "error in MPI_Type_create_darray call; aborting after %d errors\n", errs);
102 MPI_Type_commit(&darray);
104 MPI_Type_size(darray, &sizeoftype);
105 if (sizeoftype != sizeof(int)) {
108 fprintf(stderr, "size of type = %d; should be %d\n", sizeoftype, (int) sizeof(int));
112 err = pack_and_unpack((char *) array, 1, darray, 9 * sizeof(int));
114 for (i = 0; i < 9; i++) {
116 if ((i == rank) && (array[i] != rank)) {
119 fprintf(stderr, "[2d array rank=%d]:array[%d] = %d; should be %d\n",
120 rank, i, array[i], rank);
122 else if ((i != rank) && (array[i] != 0)) {
125 fprintf(stderr, "[2d array rank=%d]:array[%d] = %d; should be %d\n",
126 rank, i, array[i], 0);
129 MPI_Type_free(&darray);
135 /* darray_4d_c_test1()
137 * Returns the number of errors encountered.
139 int darray_4d_c_test1(void)
143 int array_size[4] = { 6, 3, 2, 2 };
144 int array_distrib[4] = { MPI_DISTRIBUTE_BLOCK,
145 MPI_DISTRIBUTE_BLOCK,
149 int array_dargs[4] = { MPI_DISTRIBUTE_DFLT_DARG,
150 MPI_DISTRIBUTE_DFLT_DARG,
151 MPI_DISTRIBUTE_DFLT_DARG,
152 MPI_DISTRIBUTE_DFLT_DARG
154 int array_psizes[4] = { 6, 3, 1, 1 };
156 int i, rank, err, errs = 0, sizeoftype;
158 for (rank = 0; rank < 18; rank++) {
160 for (i = 0; i < 72; i++) {
165 err = MPI_Type_create_darray(18, /* size */
169 array_dargs, array_psizes, MPI_ORDER_C, MPI_INT, &darray);
170 if (err != MPI_SUCCESS) {
174 "error in MPI_Type_create_darray call; aborting after %d errors\n", errs);
176 MTestPrintError(err);
180 MPI_Type_commit(&darray);
182 /* verify the size of the type */
183 MPI_Type_size(darray, &sizeoftype);
184 if (sizeoftype != 4 * sizeof(int)) {
187 fprintf(stderr, "size of type = %d; should be %d\n",
188 sizeoftype, (int) (4 * sizeof(int)));
192 /* pack and unpack the type, zero'ing out all other values */
193 err = pack_and_unpack((char *) array, 1, darray, 72 * sizeof(int));
195 for (i = 0; i < 4 * rank; i++) {
199 fprintf(stderr, "[4d array rank=%d]:array[%d] = %d; should be %d\n",
200 rank, i, array[i], 0);
204 for (i = 4 * rank; i < 4 * rank + 4; i++) {
208 fprintf(stderr, "[4d array rank=%d]:array[%d] = %d; should be %d\n",
209 rank, i, array[i], i);
212 for (i = 4 * rank + 4; i < 72; i++) {
216 fprintf(stderr, "[4d array rank=%d]:array[%d] = %d; should be %d\n",
217 rank, i, array[i], 0);
221 MPI_Type_free(&darray);
226 /******************************************************************/
230 * Perform packing and unpacking of a buffer for the purposes of checking
231 * to see if we are processing a type correctly. Zeros the buffer between
232 * these two operations, so the data described by the type should be in
233 * place upon return but all other regions of the buffer should be zero.
236 * typebuf - pointer to buffer described by datatype and count that
237 * will be packed and then unpacked into
238 * count, datatype - description of typebuf
239 * typebufsz - size of typebuf; used specifically to zero the buffer
240 * between the pack and unpack steps
243 static int pack_and_unpack(char *typebuf, int count, MPI_Datatype datatype, int typebufsz)
246 int err, errs = 0, pack_size, type_size, position;
248 err = MPI_Type_size(datatype, &type_size);
249 if (err != MPI_SUCCESS) {
252 fprintf(stderr, "error in MPI_Type_size call; aborting after %d errors\n", errs);
254 MTestPrintError(err);
260 err = MPI_Pack_size(count, datatype, MPI_COMM_SELF, &pack_size);
261 if (err != MPI_SUCCESS) {
264 fprintf(stderr, "error in MPI_Pack_size call; aborting after %d errors\n", errs);
266 MTestPrintError(err);
269 packbuf = (char *) malloc(pack_size);
270 if (packbuf == NULL) {
273 fprintf(stderr, "error in malloc call; aborting after %d errors\n", errs);
278 /* FIXME: the pack size returned need not be the type_size - this will
279 * only be true if the pack routine simply moves the bytes but does
280 * no other transformations of the data */
282 err = MPI_Pack(typebuf, count, datatype, packbuf, type_size, &position, MPI_COMM_SELF);
284 if (position != type_size) {
287 fprintf(stderr, "position = %d; should be %d (pack)\n", position, type_size);
290 memset(typebuf, 0, typebufsz);
292 err = MPI_Unpack(packbuf, type_size, &position, typebuf, count, datatype, MPI_COMM_SELF);
293 if (err != MPI_SUCCESS) {
296 fprintf(stderr, "error in MPI_Unpack call; aborting after %d errors\n", errs);
298 MTestPrintError(err);
303 if (position != type_size) {
306 fprintf(stderr, "position = %d; should be %d (unpack)\n", position, type_size);
312 static int parse_args(int argc, char **argv)
317 * while ((ret = getopt(argc, argv, "v")) >= 0)
326 if (argc > 1 && strcmp(argv[1], "-v") == 0)