File: accfence2_am.c

package info (click to toggle)
mpich 4.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 423,384 kB
  • sloc: ansic: 1,088,434; cpp: 71,364; javascript: 40,763; f90: 22,829; sh: 17,463; perl: 14,773; xml: 14,418; python: 10,265; makefile: 9,246; fortran: 8,008; java: 4,355; asm: 324; ruby: 176; lisp: 19; php: 8; sed: 4
file content (95 lines) | stat: -rw-r--r-- 3,139 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 * Copyright (C) by Argonne National Laboratory
 *     See COPYRIGHT in top-level directory
 */

#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#include "mpitest.h"

#ifndef MAX_INT
#define MAX_INT 0x7fffffff
#endif

/*
static char MTEST_Descrip[] = "Test MPI_Accumulate with fence";
*/

/* same as accfence2.c, but uses alloc_mem */

int main(int argc, char *argv[])
{
    int errs = 0;
    int rank, size, source;
    int minsize = 2, count, i;
    MPI_Comm comm;
    MPI_Win win;
    int *winbuf, *sbuf;

    MTest_Init(&argc, &argv);

    /* The following illustrates the use of the routines to
     * run through a selection of communicators and datatypes.
     * Use subsets of these for tests that do not involve combinations
     * of communicators, datatypes, and counts of datatypes */
    while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
        if (comm == MPI_COMM_NULL)
            continue;
        /* Determine the sender and receiver */
        MPI_Comm_rank(comm, &rank);
        MPI_Comm_size(comm, &size);
        source = 0;

        for (count = 32768; count < 65000; count = count * 2) {

            /* We compare with an integer value that can be as large as
             * size * (count * count + (1/2)*(size-1))
             * For large machines (size large), this can exceed the
             * maximum integer for some large values of count.  We check
             * that in advance and break this loop if the above value
             * would exceed MAX_INT.  Specifically,
             *
             * size*count*count + (1/2)*size*(size-1) > MAX_INT
             * count*count > (MAX_INT/size - (1/2)*(size-1))
             */
            if (count * count > (MAX_INT / size - (size - 1) / 2))
                break;

            MPI_Alloc_mem(count * sizeof(int), MPI_INFO_NULL, &winbuf);
            MPI_Alloc_mem(count * sizeof(int), MPI_INFO_NULL, &sbuf);

            for (i = 0; i < count; i++)
                winbuf[i] = 0;
            for (i = 0; i < count; i++)
                sbuf[i] = rank + i * count;
            MPI_Win_create(winbuf, count * sizeof(int), sizeof(int), MPI_INFO_NULL, comm, &win);
            MPI_Win_fence(0, win);
            MPI_Accumulate(sbuf, count, MPI_INT, source, 0, count, MPI_INT, MPI_SUM, win);
            MPI_Win_fence(0, win);
            if (rank == source) {
                /* Check the results */
                for (i = 0; i < count; i++) {
                    int result = i * count * size + (size * (size - 1)) / 2;
                    if (winbuf[i] != result) {
                        if (errs < 10) {
                            fprintf(stderr,
                                    "Winbuf[%d] = %d, expected %d (count = %d, size = %d)\n", i,
                                    winbuf[i], result, count, size);
                        }
                        errs++;
                    }
                }
            }

            MPI_Win_free(&win);

            MPI_Free_mem(winbuf);
            MPI_Free_mem(sbuf);
        }
        MTestFreeComm(&comm);
    }

    MTest_Finalize(errs);
    return MTestReturnValue(errs);
}