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 /* same as accfence2.c, but uses alloc_mem */
22 int main(int argc, char *argv[])
25 int rank, size, source;
26 int minsize = 2, count, i;
31 MTest_Init(&argc, &argv);
33 /* The following illustrates the use of the routines to
34 * run through a selection of communicators and datatypes.
35 * Use subsets of these for tests that do not involve combinations
36 * of communicators, datatypes, and counts of datatypes */
37 while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
38 if (comm == MPI_COMM_NULL)
40 /* Determine the sender and receiver */
41 MPI_Comm_rank(comm, &rank);
42 MPI_Comm_size(comm, &size);
45 for (count = 32768; count < 65000; count = count * 2) {
47 /* We compare with an integer value that can be as large as
48 * size * (count * count + (1/2)*(size-1))
49 * For large machines (size large), this can exceed the
50 * maximum integer for some large values of count. We check
51 * that in advance and break this loop if the above value
52 * would exceed MAX_INT. Specifically,
54 * size*count*count + (1/2)*size*(size-1) > MAX_INT
55 * count*count > (MAX_INT/size - (1/2)*(size-1))
57 if (count * count > (MAX_INT / size - (size - 1) / 2))
60 MPI_Alloc_mem(count * sizeof(int), MPI_INFO_NULL, &winbuf);
61 MPI_Alloc_mem(count * sizeof(int), MPI_INFO_NULL, &sbuf);
63 for (i = 0; i < count; i++)
65 for (i = 0; i < count; i++)
66 sbuf[i] = rank + i * count;
67 MPI_Win_create(winbuf, count * sizeof(int), sizeof(int), MPI_INFO_NULL, comm, &win);
68 MPI_Win_fence(0, win);
69 MPI_Accumulate(sbuf, count, MPI_INT, source, 0, count, MPI_INT, MPI_SUM, win);
70 MPI_Win_fence(0, win);
72 /* Check the results */
73 for (i = 0; i < count; i++) {
74 int result = i * count * size + (size * (size - 1)) / 2;
75 if (winbuf[i] != result) {
78 "Winbuf[%d] = %d, expected %d (count = %d, size = %d)\n", i,
79 winbuf[i], result, count, size);