OpenMPI 0.1.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

topology_inln.h
1 // -*- c++ -*-
2 //
3 // Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
4 // University Research and Technology
5 // Corporation. All rights reserved.
6 // Copyright (c) 2004-2005 The University of Tennessee and The University
7 // of Tennessee Research Foundation. All rights
8 // reserved.
9 // Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
10 // University of Stuttgart. All rights reserved.
11 // Copyright (c) 2004-2005 The Regents of the University of California.
12 // All rights reserved.
13 // Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
14 // Copyright (c) 2011 FUJITSU LIMITED. All rights reserved.
15 // $COPYRIGHT$
16 //
17 // Additional copyrights may follow
18 //
19 // $HEADER$
20 //
21
22 //
23 // ======== Cartcomm member functions ========
24 //
25
26 inline
27 MPI::Cartcomm::Cartcomm(const MPI_Comm& data) {
28 int status = 0;
29 if (MPI::Is_initialized() && (data != MPI_COMM_NULL)) {
30 (void)MPI_Topo_test(data, &status) ;
31 if (status == MPI_CART)
32 mpi_comm = data;
33 else
34 mpi_comm = MPI_COMM_NULL;
35 }
36 else {
37 mpi_comm = data;
38 }
39 }
40
41 //
42 // Groups, Contexts, and Communicators
43 //
44
45 inline MPI::Cartcomm
46 MPI::Cartcomm::Dup() const
47 {
48 MPI_Comm newcomm;
49 (void)MPI_Comm_dup(mpi_comm, &newcomm);
50 return newcomm;
51 }
52
53 //
54 // Process Topologies
55 //
56
57 inline int
58 MPI::Cartcomm::Get_dim() const
59 {
60 int ndims;
61 (void)MPI_Cartdim_get(mpi_comm, &ndims);
62 return ndims;
63 }
64
65 inline void
66 MPI::Cartcomm::Get_topo(int maxdims, int dims[], bool periods[],
67 int coords[]) const
68 {
69 int *int_periods = new int [maxdims];
70 int i;
71 for (i=0; i<maxdims; i++) {
72 int_periods[i] = (int)periods[i];
73 }
74 (void)MPI_Cart_get(mpi_comm, maxdims, dims, int_periods, coords);
75 for (i=0; i<maxdims; i++) {
76 periods[i] = OPAL_INT_TO_BOOL(int_periods[i]);
77 }
78 delete [] int_periods;
79 }
80
81 inline int
82 MPI::Cartcomm::Get_cart_rank(const int coords[]) const
83 {
84 int rank;
85 (void)MPI_Cart_rank(mpi_comm, const_cast<int *>(coords), &rank);
86 return rank;
87 }
88
89 inline void
90 MPI::Cartcomm::Get_coords(int rank, int maxdims, int coords[]) const
91 {
92 (void)MPI_Cart_coords(mpi_comm, rank, maxdims, coords);
93 }
94
95 inline void
96 MPI::Cartcomm::Shift(int direction, int disp,
97 int &rank_source, int &rank_dest) const
98 {
99 (void)MPI_Cart_shift(mpi_comm, direction, disp, &rank_source, &rank_dest);
100 }
101
102 inline MPI::Cartcomm
103 MPI::Cartcomm::Sub(const bool remain_dims[]) const
104 {
105 int ndims;
106 MPI_Cartdim_get(mpi_comm, &ndims);
107 int* int_remain_dims = new int[ndims];
108 for (int i=0; i<ndims; i++) {
109 int_remain_dims[i] = (int)remain_dims[i];
110 }
111 MPI_Comm newcomm;
112 (void)MPI_Cart_sub(mpi_comm, int_remain_dims, &newcomm);
113 delete [] int_remain_dims;
114 return newcomm;
115 }
116
117 inline int
118 MPI::Cartcomm::Map(int ndims, const int dims[], const bool periods[]) const
119 {
120 int *int_periods = new int [ndims];
121 for (int i=0; i<ndims; i++) {
122 int_periods[i] = (int) periods[i];
123 }
124 int newrank;
125 (void)MPI_Cart_map(mpi_comm, ndims, const_cast<int *>(dims), int_periods, &newrank);
126 delete [] int_periods;
127 return newrank;
128 }
129
130
131 inline MPI::Cartcomm&
132 MPI::Cartcomm::Clone() const
133 {
134 MPI_Comm newcomm;
135 (void)MPI_Comm_dup(mpi_comm, &newcomm);
136 MPI::Cartcomm* dup = new MPI::Cartcomm(newcomm);
137 return *dup;
138 }
139
140 //
141 // ======== Graphcomm member functions ========
142 //
143
144 inline
145 MPI::Graphcomm::Graphcomm(const MPI_Comm& data) {
146 int status = 0;
147 if (MPI::Is_initialized() && (data != MPI_COMM_NULL)) {
148 (void)MPI_Topo_test(data, &status) ;
149 if (status == MPI_GRAPH)
150 mpi_comm = data;
151 else
152 mpi_comm = MPI_COMM_NULL;
153 }
154 else {
155 mpi_comm = data;
156 }
157 }
158
159 //
160 // Groups, Contexts, and Communicators
161 //
162
163 inline MPI::Graphcomm
164 MPI::Graphcomm::Dup() const
165 {
166 MPI_Comm newcomm;
167 (void)MPI_Comm_dup(mpi_comm, &newcomm);
168 return newcomm;
169 }
170
171 //
172 // Process Topologies
173 //
174
175 inline void
176 MPI::Graphcomm::Get_dims(int nnodes[], int nedges[]) const
177 {
178 (void)MPI_Graphdims_get(mpi_comm, nnodes, nedges);
179 }
180
181 inline void
182 MPI::Graphcomm::Get_topo(int maxindex, int maxedges, int index[],
183 int edges[]) const
184 {
185 (void)MPI_Graph_get(mpi_comm, maxindex, maxedges, index, edges);
186 }
187
188 inline int
189 MPI::Graphcomm::Get_neighbors_count(int rank) const
190 {
191 int nneighbors;
192 (void)MPI_Graph_neighbors_count(mpi_comm, rank, &nneighbors);
193 return nneighbors;
194 }
195
196 inline void
197 MPI::Graphcomm::Get_neighbors(int rank, int maxneighbors,
198 int neighbors[]) const
199 {
200 (void)MPI_Graph_neighbors(mpi_comm, rank, maxneighbors, neighbors);
201 }
202
203 inline int
204 MPI::Graphcomm::Map(int nnodes, const int index[],
205 const int edges[]) const
206 {
207 int newrank;
208 (void)MPI_Graph_map(mpi_comm, nnodes, const_cast<int *>(index), const_cast<int *>(edges), &newrank);
209 return newrank;
210 }
211
212 inline MPI::Graphcomm&
213 MPI::Graphcomm::Clone() const
214 {
215 MPI_Comm newcomm;
216 (void)MPI_Comm_dup(mpi_comm, &newcomm);
217 MPI::Graphcomm* dup = new MPI::Graphcomm(newcomm);
218 return *dup;
219 }
ompi_communicator_t
Definition: communicator.h:118