File: neighb_alltoallw2.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 (74 lines) | stat: -rw-r--r-- 2,566 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright (C) by Argonne National Laboratory
 *     See COPYRIGHT in top-level directory
 */

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

/* Test MPI_Neighbor_alltoallw with different indegree and outdegree */

/* Reference issue #6233. Credit: tjahns */

int main(int argc, char *argv[])
{
    int errs = 0;
    int rank, size;

    MTest_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);

    if (size != 3) {
        printf("This test require exactly 3 processes\n");
        goto fn_exit;
    }

    /* build dist graph where rank 0 sends to rank 1 and 2 */
    static const int indegree[3] = { 0, 1, 1 };
    static const int sources[3][1] = { {-1}, {0}, {0} };
    static const int outdegree[3] = { 2, 0, 0 };
    static const int destinations[3][2] = { {1, 2}, {-1, -1}, {-1, -1} };
    enum { reorder = 0 };
    MPI_Comm neigh_comm;

    MPI_Dist_graph_create_adjacent(MPI_COMM_WORLD,
                                   indegree[rank], sources[rank], MPI_UNWEIGHTED,
                                   outdegree[rank], destinations[rank], MPI_UNWEIGHTED,
                                   MPI_INFO_NULL, reorder, &neigh_comm);

    /* send single integer from rank 0 to rank 1 and 2 */
    static const int send_buf[3][1] = { 0, -1, -2 };
    static const int sendcounts[3][2] = { {1, 1}, {-1, -1}, {-1, -1} };
    static const MPI_Aint sdispls[3][2] = { {0, 0}, {-1, -1}, {-1, -1} };
    static const MPI_Datatype sendtypes[3][2] = {
        {MPI_INT, MPI_INT},
        {MPI_DATATYPE_NULL, MPI_DATATYPE_NULL},
        {MPI_DATATYPE_NULL, MPI_DATATYPE_NULL}
    };
    int recv_buf[3][1] = { {-3}, {-4}, {-5} };
    static const int recvcounts[3][1] = { {-1}, {1}, {1} };
    static const MPI_Aint rdispls[3][1] = { {-1}, {0}, {0} };
    static const MPI_Datatype recvtypes[3][2] = { {MPI_DATATYPE_NULL}, {MPI_INT}, {MPI_INT} };

    MPI_Neighbor_alltoallw(send_buf[rank], sendcounts[rank], sdispls[rank], sendtypes[rank],
                           recv_buf[rank], recvcounts[rank], rdispls[rank], recvtypes[rank],
                           neigh_comm);

    /* check receive buffer */
    static const int ref_recv_buf[3][1] = { {-3}, {0}, {0} };

    if (recv_buf[rank][0] != ref_recv_buf[rank][0]) {
        errs++;
        printf("rank: %d, expected: %d, actual value: %d\n",
               rank, ref_recv_buf[rank][0], recv_buf[rank][0]);
    }

    MPI_Comm_free(&neigh_comm);

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