Zoltan2
Loading...
Searching...
No Matches
Zoltan2_MachineTorusLDMS.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Zoltan2: A package of combinatorial algorithms for scientific computing
4//
5// Copyright 2012 NTESS and the Zoltan2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef _ZOLTAN2_MACHINEDEFAULT_HPP_
11#define _ZOLTAN2_MACHINEDEFAULT_HPP_
12
13#include <Teuchos_Comm.hpp>
14#include <Teuchos_CommHelpers.hpp>
15
16namespace Zoltan2{
17
23template <typename nNo_t, typename nCoord_t>
24class DefaultMachine : public MachineRepresentation<nNo_t, nCoord_t> {
25
26private:
27 int networkDim;
28 int numProcs;
29 int myRank;
30
31 nCoord_t **procCoords; // KDD Maybe should be RCP?
32
33public:
38 MachineRepresentation(const Comm<int> &comm):
39 networkDim(0),
40 numProcs(comm.getSize()),
41 myRank(comm.getRank()),
42 procCoords(NULL)
43 {
44 // Will need this constructor to be specific to RAAMP (MD).
45 // Will need a default constructor using, e.g., GeometricGenerator
46 // or nothing at all, for when RAAMP is not available as TPL.
47 //
48 // (AG) In addition, need to be able to run without special
49 // privileges in system (e.g., on hopper).
50 // Notes: For now, all cores connected to same NIC will get the
51 // same coordinates; later, we could add extra coordinate dimensions
52 // to represent nodes or dies (using hwloc info through RAAMP
53 // data object).
54
55 // (MD) will modify mapping test to use machine representation
56 // #ifdef HAVE_ZOLTAN2_OVIS
57
58 // Call initializer for RAAMP data object (AG)
59
60 // get network dimension.
61 // TODO change.
62 // Call RAAMP Data Object to get the network dimension (AG)
63 networkDim = 3;
64
65 //allocate memory for processor coordinates.
66 procCoords = new nCoord_t *[networkDim];
67 for (int i = 0; i < networkDim; ++i) {
68 procCoords[i] = new nCoord_t [numProcs];
69 memset (procCoords[i], 0, sizeof(nCoord_t) * numProcs);
70 }
71 // Obtain the coordinate of the processor.
72 this->getMyCoordinate(/*nCoord_t &xyz[networkDim]*/);
73 // Copy xyz into appropriate spot in procCoords. (MD)
74 // KDD I agree with this
75
76 // reduceAll the coordinates of each processor.
78 }
79
80
84 MachineRepresentation(const RCP<Comm<int> > &comm_):
85 networkDim(0),
86 numProcs(comm_->getSize()),
87 procCoords(0),
88 comm(comm_)
89 {
90 // Will need this constructor to be specific to RAAMP (MD).
91 // Will need a default constructor using, e.g., GeometricGenerator
92 // or nothing at all, for when RAAMP is not available as TPL.
93 //
94 // (AG) In addition, need to be able to run without special
95 // privileges in system (e.g., on hopper).
96 // Notes: For now, all cores connected to same NIC will get the
97 // same coordinates; later, we could add extra coordinate dimensions
98 // to represent nodes or dies (using hwloc info through RAAMP
99 // data object).
100
101 // (MD) will modify mapping test to use machine representation
102 // #ifdef HAVE_ZOLTAN2_OVIS
103
104 // Call initializer for RAAMP data object (AG)
105
106 // get network dimension.
107 // TODO change.
108 // Call RAAMP Data Object to get the network dimension (AG)
109 networkDim = 3;
110
111 // Allocate memory for processor coordinates.
112 procCoords = new nCoord_t *[networkDim];
113 for (int i = 0; i < networkDim; ++i) {
114 procCoords[i] = new nCoord_t [numProcs];
115 memset (procCoords[i], 0, sizeof(nCoord_t) * numProcs);
116 }
117 // Obtain the coordinate of the processor.
118 this->getMyCoordinate(/*nCoord_t &xyz[networkDim]*/);
119 // Copy xyz into appropriate spot in procCoords. (MD) // KDD I Agree.
120
121 // reduceAll the coordinates of each processor.
123 }
124
125
129 void getMyCoordinate(/* nCoord_t &xyz[networkDim]*/) {
130 // KDD Enable the argument rather
131 // KDD than writing into array here
132
133 // Call RAAMP system to get coordinates and store in xyz (MD)
134 // What is the RAAMP call? (AG)
135 // AG will return a view (pointer) to RAAMP's data.
136 // We will copy it into xyz.
137
138//KDD #if defined(HAVE_ZOLTAN2_LDMS)
139//KDD #elif defined(HAVE_ZOLTAN2_TOPOMGR)
140//KDD #elif defined(HAVE_ZOLTAN2_RCA)
141//KDD #else
142
143 // The code below may be good for the default constructor, perhaps,
144 // but it should copy the data into xyz instead of the procCoords.
145 int myRank = comm->getRank();
146
147 int slice = int (pow( double(numProcs), double(1.0 / networkDim)) + 0.5 );
148
149 int m = myRank;
150 for (int i = 0; i < networkDim; ++i) {
151 procCoords[i][myRank] = m / int(pow(slice, double(networkDim - i - 1)));
152 m = m % int(pow(double(slice), double(networkDim - i - 1)));
153 }
154//KDD #endif
155 }
156
157 // KDD Need to return coordinate of any rank?
158 // void getCoordinate(partId_t rank, nCoord_t &xyz[networkDim]) { }
159
163 void gatherMachineCoordinates() { // KDD Should be private
164 nCoord_t *tmpVect = new nCoord_t [numProcs];
165
166 for (int i = 0; i < networkDim; ++i) {
167 reduceAll<int, nCoord_t>(
168 *comm,
169 Teuchos::REDUCE_SUM,
170 numProcs,
171 procCoords[i],
172 tmpVect);
173 nCoord_t *tmp = tmpVect;
174 tmpVect = procCoords[i];
175 procCoords[i] = tmp;
176 }
177 delete [] tmpVect;
178 }
179
184 for (int i = 0; i < networkDim; ++i) {
185 delete [] procCoords[i];
186 }
187 delete [] procCoords;
188 // Free/release THE RAAMP Data Object.
189 // Deinitialize/finalize/whatever (AG)
190 }
191
195 int getProcDim() const{ // KDD Maybe getNetworkDim or getProcCoordDim
196 return networkDim;
197 }
198
202 nCoord_t** getProcCoords() const{
203 // KDD Make clear that returning a View; maybe return ArrayView
204 return procCoords;
205 }
206
210 int getNumProcs() const{
211 return numProcs;
212 }
213
214 // KDD TODO: Need more for full LDMS interface.
215
216};
217}
218#endif
A Default MachineRepresentation Class.
void getMyCoordinate()
getMyCoordinate function stores the coordinate of the current processor in procCoords[*][rank]
int getProcDim() const
getProcDim function returns the dimension of the physical processor layout.
MachineRepresentation(const RCP< Comm< int > > &comm_)
Constructor MachineRepresentation Class.
void gatherMachineCoordinates()
gatherMachineCoordinates function reduces and stores all machine coordinates.
virtual ~MachineRepresentation()
destructor of the class free memory in procCoords.
nCoord_t ** getProcCoords() const
getProcDim function returns the coordinates of processors in two dimensional array.
MachineRepresentation(const Comm< int > &comm)
Constructor MachineRepresentation Class.
int getNumProcs() const
getNumProcs function returns the number of processors.
MachineRepresentation Class Base class for representing machine coordinates, networks,...
Created by mbenlioglu on Aug 31, 2020.