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