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 parse_args(int argc, char **argv);
22 int lots_of_types_test(void);
24 struct test_struct_1 {
28 int main(int argc, char *argv[])
33 MTest_Init(&argc, &argv);
34 parse_args(argc, argv);
36 /* To improve reporting of problems about operations, we
37 change the error handler to errors return */
38 MPI_Comm_set_errhandler( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
40 err = lots_of_types_test();
41 if (verbose && err) fprintf(stderr, "error in lots_of_types_test\n");
44 /* print message and exit */
45 MTest_Finalize( errs );
51 /* this test allocates 1024 indexed datatypes with 1024 distinct blocks
52 * each. it's possible that a low memory machine will run out of memory
53 * running this test; it appears to take ~25MB of memory at this time.
54 * -- Rob Ross, 11/2/2005
56 #define NUM_DTYPES 1024
57 #define NUM_BLOCKS 1024
58 int lots_of_types_test(void)
62 MPI_Datatype mytypes[NUM_DTYPES];
64 int sendbuf[4] = { 1, 2, 3, 4 };
70 /* note: first element of struct has zero blklen and should be dropped */
71 int disps[NUM_BLOCKS];
74 for (i=0; i < NUM_DTYPES; i++)
75 mytypes[i] = MPI_DATATYPE_NULL;
77 for (i=0; i < NUM_DTYPES; i++) {
83 for (j=1; j < NUM_BLOCKS; j++) {
85 blks[j] = (j % 3) + 1;
88 err = MPI_Type_indexed(NUM_BLOCKS, blks, disps, MPI_INT, &mytypes[i]);
89 if (err != MPI_SUCCESS) {
92 fprintf(stderr, "MPI_Type_indexed returned error on type %d\n",
95 mytypes[i] = MPI_DATATYPE_NULL;
99 MPI_Type_commit(&mytypes[i]);
102 for (i=0; i < NUM_DTYPES; i++) {
104 int recvbuf[4] = { -1, -1, -1, -1 };
106 /* we will only receive 4 ints, so short buffer is ok */
107 err = MPI_Irecv(recvbuf, 1, mytypes[i], 0, 0, MPI_COMM_SELF, &request);
108 if (err != MPI_SUCCESS) {
111 fprintf(stderr, "MPI_Irecv returned error\n");
115 err = MPI_Send(sendbuf, 4, MPI_INT, 0, 0, MPI_COMM_SELF);
116 if (err != MPI_SUCCESS) {
119 fprintf(stderr, "MPI_Send returned error\n");
123 err = MPI_Wait(&request, &status);
124 if (err != MPI_SUCCESS) {
127 fprintf(stderr, "MPI_Wait returned error\n");
132 for (j=0; j < 4; j++) {
133 if (recvbuf[j] != sendbuf[j]) {
136 fprintf(stderr, "recvbuf[%d] = %d; should be %d\n",
137 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",
154 count, MPI_UNDEFINED);
158 err = MPI_Get_elements(&status, mytypes[i], &elements);
159 if (err != MPI_SUCCESS) {
162 fprintf(stderr, "MPI_Get_elements returned error\n");
168 fprintf(stderr, "elements = %d; should be 4\n", elements);
174 for (i=0; i < NUM_DTYPES; i++) {
175 if (mytypes[i] != MPI_DATATYPE_NULL)
176 MPI_Type_free(&mytypes[i]);
183 int parse_args(int argc, char **argv)
188 while ((ret = getopt(argc, argv, "v")) >= 0)
197 if (argc > 1 && strcmp(argv[1], "-v") == 0)