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.
13 int win_buf[SIZE], origin_buf[SIZE], result_buf[SIZE];
15 int do_test(int origin_count, MPI_Datatype origin_type, int result_count,
16 MPI_Datatype result_type, int target_count, MPI_Datatype target_type)
18 int errs = 0, ret, origin_type_size, result_type_size;
20 ret = MPI_Put(origin_buf, origin_count, origin_type, 1, 0, target_count, target_type, win);
24 ret = MPI_Get(origin_buf, origin_count, origin_type, 1, 0, target_count, target_type, win);
28 ret = MPI_Accumulate(origin_buf, origin_count, origin_type, 1, 0, target_count,
29 target_type, MPI_SUM, win);
33 ret = MPI_Get_accumulate(origin_buf, origin_count, origin_type, result_buf, result_count,
34 result_type, 1, 0, target_count, target_type, MPI_SUM, win);
38 MPI_Type_size(origin_type, &origin_type_size);
39 MPI_Type_size(result_type, &result_type_size);
41 if (origin_count == 0 || origin_type_size == 0) {
42 ret = MPI_Put(NULL, origin_count, origin_type, 1, 0, target_count, target_type, win);
46 ret = MPI_Get(NULL, origin_count, origin_type, 1, 0, target_count, target_type, win);
50 ret = MPI_Accumulate(NULL, origin_count, origin_type, 1, 0, target_count, target_type,
55 ret = MPI_Get_accumulate(NULL, origin_count, origin_type, result_buf, result_count,
56 result_type, 1, 0, target_count, target_type, MPI_SUM, win);
60 if (result_count == 0 || result_type_size == 0) {
61 ret = MPI_Get_accumulate(NULL, origin_count, origin_type, NULL, result_count,
62 result_type, 1, 0, target_count, target_type, MPI_SUM, win);
71 int main(int argc, char *argv[])
73 int rank, nprocs, i, j, k;
75 MPI_Datatype types[4];
77 MPI_Init(&argc, &argv);
78 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
79 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
82 printf("Run this program with 2 or more processes\n");
83 MPI_Abort(MPI_COMM_WORLD, 1);
86 /* types[0] is of zero size. Everything else is non-zero size */
87 MPI_Type_contiguous(0, MPI_INT, &types[0]);
88 MPI_Type_commit(&types[0]);
90 MPI_Type_contiguous(1, MPI_INT, &types[1]);
91 MPI_Type_commit(&types[1]);
94 types[3] = MPI_DOUBLE;
96 MPI_Win_create(win_buf, SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win);
98 MPI_Win_fence(0, win);
102 for (i = 0; i < 4; i++)
103 for (j = 0; j < 4; j++)
104 for (k = 0; k < 4; k++)
105 do_test(0, types[i], 0, types[j], 0, types[k]);
107 /* single zero-size datatype, but non-zero count */
108 for (i = 1; i < 4; i++) {
109 for (j = 1; j < 4; j++) {
110 do_test(1, types[0], 0, types[i], 0, types[j]);
111 do_test(0, types[i], 1, types[0], 0, types[j]);
112 do_test(0, types[i], 0, types[j], 1, types[0]);
116 /* two zero-size datatypes, but non-zero count */
117 for (i = 1; i < 4; i++) {
118 do_test(1, types[0], 1, types[0], 0, types[i]);
119 do_test(1, types[0], 0, types[i], 1, types[0]);
120 do_test(0, types[i], 1, types[0], 1, types[0]);
122 do_test(1, types[0], 2, types[0], 0, types[i]);
123 do_test(2, types[0], 1, types[0], 0, types[i]);
125 do_test(1, types[0], 0, types[i], 2, types[0]);
126 do_test(2, types[0], 0, types[i], 1, types[0]);
128 do_test(0, types[i], 1, types[0], 2, types[0]);
129 do_test(0, types[i], 2, types[0], 1, types[0]);
132 /* three zero-size datatypes, but non-zero count */
133 do_test(1, types[0], 1, types[0], 1, types[0]);
134 do_test(1, types[0], 1, types[0], 2, types[0]);
135 do_test(1, types[0], 2, types[0], 1, types[0]);
136 do_test(1, types[0], 2, types[0], 2, types[0]);
137 do_test(2, types[0], 1, types[0], 1, types[0]);
138 do_test(2, types[0], 1, types[0], 2, types[0]);
139 do_test(2, types[0], 2, types[0], 1, types[0]);
141 MPI_Win_fence(0, win);
144 MPI_Type_free(&types[0]);
145 MPI_Type_free(&types[1]);
148 printf(" No Errors\n");