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();
37 fprintf(stderr, "error in hindexed_zerotype_test\n");
40 err = hindexed_sparsetype_test();
42 fprintf(stderr, "error in hindexed_sparsetype_test\n");
45 /* print message and exit */
47 fprintf(stderr, "Found %d errors\n", errs);
50 printf(" No Errors\n");
56 /* tests with an hindexed type with all zero length blocks */
57 int hindexed_zerotype_test(void)
65 int blks[] = { 0, 0, 0 };
66 MPI_Aint disps[] = { 0, 4, 16 };
68 err = MPI_Type_hindexed(3, blks, disps, MPI_INT, &mytype);
69 if (err != MPI_SUCCESS) {
72 fprintf(stderr, "MPI_Type_hindexed returned error\n");
76 MPI_Type_commit(&mytype);
78 err = MPI_Irecv(NULL, 2, mytype, 0, 0, MPI_COMM_SELF, &request);
79 if (err != MPI_SUCCESS) {
82 fprintf(stderr, "MPI_Irecv returned error\n");
86 err = MPI_Send(NULL, 1, mytype, 0, 0, MPI_COMM_SELF);
87 if (err != MPI_SUCCESS) {
90 fprintf(stderr, "MPI_Send returned error\n");
94 err = MPI_Wait(&request, &status);
95 if (err != MPI_SUCCESS) {
98 fprintf(stderr, "MPI_Wait returned error\n");
102 /* verify count and elements */
103 err = MPI_Get_count(&status, mytype, &count);
104 if (err != MPI_SUCCESS) {
107 fprintf(stderr, "MPI_Get_count returned error\n");
113 fprintf(stderr, "count = %d; should be 0\n", count);
117 err = MPI_Get_elements(&status, mytype, &elements);
118 if (err != MPI_SUCCESS) {
121 fprintf(stderr, "MPI_Get_elements returned error\n");
127 fprintf(stderr, "elements = %d; should be 0\n", elements);
131 MPI_Type_free(&mytype);
136 /* tests a short receive into a sparse hindexed type with a zero
137 * length block in it. sort of eccentric, but we've got the basic
138 * stuff covered with other tests.
140 int hindexed_sparsetype_test(void)
143 int i, count, elements;
148 int sendbuf[6] = { 1, 2, 3, 4, 5, 6 };
150 int correct[16] = { 1, -2, 4, -4, 2, 3, 5, -8, -9, -10, 6,
151 -12, -13, -14, -15, -16
154 int blks[] = { 1, 0, 2, 1 };
155 MPI_Aint disps[] = { 0, 1 * sizeof(int), 4 * sizeof(int), 2 * sizeof(int) };
157 err = MPI_Type_hindexed(4, blks, disps, MPI_INT, &mytype);
158 if (err != MPI_SUCCESS) {
161 fprintf(stderr, "MPI_Type_hindexed returned error\n");
165 MPI_Type_commit(&mytype);
167 for (i = 0; i < 16; i++)
168 recvbuf[i] = -(i + 1);
170 err = MPI_Irecv(recvbuf, 2, mytype, 0, 0, MPI_COMM_SELF, &request);
171 if (err != MPI_SUCCESS) {
174 fprintf(stderr, "MPI_Irecv returned error\n");
178 err = MPI_Send(sendbuf, 6, MPI_INT, 0, 0, MPI_COMM_SELF);
179 if (err != MPI_SUCCESS) {
182 fprintf(stderr, "MPI_Send returned error\n");
186 err = MPI_Wait(&request, &status);
187 if (err != MPI_SUCCESS) {
190 fprintf(stderr, "MPI_Wait returned error\n");
195 for (i = 0; i < 16; i++) {
196 if (recvbuf[i] != correct[i]) {
199 fprintf(stderr, "recvbuf[%d] = %d; should be %d\n", i, recvbuf[i], correct[i]);
204 /* verify count and elements */
205 err = MPI_Get_count(&status, mytype, &count);
206 if (err != MPI_SUCCESS) {
209 fprintf(stderr, "MPI_Get_count returned error\n");
212 if (count != MPI_UNDEFINED) {
215 fprintf(stderr, "count = %d; should be MPI_UNDEFINED (%d)\n", count, MPI_UNDEFINED);
219 err = MPI_Get_elements(&status, mytype, &elements);
220 if (err != MPI_SUCCESS) {
223 fprintf(stderr, "MPI_Get_elements returned error\n");
229 fprintf(stderr, "elements = %d; should be 6\n", elements);
233 MPI_Type_free(&mytype);
239 int parse_args(int argc, char **argv)
244 * while ((ret = getopt(argc, argv, "v")) >= 0)
253 if (argc > 1 && strcmp(argv[1], "-v") == 0)