1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2003 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
13 #define MAX_INT 0x7fffffff
17 static char MTEST_Descrip[] = "Test MPI_Accumulate with fence";
20 int main(int argc, char *argv[])
23 int rank, size, source;
24 int minsize = 2, count, i;
29 MTest_Init(&argc, &argv);
31 /* The following illustrates the use of the routines to
32 * run through a selection of communicators and datatypes.
33 * Use subsets of these for tests that do not involve combinations
34 * of communicators, datatypes, and counts of datatypes */
35 while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
36 if (comm == MPI_COMM_NULL)
38 /* Determine the sender and receiver */
39 MPI_Comm_rank(comm, &rank);
40 MPI_Comm_size(comm, &size);
43 for (count = 1; count < 65000; count = count * 2) {
44 /* We compare with an integer value that can be as large as
45 * size * (count * count + (1/2)*(size-1))
46 * For large machines (size large), this can exceed the
47 * maximum integer for some large values of count. We check
48 * that in advance and break this loop if the above value
49 * would exceed MAX_INT. Specifically,
51 * size*count*count + (1/2)*size*(size-1) > MAX_INT
52 * count*count > (MAX_INT/size - (1/2)*(size-1))
54 if (count * count > (MAX_INT / size - (size - 1) / 2))
56 winbuf = (int *) malloc(count * sizeof(int));
57 sbuf = (int *) malloc(count * sizeof(int));
59 for (i = 0; i < count; i++)
61 for (i = 0; i < count; i++)
62 sbuf[i] = rank + i * count;
63 MPI_Win_create(winbuf, count * sizeof(int), sizeof(int), MPI_INFO_NULL, comm, &win);
64 MPI_Win_fence(0, win);
65 MPI_Accumulate(sbuf, count, MPI_INT, source, 0, count, MPI_INT, MPI_SUM, win);
66 MPI_Win_fence(0, win);
68 /* Check the results */
69 for (i = 0; i < count; i++) {
70 int result = i * count * size + (size * (size - 1)) / 2;
71 if (winbuf[i] != result) {
74 "Winbuf[%d] = %d, expected %d (count = %d, size = %d)\n", i,
75 winbuf[i], result, count, size);