1 #ifndef _ZOLTAN2_MACHINE_TORUS_RCALIBTEST_HPP_
2 #define _ZOLTAN2_MACHINE_TORUS_RCALIBTEST_HPP_
4 #include <Teuchos_Comm.hpp>
5 #include <Teuchos_CommHelpers.hpp>
18 template <
typename pcoord_t,
typename part_t>
28 networkDim(3), actual_networkDim(3),
29 procCoords(NULL), actual_procCoords(NULL),
30 machine_extent(NULL),actual_machine_extent(NULL),
31 is_transformed(false), pl(NULL)
33 actual_machine_extent = machine_extent =
new int[networkDim];
35 actual_machine_extent = machine_extent;
38 actual_procCoords = procCoords =
new pcoord_t *[networkDim];
39 for (
int i = 0; i < networkDim; ++i) {
40 procCoords[i] =
new pcoord_t[this->
numRanks];
41 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
45 pcoord_t *xyz =
new pcoord_t[networkDim];
47 for (
int i = 0; i < networkDim; i++)
48 procCoords[i][this->
myRank] = xyz[i];
53 gatherMachineCoordinates(comm);
58 int transformed_network_dim = networkDim;
60 if (dim < transformed_network_dim)
61 wrap_around[dim++] =
true;
62 if (dim < transformed_network_dim)
63 wrap_around[dim++] =
true;
64 if (dim < transformed_network_dim)
65 wrap_around[dim++] =
true;
70 const Teuchos::ParameterList &pl_):
72 networkDim(3), actual_networkDim(3),
73 procCoords(NULL), actual_procCoords(NULL),
74 machine_extent(NULL),actual_machine_extent(NULL),
75 is_transformed(false), pl(&pl_)
78 actual_machine_extent = machine_extent =
new int[networkDim];
80 actual_machine_extent = machine_extent;
83 actual_procCoords = procCoords =
new pcoord_t *[networkDim];
86 const Teuchos::ParameterEntry *pe1 =
87 this->pl->getEntryPtr(
"Input_RCA_Machine_Coords");
89 std::string input_coord_file;
90 input_coord_file = pe1->getValue<std::string>(&input_coord_file);
91 if (input_coord_file !=
"") {
94 std::vector < std::vector <pcoord_t> > proc_coords(networkDim);
95 std::fstream machine_coord_file(input_coord_file.c_str());
99 machine_coord_file >> a >> b >> c;
100 while(!machine_coord_file.eof()) {
101 proc_coords[0].push_back(a);
102 proc_coords[1].push_back(b);
103 proc_coords[2].push_back(c);
105 machine_coord_file >> a >> b >> c;
108 machine_coord_file.close();
109 std::cout <<
"Rewriting numprocs from:"
110 << this->
numRanks <<
" to:" << i << std::endl;
113 for(
int ii = 0; ii < networkDim; ++ii) {
114 procCoords[ii] =
new pcoord_t[this->
numRanks];
115 for (
int j = 0; j < this->
numRanks; ++j) {
116 procCoords[ii][j] = proc_coords[ii][j];
120 comm.broadcast(0,
sizeof(
int), (
char *) &(this->
numRanks));
123 for (
int i = 0; i < networkDim; ++i) {
124 procCoords[i] =
new pcoord_t[this->
numRanks];
125 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
131 for (
int i = 0; i < networkDim; ++i) {
132 procCoords[i] =
new pcoord_t[this->
numRanks];
133 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
136 pcoord_t *xyz =
new pcoord_t[networkDim];
138 for (
int i = 0; i < networkDim; i++)
139 procCoords[i][this->
myRank] = xyz[i];
144 gatherMachineCoordinates(comm);
146 const Teuchos::ParameterEntry *pe2 =
147 this->pl->getEntryPtr(
"Machine_Optimization_Level");
150 int optimization_level;
151 optimization_level = pe2->getValue<
int>(&optimization_level);
153 if (optimization_level == 1) {
154 is_transformed =
true;
155 this->networkDim = 3;
156 procCoords =
new pcoord_t * [networkDim];
157 for(
int i = 0; i < networkDim; ++i) {
158 procCoords[i] =
new pcoord_t[this->
numRanks] ;
161 for (
int i = 0; i < this->
numRanks; ++i) {
162 procCoords[0][i] = this->actual_procCoords[0][i] * 8;
163 int yordinal = this->actual_procCoords[1][i];
164 procCoords[1][i] = yordinal/2 * (16 + 8) + (yordinal %2) * 8;
165 int zordinal = this->actual_procCoords[2][i];
166 procCoords[2][i] = zordinal * 5 + (zordinal / 8) * 3;
168 int mx = this->machine_extent[0];
169 int my = this->machine_extent[1];
170 int mz = this->machine_extent[2];
173 this->machine_extent =
new int[networkDim];
174 this->machine_extent[0] = mx * 8;
175 this->machine_extent[1] = my/2 * (16 + 8) + (my %2) * 8;
176 this->machine_extent[2] = mz * 5 + (mz / 8) * 3;
178 std::cout <<
"Transforming the coordinates" << std::endl;
181 else if(optimization_level >= 3) {
182 is_transformed =
true;
183 this->networkDim = 6;
184 procCoords =
new pcoord_t * [networkDim];
185 for(
int i = 0; i < networkDim; ++i) {
186 procCoords[i] =
new pcoord_t[this->
numRanks] ;
191 this->machine_extent =
new int[networkDim];
193 this->machine_extent[0] =
194 ceil (
int (this->actual_machine_extent[0]) / 2.0) * 64 ;
195 this->machine_extent[3] = 2 * 8 ;
196 this->machine_extent[1] =
197 ceil(
int (this->actual_machine_extent[1]) / 2.0) * 8 * 2400;
198 this->machine_extent[4] = 2 * 8;
199 this->machine_extent[2] =
200 ceil((
int (this->actual_machine_extent[2])) / 8.0) * 160;
201 this->machine_extent[5] = 8 * 5;
203 for (
int k = 0; k < this->
numRanks ; k++) {
215 procCoords[0][k] = (int (this->actual_procCoords[0][k]) / 2) * 64;
218 procCoords[3][k] = (int (this->actual_procCoords[0][k]) % 2) * 8 ;
225 (int (this->actual_procCoords[1][k]) / 2) * 8 * 2400;
227 procCoords[4][k] = (int (this->actual_procCoords[1][k]) % 2) * 8;
237 ((int (this->actual_procCoords[2][k])) / 8) * 160;
239 procCoords[5][k] = ((int (this->actual_procCoords[2][k])) % 8) * 5;
242 else if(optimization_level == 2) {
244 is_transformed =
true;
245 this->networkDim = 6;
246 procCoords =
new pcoord_t * [networkDim];
247 for(
int i = 0; i < networkDim; ++i) {
248 procCoords[i] =
new pcoord_t[this->
numRanks] ;
253 this->machine_extent =
new int[networkDim];
255 this->machine_extent[0] =
256 ceil(
int (this->actual_machine_extent[0]) / 3.0) * 128 ;
257 this->machine_extent[3] = 3 * 8 ;
258 this->machine_extent[1] =
259 ceil(
int (this->actual_machine_extent[1]) / 2.0) * 8 * 2400;
260 this->machine_extent[4] = 2 * 8;
261 this->machine_extent[2] =
262 ceil((
int (this->actual_machine_extent[2])) / 8.0) * 160;
263 this->machine_extent[5] = 8 * 5;
266 for (
int k = 0; k < this->
numRanks ; k++) {
277 procCoords[0][k] = (int (this->actual_procCoords[0][k]) / 3) * 128;
280 procCoords[3][k] = (int (this->actual_procCoords[0][k]) % 3) * 8 ;
287 (int (this->actual_procCoords[1][k]) / 2) * 8 * 2400;
289 procCoords[4][k] = (int (this->actual_procCoords[1][k]) % 2) * 8;
293 ((int (this->actual_procCoords[2][k])) / 8) * 160;
295 procCoords[5][k] = ((int (this->actual_procCoords[2][k])) % 8) * 5;
302 if (is_transformed) {
303 is_transformed =
false;
304 for (
int i = 0; i < actual_networkDim; i++) {
305 delete [] actual_procCoords[i];
307 delete [] actual_procCoords;
308 delete [] actual_machine_extent;
310 for (
int i = 0; i < networkDim; i++) {
311 delete [] procCoords[i];
313 delete [] procCoords;
314 delete [] machine_extent;
323 if (is_transformed) {
328 nxyz[dim++] = this->machine_extent[0];
329 nxyz[dim++] = this->machine_extent[1];
330 nxyz[dim++] = this->machine_extent[2];
346 for (
int i = 0; i < this->
numRanks; ++i) {
347 std::cout <<
"Rank:" << i
348 <<
" " << procCoords[0][i]
349 <<
" " << procCoords[1][i]
350 <<
" " << procCoords[2][i] << std::endl;
352 std::cout <<
"Machine Extent:"
353 <<
" " << this->machine_extent[0]
354 <<
" " << this->machine_extent[1]
355 <<
" " << this->machine_extent[2] << std::endl;
360 for (
int i = 0; i < this->networkDim; ++i) {
361 xyz[i] = procCoords[i][this->
myRank];
367 xyz[0] = rand() % 25;
368 xyz[1] = rand() % 16;
369 xyz[2] = rand() % 24;
374 pcoord_t *xyz)
const {
375 for (
int i = 0; i < this->networkDim; ++i) {
376 xyz[i] = procCoords[i][rank];
387 allCoords = procCoords;
393 for (
int i = 0; i < networkDim; ++i) {
394 pcoord_t distance = procCoords[i][rank1] - procCoords[i][rank2];
396 distance = -distance;
397 if (machine_extent[i] - distance < distance)
398 distance = machine_extent[i] - distance;
408 int actual_networkDim;
410 pcoord_t **procCoords;
411 pcoord_t **actual_procCoords;
414 part_t *actual_machine_extent;
418 const Teuchos::ParameterList *pl;
426 void gatherMachineCoordinates(
const Teuchos::Comm<int> &comm) {
428 pcoord_t *tmpVect =
new pcoord_t [this->
numRanks];
430 for (
int i = 0; i < networkDim; i++) {
431 Teuchos::reduceAll<int, pcoord_t>(comm, Teuchos::REDUCE_SUM,
433 procCoords[i], tmpVect);
434 pcoord_t *tmp = tmpVect;
435 tmpVect = procCoords[i];
bool getMachineExtent(int *nxyz) const
bool getAllMachineCoordinatesView(pcoord_t **&allCoords) const
MachineClass Base class for representing machine coordinates, networks, etc.
bool getMyMachineCoordinate(pcoord_t *xyz)
SparseMatrixAdapter_t::part_t part_t
bool getMachineCoordinate(const char *nodename, pcoord_t *xyz)
virtual ~MachineTorusRCAForTesting()
bool getMachineCoordinate(const int rank, pcoord_t *xyz) const
bool hasMachineCoordinates() const
MachineTorusRCAForTesting(const Teuchos::Comm< int > &comm, const Teuchos::ParameterList &pl_)
int getRealMachineDim() const
int getMachineDim() const
bool getMyActualMachineCoordinate(pcoord_t *xyz)
virtual bool getHopCount(int rank1, int rank2, pcoord_t &hops)
getHopCount function set hops between rank1 and rank2 return true if coordinates are available ...
virtual bool getMachineExtentWrapArounds(bool *wrap_around) const
An RCA Machine Class (Torus Networks) for testing only A more realistic machine should be used for ta...
bool getRealMachineExtent(int *nxyz) const
MachineTorusRCAForTesting(const Teuchos::Comm< int > &comm)
Constructor: A BlueGeneQ network machine description;.