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.
12 static int verbose = 0;
14 int parse_args(int argc, char **argv);
15 int hindexed_zerotype_test(void);
16 int hindexed_sparsetype_test(void);
18 struct test_struct_1 {
22 int main(int argc, char *argv[])
27 MPI_Init(&argc, &argv);
28 parse_args(argc, argv);
30 /* To improve reporting of problems about operations, we
31 change the error handler to errors return */
32 MPI_Comm_set_errhandler( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
34 err = hindexed_zerotype_test();
35 if (verbose && err) fprintf(stderr, "error in hindexed_zerotype_test\n");
38 err = hindexed_sparsetype_test();
39 if (verbose && err) fprintf(stderr, "error in hindexed_sparsetype_test\n");
42 /* print message and exit */
44 fprintf(stderr, "Found %d errors\n", errs);
47 printf(" No Errors\n");
53 /* tests with an hindexed type with all zero length blocks */
54 int hindexed_zerotype_test(void)
62 int blks[] = { 0, 0, 0 };
63 MPI_Aint disps[] = { 0, 4, 16 };
65 err = MPI_Type_hindexed(3, blks, disps, MPI_INT, &mytype);
66 if (err != MPI_SUCCESS) {
69 fprintf(stderr, "MPI_Type_hindexed returned error\n");
73 MPI_Type_commit(&mytype);
75 err = MPI_Irecv(NULL, 2, mytype, 0, 0, MPI_COMM_SELF, &request);
76 if (err != MPI_SUCCESS) {
79 fprintf(stderr, "MPI_Irecv returned error\n");
83 err = MPI_Send(NULL, 1, mytype, 0, 0, MPI_COMM_SELF);
84 if (err != MPI_SUCCESS) {
87 fprintf(stderr, "MPI_Send returned error\n");
91 err = MPI_Wait(&request, &status);
92 if (err != MPI_SUCCESS) {
95 fprintf(stderr, "MPI_Wait returned error\n");
99 /* verify count and elements */
100 err = MPI_Get_count(&status, mytype, &count);
101 if (err != MPI_SUCCESS) {
104 fprintf(stderr, "MPI_Get_count returned error\n");
110 fprintf(stderr, "count = %d; should be 0\n", count);
114 err = MPI_Get_elements(&status, mytype, &elements);
115 if (err != MPI_SUCCESS) {
118 fprintf(stderr, "MPI_Get_elements returned error\n");
124 fprintf(stderr, "elements = %d; should be 0\n", elements);
128 // MPI_Type_free(&mytype);
133 /* tests a short receive into a sparse hindexed type with a zero
134 * length block in it. sort of eccentric, but we've got the basic
135 * stuff covered with other tests.
137 int hindexed_sparsetype_test(void)
140 int i, count, elements;
145 int sendbuf[6] = { 1, 2, 3, 4, 5, 6 };
147 int correct[16] = { 1, -2, 4, -4, 2, 3, 5, -8, -9, -10, 6,
148 -12, -13, -14, -15, -16 };
150 int blks[] = { 1, 0, 2, 1 };
151 MPI_Aint disps[] = { 0, 1*sizeof(int), 4*sizeof(int), 2*sizeof(int) };
153 err = MPI_Type_hindexed(4, blks, disps, MPI_INT, &mytype);
154 if (err != MPI_SUCCESS) {
157 fprintf(stderr, "MPI_Type_hindexed returned error\n");
161 MPI_Type_commit(&mytype);
163 for (i=0; i < 16; i++) recvbuf[i] = -(i+1);
165 err = MPI_Irecv(recvbuf, 2, mytype, 0, 0, MPI_COMM_SELF, &request);
166 if (err != MPI_SUCCESS) {
169 fprintf(stderr, "MPI_Irecv returned error\n");
173 err = MPI_Send(sendbuf, 6, MPI_INT, 0, 0, MPI_COMM_SELF);
174 if (err != MPI_SUCCESS) {
177 fprintf(stderr, "MPI_Send returned error\n");
181 err = MPI_Wait(&request, &status);
182 if (err != MPI_SUCCESS) {
185 fprintf(stderr, "MPI_Wait returned error\n");
190 for (i=0; i < 16; i++) {
191 if (recvbuf[i] != correct[i]) {
194 fprintf(stderr, "recvbuf[%d] = %d; should be %d\n",
195 i, recvbuf[i], correct[i]);
200 /* verify count and elements */
201 err = MPI_Get_count(&status, mytype, &count);
202 if (err != MPI_SUCCESS) {
205 fprintf(stderr, "MPI_Get_count returned error\n");
208 if (count != MPI_UNDEFINED) {
211 fprintf(stderr, "count = %d; should be MPI_UNDEFINED (%d)\n",
212 count, MPI_UNDEFINED);
216 err = MPI_Get_elements(&status, mytype, &elements);
217 if (err != MPI_SUCCESS) {
220 fprintf(stderr, "MPI_Get_elements returned error\n");
226 fprintf(stderr, "elements = %d; should be 6\n", elements);
230 // MPI_Type_free(&mytype);
236 int parse_args(int argc, char **argv)
241 while ((ret = getopt(argc, argv, "v")) >= 0)
250 if (argc > 1 && strcmp(argv[1], "-v") == 0)