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.
14 The default behavior of the test routines should be to briefly indicate
15 the cause of any errors - in this test, that means that verbose needs
16 to be set. Verbose should turn on output that is independent of error
19 static int verbose = 1;
21 int main(int argc, char *argv[]);
22 int parse_args(int argc, char **argv);
23 int lots_of_types_test(void);
25 struct test_struct_1 {
29 int main(int argc, char *argv[])
34 MTest_Init(&argc, &argv);
35 parse_args(argc, argv);
37 /* To improve reporting of problems about operations, we
38 change the error handler to errors return */
39 MPI_Comm_set_errhandler( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
41 err = lots_of_types_test();
42 if (verbose && err) fprintf(stderr, "error in lots_of_types_test\n");
45 /* print message and exit */
46 MTest_Finalize( errs );
52 /* this test allocates 1024 indexed datatypes with 1024 distinct blocks
53 * each. it's possible that a low memory machine will run out of memory
54 * running this test; it appears to take ~25MB of memory at this time.
55 * -- Rob Ross, 11/2/2005
57 #define NUM_DTYPES 1024
58 #define NUM_BLOCKS 1024
59 int lots_of_types_test(void)
63 MPI_Datatype mytypes[NUM_DTYPES];
65 int sendbuf[4] = { 1, 2, 3, 4 };
71 /* note: first element of struct has zero blklen and should be dropped */
72 int disps[NUM_BLOCKS];
75 for (i=0; i < NUM_DTYPES; i++)
76 mytypes[i] = MPI_DATATYPE_NULL;
78 for (i=0; i < NUM_DTYPES; i++) {
84 for (j=1; j < NUM_BLOCKS; j++) {
86 blks[j] = (j % 3) + 1;
89 err = MPI_Type_indexed(NUM_BLOCKS, blks, disps, MPI_INT, &mytypes[i]);
90 if (err != MPI_SUCCESS) {
93 fprintf(stderr, "MPI_Type_indexed returned error on type %d\n",
96 mytypes[i] = MPI_DATATYPE_NULL;
100 MPI_Type_commit(&mytypes[i]);
103 for (i=0; i < NUM_DTYPES; i++) {
105 int recvbuf[4] = { -1, -1, -1, -1 };
107 /* we will only receive 4 ints, so short buffer is ok */
108 err = MPI_Irecv(recvbuf, 1, mytypes[i], 0, 0, MPI_COMM_SELF, &request);
109 if (err != MPI_SUCCESS) {
112 fprintf(stderr, "MPI_Irecv returned error\n");
116 err = MPI_Send(sendbuf, 4, MPI_INT, 0, 0, MPI_COMM_SELF);
117 if (err != MPI_SUCCESS) {
120 fprintf(stderr, "MPI_Send returned error\n");
124 err = MPI_Wait(&request, &status);
125 if (err != MPI_SUCCESS) {
128 fprintf(stderr, "MPI_Wait returned error\n");
133 for (j=0; j < 4; j++) {
134 if (recvbuf[j] != sendbuf[j]) {
137 fprintf(stderr, "recvbuf[%d] = %d; should be %d\n",
138 j, recvbuf[j], sendbuf[j]);
143 /* verify count and elements */
144 err = MPI_Get_count(&status, mytypes[i], &count);
145 if (err != MPI_SUCCESS) {
148 fprintf(stderr, "MPI_Get_count returned error\n");
151 if (count != MPI_UNDEFINED) {
154 fprintf(stderr, "count = %d; should be MPI_UNDEFINED (%d)\n",
155 count, MPI_UNDEFINED);
159 err = MPI_Get_elements(&status, mytypes[i], &elements);
160 if (err != MPI_SUCCESS) {
163 fprintf(stderr, "MPI_Get_elements returned error\n");
169 fprintf(stderr, "elements = %d; should be 4\n", elements);
175 for (i=0; i < NUM_DTYPES; i++) {
176 if (mytypes[i] != MPI_DATATYPE_NULL)
177 MPI_Type_free(&mytypes[i]);
184 int parse_args(int argc, char **argv)
189 while ((ret = getopt(argc, argv, "v")) >= 0)
198 if (argc > 1 && strcmp(argv[1], "-v") == 0)