File: alltoall1.c

package info (click to toggle)
mpich 4.3.0%2Breally4.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 419,120 kB
  • sloc: ansic: 1,215,557; cpp: 74,755; javascript: 40,763; f90: 20,649; sh: 18,463; xml: 14,418; python: 14,397; perl: 13,772; makefile: 9,279; fortran: 8,063; java: 4,553; asm: 324; ruby: 176; lisp: 19; php: 8; sed: 4
file content (121 lines) | stat: -rw-r--r-- 4,040 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 * Copyright (C) by Argonne National Laboratory
 *     See COPYRIGHT in top-level directory
 */

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

/*
static char MTEST_Descrip[] = "";
*/

int main(int argc, char *argv[])
{
    int errs = 0;
    int rank, size;
    int minsize = 2, count;
    MPI_Comm comm;
    int *sendbuf, *recvbuf, *p;
    int sendcount, recvcount;
    int i, j;
    MPI_Datatype sendtype, recvtype;

    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);

        /* printf("Size of comm = %d\n", size); */
        for (count = 1; count < 65000; count = count * 2) {

            /* Create a send buf and a receive buf suitable for testing
             * all to all.  */
            sendcount = count;
            recvcount = count;
            sendbuf = (int *) malloc(count * size * sizeof(int));
            recvbuf = (int *) malloc(count * size * sizeof(int));
            sendtype = MPI_INT;
            recvtype = MPI_INT;

            if (!sendbuf || !recvbuf) {
                errs++;
                fprintf(stderr, "Failed to allocate sendbuf and/or recvbuf\n");
                MPI_Abort(MPI_COMM_WORLD, 1);
            }
            for (i = 0; i < count * size; i++)
                recvbuf[i] = -1;
            p = sendbuf;
            for (j = 0; j < size; j++) {
                for (i = 0; i < count; i++) {
                    *p++ = j * size + rank + i;
                }
            }

            MTest_Alltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);

            p = recvbuf;
            for (j = 0; j < size; j++) {
                for (i = 0; i < count; i++) {
                    if (*p != rank * size + j + i) {
                        errs++;
                        if (errs < 10) {
                            fprintf(stderr, "Error with communicator %s and size=%d count=%d\n",
                                    MTestGetIntracommName(), size, count);
                            fprintf(stderr, "recvbuf[%d,%d] = %d, should be %d\n",
                                    j, i, *p, rank * size + j + i);
                        }
                    }
                    p++;
                }
            }

#if MTEST_HAVE_MIN_MPI_VERSION(2,2)
            /* check MPI_IN_PLACE, added in MPI-2.2 */
            p = recvbuf;
            for (j = 0; j < size; j++) {
                for (i = 0; i < count; i++) {
                    *p++ = j * size + rank + i;
                }
            }
            MPI_Alltoall(MPI_IN_PLACE, -1 /*ignored */ , MPI_DATATYPE_NULL /*ignored */ ,
                         recvbuf, recvcount, recvtype, comm);
            p = recvbuf;
            for (j = 0; j < size; j++) {
                for (i = 0; i < count; i++) {
                    if (*p != rank * size + j + i) {
                        errs++;
                        if (errs < 10) {
                            fprintf(stderr,
                                    "Error (MPI_IN_PLACE) with communicator %s and size=%d count=%d\n",
                                    MTestGetIntracommName(), size, count);
                            fprintf(stderr, "recvbuf[%d,%d] = %d, should be %d\n", j, i, *p,
                                    rank * size + j + i);
                        }
                    }
                    p++;
                }
            }
#endif

            free(recvbuf);
            free(sendbuf);
        }
        MTestFreeComm(&comm);
    }

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