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 main(int argc, char *argv[]);
15 int parse_args(int argc, char **argv);
16 int hindexed_zerotype_test(void);
17 int hindexed_sparsetype_test(void);
19 struct test_struct_1 {
23 int main(int argc, char *argv[])
28 MPI_Init(&argc, &argv);
29 parse_args(argc, argv);
31 /* To improve reporting of problems about operations, we
32 change the error handler to errors return */
33 MPI_Comm_set_errhandler( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
35 err = hindexed_zerotype_test();
36 if (verbose && err) fprintf(stderr, "error in hindexed_zerotype_test\n");
39 err = hindexed_sparsetype_test();
40 if (verbose && err) fprintf(stderr, "error in hindexed_sparsetype_test\n");
43 /* print message and exit */
45 fprintf(stderr, "Found %d errors\n", errs);
48 printf(" No Errors\n");
54 /* tests with an hindexed type with all zero length blocks */
55 int hindexed_zerotype_test(void)
63 int blks[] = { 0, 0, 0 };
64 MPI_Aint disps[] = { 0, 4, 16 };
66 err = MPI_Type_hindexed(3, blks, disps, MPI_INT, &mytype);
67 if (err != MPI_SUCCESS) {
70 fprintf(stderr, "MPI_Type_hindexed returned error\n");
74 MPI_Type_commit(&mytype);
76 err = MPI_Irecv(NULL, 2, mytype, 0, 0, MPI_COMM_SELF, &request);
77 if (err != MPI_SUCCESS) {
80 fprintf(stderr, "MPI_Irecv returned error\n");
84 err = MPI_Send(NULL, 1, mytype, 0, 0, MPI_COMM_SELF);
85 if (err != MPI_SUCCESS) {
88 fprintf(stderr, "MPI_Send returned error\n");
92 err = MPI_Wait(&request, &status);
93 if (err != MPI_SUCCESS) {
96 fprintf(stderr, "MPI_Wait returned error\n");
100 /* verify count and elements */
101 err = MPI_Get_count(&status, mytype, &count);
102 if (err != MPI_SUCCESS) {
105 fprintf(stderr, "MPI_Get_count returned error\n");
111 fprintf(stderr, "count = %d; should be 0\n", count);
115 err = MPI_Get_elements(&status, mytype, &elements);
116 if (err != MPI_SUCCESS) {
119 fprintf(stderr, "MPI_Get_elements returned error\n");
125 fprintf(stderr, "elements = %d; should be 0\n", elements);
129 // MPI_Type_free(&mytype);
134 /* tests a short receive into a sparse hindexed type with a zero
135 * length block in it. sort of eccentric, but we've got the basic
136 * stuff covered with other tests.
138 int hindexed_sparsetype_test(void)
141 int i, count, elements;
146 int sendbuf[6] = { 1, 2, 3, 4, 5, 6 };
148 int correct[16] = { 1, -2, 4, -4, 2, 3, 5, -8, -9, -10, 6,
149 -12, -13, -14, -15, -16 };
151 int blks[] = { 1, 0, 2, 1 };
152 MPI_Aint disps[] = { 0, 1*sizeof(int), 4*sizeof(int), 2*sizeof(int) };
154 err = MPI_Type_hindexed(4, blks, disps, MPI_INT, &mytype);
155 if (err != MPI_SUCCESS) {
158 fprintf(stderr, "MPI_Type_hindexed returned error\n");
162 MPI_Type_commit(&mytype);
164 for (i=0; i < 16; i++) recvbuf[i] = -(i+1);
166 err = MPI_Irecv(recvbuf, 2, mytype, 0, 0, MPI_COMM_SELF, &request);
167 if (err != MPI_SUCCESS) {
170 fprintf(stderr, "MPI_Irecv returned error\n");
174 err = MPI_Send(sendbuf, 6, MPI_INT, 0, 0, MPI_COMM_SELF);
175 if (err != MPI_SUCCESS) {
178 fprintf(stderr, "MPI_Send returned error\n");
182 err = MPI_Wait(&request, &status);
183 if (err != MPI_SUCCESS) {
186 fprintf(stderr, "MPI_Wait returned error\n");
191 for (i=0; i < 16; i++) {
192 if (recvbuf[i] != correct[i]) {
195 fprintf(stderr, "recvbuf[%d] = %d; should be %d\n",
196 i, recvbuf[i], correct[i]);
201 /* verify count and elements */
202 err = MPI_Get_count(&status, mytype, &count);
203 if (err != MPI_SUCCESS) {
206 fprintf(stderr, "MPI_Get_count returned error\n");
209 if (count != MPI_UNDEFINED) {
212 fprintf(stderr, "count = %d; should be MPI_UNDEFINED (%d)\n",
213 count, MPI_UNDEFINED);
217 err = MPI_Get_elements(&status, mytype, &elements);
218 if (err != MPI_SUCCESS) {
221 fprintf(stderr, "MPI_Get_elements returned error\n");
227 fprintf(stderr, "elements = %d; should be 6\n", elements);
231 // MPI_Type_free(&mytype);
237 int parse_args(int argc, char **argv)
242 while ((ret = getopt(argc, argv, "v")) >= 0)
251 if (argc > 1 && strcmp(argv[1], "-v") == 0)