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();
43 fprintf(stderr, "error in lots_of_types_test\n");
46 /* print message and exit */
53 /* this test allocates 1024 indexed datatypes with 1024 distinct blocks
54 * each. it's possible that a low memory machine will run out of memory
55 * running this test; it appears to take ~25MB of memory at this time.
56 * -- Rob Ross, 11/2/2005
58 #define NUM_DTYPES 1024
59 #define NUM_BLOCKS 1024
60 int lots_of_types_test(void)
64 MPI_Datatype mytypes[NUM_DTYPES];
66 int sendbuf[4] = { 1, 2, 3, 4 };
72 /* note: first element of struct has zero blklen and should be dropped */
73 int disps[NUM_BLOCKS];
76 for (i = 0; i < NUM_DTYPES; i++)
77 mytypes[i] = MPI_DATATYPE_NULL;
79 for (i = 0; i < NUM_DTYPES; i++) {
85 for (j = 1; j < NUM_BLOCKS; j++) {
87 blks[j] = (j % 3) + 1;
90 err = MPI_Type_indexed(NUM_BLOCKS, blks, disps, MPI_INT, &mytypes[i]);
91 if (err != MPI_SUCCESS) {
94 fprintf(stderr, "MPI_Type_indexed returned error on type %d\n", i);
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", j, recvbuf[j], sendbuf[j]);
142 /* verify count and elements */
143 err = MPI_Get_count(&status, mytypes[i], &count);
144 if (err != MPI_SUCCESS) {
147 fprintf(stderr, "MPI_Get_count returned error\n");
150 if (count != MPI_UNDEFINED) {
153 fprintf(stderr, "count = %d; should be MPI_UNDEFINED (%d)\n", count, MPI_UNDEFINED);
157 err = MPI_Get_elements(&status, mytypes[i], &elements);
158 if (err != MPI_SUCCESS) {
161 fprintf(stderr, "MPI_Get_elements returned error\n");
167 fprintf(stderr, "elements = %d; should be 4\n", elements);
173 for (i = 0; i < NUM_DTYPES; i++) {
174 if (mytypes[i] != MPI_DATATYPE_NULL)
175 MPI_Type_free(&mytypes[i]);
182 int parse_args(int argc, char **argv)
187 * while ((ret = getopt(argc, argv, "v")) >= 0)
196 if (argc > 1 && strcmp(argv[1], "-v") == 0)