File: comm_helpers.c

package info (click to toggle)
openmpi 2.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 99,912 kB
  • ctags: 55,589
  • sloc: ansic: 525,999; f90: 18,307; makefile: 12,062; sh: 6,583; java: 6,278; asm: 3,515; cpp: 2,227; perl: 2,136; python: 1,350; lex: 734; fortran: 52; tcl: 12
file content (92 lines) | stat: -rw-r--r-- 3,291 bytes parent folder | download
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
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2006      The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2006      The Technical University of Chemnitz. All
 *                         rights reserved.
 * Copyright (c) 2014      Research Organization for Information Science
 *                         and Technology (RIST). All rights reserved.
 * Copyright (c) 2015      Los Alamos National Security, LLC. All rights
 *                         reserved.
 *
 * Author(s): Torsten Hoefler <htor@cs.indiana.edu>
 *
 */

#include "comm_helpers.h"

int ompi_comm_neighbors_count(MPI_Comm comm, int *indegree, int *outdegree, int *weighted) {
    int res;

    if (OMPI_COMM_IS_CART(comm)) {
        int ndims;
        res = MPI_Cartdim_get(comm, &ndims)  ;
        if (MPI_SUCCESS != res) {
            return res;
        }
        /* outdegree is always 2*ndims because we need to iterate over empty buffers for MPI_PROC_NULL */
        *outdegree = *indegree = 2*ndims;
        *weighted = 0;
    } else if (OMPI_COMM_IS_GRAPH(comm)) {
        int rank, nneighbors;
        rank = ompi_comm_rank ((ompi_communicator_t *) comm);
        res = MPI_Graph_neighbors_count(comm, rank, &nneighbors);
        if (MPI_SUCCESS != res) {
            return res;
        }
        *outdegree = *indegree = nneighbors;
        *weighted = 0;
    } else if (OMPI_COMM_IS_DIST_GRAPH(comm)) {
        res = MPI_Dist_graph_neighbors_count(comm, indegree, outdegree, weighted);
    } else {
        return MPI_ERR_ARG;
    }

    return MPI_SUCCESS;
}

int ompi_comm_neighbors(MPI_Comm comm, int maxindegree, int sources[], int sourceweights[], int maxoutdegree, int destinations[], int destweights[]) {
    int res;
    int index = 0;

    int indeg, outdeg, wgtd;
    res = ompi_comm_neighbors_count(comm, &indeg, &outdeg, &wgtd);
    if (MPI_SUCCESS != res) {
        return res;
    }
    if(indeg > maxindegree && outdeg > maxoutdegree) return MPI_ERR_TRUNCATE; /* we want to return *all* neighbors */

    if (OMPI_COMM_IS_CART(comm)) {
        int ndims, i, rpeer, speer;
        res = MPI_Cartdim_get(comm, &ndims);
        if (MPI_SUCCESS != res) {
            return res;
        }

        for(i = 0; i<ndims; i++) {
          res = MPI_Cart_shift(comm, i, 1, &rpeer, &speer);
          if (MPI_SUCCESS != res) {
              return res;
          }
          sources[index] = destinations[index] = rpeer; index++;
          sources[index] = destinations[index] = speer; index++;
        }
    } else if (OMPI_COMM_IS_GRAPH(comm)) {
        int rank = ompi_comm_rank ((ompi_communicator_t *) comm);
        res = MPI_Graph_neighbors(comm, rank, maxindegree, sources);
        if (MPI_SUCCESS != res) {
            return res;
        }
        for(int i=0; i<maxindegree; i++) destinations[i] = sources[i];
    } else if (OMPI_COMM_IS_DIST_GRAPH(comm)) {
        res = MPI_Dist_graph_neighbors(comm, maxindegree, sources, sourceweights, maxoutdegree, destinations, destweights);
        if (MPI_SUCCESS != res) {
            return res;
        }
    } else {
        return MPI_ERR_ARG;
    }

    return MPI_SUCCESS;
}