source: proiecte/hpl/openmpi_compiled/include/openmpi/ompi/mpi/cxx/topology_inln.h @ 97

Last change on this file since 97 was 97, checked in by (none), 14 years ago

Adding compiled files

File size: 4.9 KB
Line 
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
25inline
26MPI::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
44inline MPI::Cartcomm
45MPI::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
56inline int
57MPI::Cartcomm::Get_dim() const 
58{
59  int ndims;
60  (void)MPI_Cartdim_get(mpi_comm, &ndims);
61  return ndims;
62}
63
64inline void
65MPI::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
80inline int
81MPI::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 
88inline void
89MPI::Cartcomm::Get_coords(int rank, int maxdims, int coords[]) const 
90{
91  (void)MPI_Cart_coords(mpi_comm, rank, maxdims, coords);
92} 
93
94inline void
95MPI::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
101inline MPI::Cartcomm
102MPI::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
116inline int
117MPI::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
130inline MPI::Cartcomm&
131MPI::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
143inline
144MPI::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
162inline MPI::Graphcomm
163MPI::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
174inline void
175MPI::Graphcomm::Get_dims(int nnodes[], int nedges[]) const 
176{
177  (void)MPI_Graphdims_get(mpi_comm, nnodes, nedges);
178}
179
180inline void
181MPI::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
187inline int
188MPI::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
195inline void
196MPI::Graphcomm::Get_neighbors(int rank, int maxneighbors, 
197              int neighbors[]) const 
198{
199  (void)MPI_Graph_neighbors(mpi_comm, rank, maxneighbors, neighbors);
200}
201
202inline int
203MPI::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
211inline MPI::Graphcomm&
212MPI::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}
Note: See TracBrowser for help on using the repository browser.