10 #ifndef _ZOLTAN2_MACHINE_TORUS_RCALIBTEST_HPP_
11 #define _ZOLTAN2_MACHINE_TORUS_RCALIBTEST_HPP_
13 #include <Teuchos_Comm.hpp>
14 #include <Teuchos_CommHelpers.hpp>
27 template <
typename pcoord_t,
typename part_t>
37 networkDim(3), actual_networkDim(3),
38 procCoords(NULL), actual_procCoords(NULL),
39 machine_extent(NULL),actual_machine_extent(NULL),
40 is_transformed(false), pl(NULL)
42 actual_machine_extent = machine_extent =
new int[networkDim];
44 actual_machine_extent = machine_extent;
47 actual_procCoords = procCoords =
new pcoord_t *[networkDim];
48 for (
int i = 0; i < networkDim; ++i) {
49 procCoords[i] =
new pcoord_t[this->
numRanks];
50 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
54 pcoord_t *xyz =
new pcoord_t[networkDim];
56 for (
int i = 0; i < networkDim; i++)
57 procCoords[i][this->
myRank] = xyz[i];
62 gatherMachineCoordinates(comm);
67 int transformed_network_dim = networkDim;
69 if (dim < transformed_network_dim)
70 wrap_around[dim++] =
true;
71 if (dim < transformed_network_dim)
72 wrap_around[dim++] =
true;
73 if (dim < transformed_network_dim)
74 wrap_around[dim++] =
true;
79 const Teuchos::ParameterList &pl_):
81 networkDim(3), actual_networkDim(3),
82 procCoords(NULL), actual_procCoords(NULL),
83 machine_extent(NULL),actual_machine_extent(NULL),
84 is_transformed(false), pl(&pl_)
87 actual_machine_extent = machine_extent =
new int[networkDim];
89 actual_machine_extent = machine_extent;
92 actual_procCoords = procCoords =
new pcoord_t *[networkDim];
95 const Teuchos::ParameterEntry *pe1 =
96 this->pl->getEntryPtr(
"Input_RCA_Machine_Coords");
98 std::string input_coord_file;
99 input_coord_file = pe1->getValue<std::string>(&input_coord_file);
100 if (input_coord_file !=
"") {
103 std::vector < std::vector <pcoord_t> > proc_coords(networkDim);
104 std::fstream machine_coord_file(input_coord_file.c_str());
108 machine_coord_file >> a >> b >> c;
109 while(!machine_coord_file.eof()) {
110 proc_coords[0].push_back(a);
111 proc_coords[1].push_back(b);
112 proc_coords[2].push_back(c);
114 machine_coord_file >> a >> b >> c;
117 machine_coord_file.close();
118 std::cout <<
"Rewriting numprocs from:"
119 << this->
numRanks <<
" to:" << i << std::endl;
122 for(
int ii = 0; ii < networkDim; ++ii) {
123 procCoords[ii] =
new pcoord_t[this->
numRanks];
124 for (
int j = 0; j < this->
numRanks; ++j) {
125 procCoords[ii][j] = proc_coords[ii][j];
129 comm.broadcast(0,
sizeof(
int), (
char *) &(this->
numRanks));
132 for (
int i = 0; i < networkDim; ++i) {
133 procCoords[i] =
new pcoord_t[this->
numRanks];
134 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
140 for (
int i = 0; i < networkDim; ++i) {
141 procCoords[i] =
new pcoord_t[this->
numRanks];
142 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
145 pcoord_t *xyz =
new pcoord_t[networkDim];
147 for (
int i = 0; i < networkDim; i++)
148 procCoords[i][this->
myRank] = xyz[i];
153 gatherMachineCoordinates(comm);
155 const Teuchos::ParameterEntry *pe2 =
156 this->pl->getEntryPtr(
"Machine_Optimization_Level");
159 int optimization_level;
160 optimization_level = pe2->getValue<
int>(&optimization_level);
162 if (optimization_level == 1) {
163 is_transformed =
true;
164 this->networkDim = 3;
165 procCoords =
new pcoord_t * [networkDim];
166 for(
int i = 0; i < networkDim; ++i) {
167 procCoords[i] =
new pcoord_t[this->
numRanks] ;
170 for (
int i = 0; i < this->
numRanks; ++i) {
171 procCoords[0][i] = this->actual_procCoords[0][i] * 8;
172 int yordinal = this->actual_procCoords[1][i];
173 procCoords[1][i] = yordinal/2 * (16 + 8) + (yordinal %2) * 8;
174 int zordinal = this->actual_procCoords[2][i];
175 procCoords[2][i] = zordinal * 5 + (zordinal / 8) * 3;
177 int mx = this->machine_extent[0];
178 int my = this->machine_extent[1];
179 int mz = this->machine_extent[2];
182 this->machine_extent =
new int[networkDim];
183 this->machine_extent[0] = mx * 8;
184 this->machine_extent[1] = my/2 * (16 + 8) + (my %2) * 8;
185 this->machine_extent[2] = mz * 5 + (mz / 8) * 3;
187 std::cout <<
"Transforming the coordinates" << std::endl;
190 else if(optimization_level >= 3) {
191 is_transformed =
true;
192 this->networkDim = 6;
193 procCoords =
new pcoord_t * [networkDim];
194 for(
int i = 0; i < networkDim; ++i) {
195 procCoords[i] =
new pcoord_t[this->
numRanks] ;
200 this->machine_extent =
new int[networkDim];
202 this->machine_extent[0] =
203 ceil (
int (this->actual_machine_extent[0]) / 2.0) * 64 ;
204 this->machine_extent[3] = 2 * 8 ;
205 this->machine_extent[1] =
206 ceil(
int (this->actual_machine_extent[1]) / 2.0) * 8 * 2400;
207 this->machine_extent[4] = 2 * 8;
208 this->machine_extent[2] =
209 ceil((
int (this->actual_machine_extent[2])) / 8.0) * 160;
210 this->machine_extent[5] = 8 * 5;
212 for (
int k = 0; k < this->
numRanks ; k++) {
224 procCoords[0][k] = (int (this->actual_procCoords[0][k]) / 2) * 64;
227 procCoords[3][k] = (int (this->actual_procCoords[0][k]) % 2) * 8 ;
234 (int (this->actual_procCoords[1][k]) / 2) * 8 * 2400;
236 procCoords[4][k] = (int (this->actual_procCoords[1][k]) % 2) * 8;
246 ((int (this->actual_procCoords[2][k])) / 8) * 160;
248 procCoords[5][k] = ((int (this->actual_procCoords[2][k])) % 8) * 5;
251 else if(optimization_level == 2) {
253 is_transformed =
true;
254 this->networkDim = 6;
255 procCoords =
new pcoord_t * [networkDim];
256 for(
int i = 0; i < networkDim; ++i) {
257 procCoords[i] =
new pcoord_t[this->
numRanks] ;
262 this->machine_extent =
new int[networkDim];
264 this->machine_extent[0] =
265 ceil(
int (this->actual_machine_extent[0]) / 3.0) * 128 ;
266 this->machine_extent[3] = 3 * 8 ;
267 this->machine_extent[1] =
268 ceil(
int (this->actual_machine_extent[1]) / 2.0) * 8 * 2400;
269 this->machine_extent[4] = 2 * 8;
270 this->machine_extent[2] =
271 ceil((
int (this->actual_machine_extent[2])) / 8.0) * 160;
272 this->machine_extent[5] = 8 * 5;
275 for (
int k = 0; k < this->
numRanks ; k++) {
286 procCoords[0][k] = (int (this->actual_procCoords[0][k]) / 3) * 128;
289 procCoords[3][k] = (int (this->actual_procCoords[0][k]) % 3) * 8 ;
296 (int (this->actual_procCoords[1][k]) / 2) * 8 * 2400;
298 procCoords[4][k] = (int (this->actual_procCoords[1][k]) % 2) * 8;
302 ((int (this->actual_procCoords[2][k])) / 8) * 160;
304 procCoords[5][k] = ((int (this->actual_procCoords[2][k])) % 8) * 5;
311 if (is_transformed) {
312 is_transformed =
false;
313 for (
int i = 0; i < actual_networkDim; i++) {
314 delete [] actual_procCoords[i];
316 delete [] actual_procCoords;
317 delete [] actual_machine_extent;
319 for (
int i = 0; i < networkDim; i++) {
320 delete [] procCoords[i];
322 delete [] procCoords;
323 delete [] machine_extent;
332 if (is_transformed) {
337 nxyz[dim++] = this->machine_extent[0];
338 nxyz[dim++] = this->machine_extent[1];
339 nxyz[dim++] = this->machine_extent[2];
355 for (
int i = 0; i < this->
numRanks; ++i) {
356 std::cout <<
"Rank:" << i
357 <<
" " << procCoords[0][i]
358 <<
" " << procCoords[1][i]
359 <<
" " << procCoords[2][i] << std::endl;
361 std::cout <<
"Machine Extent:"
362 <<
" " << this->machine_extent[0]
363 <<
" " << this->machine_extent[1]
364 <<
" " << this->machine_extent[2] << std::endl;
369 for (
int i = 0; i < this->networkDim; ++i) {
370 xyz[i] = procCoords[i][this->
myRank];
376 xyz[0] = rand() % 25;
377 xyz[1] = rand() % 16;
378 xyz[2] = rand() % 24;
383 pcoord_t *xyz)
const {
384 for (
int i = 0; i < this->networkDim; ++i) {
385 xyz[i] = procCoords[i][rank];
396 allCoords = procCoords;
400 virtual bool getHopCount(
int rank1,
int rank2, pcoord_t &hops)
const override {
402 for (
int i = 0; i < networkDim; ++i) {
403 pcoord_t distance = procCoords[i][rank1] - procCoords[i][rank2];
405 distance = -distance;
406 if (machine_extent[i] - distance < distance)
407 distance = machine_extent[i] - distance;
417 int actual_networkDim;
419 pcoord_t **procCoords;
420 pcoord_t **actual_procCoords;
423 part_t *actual_machine_extent;
427 const Teuchos::ParameterList *pl;
435 void gatherMachineCoordinates(
const Teuchos::Comm<int> &comm) {
437 pcoord_t *tmpVect =
new pcoord_t [this->
numRanks];
439 for (
int i = 0; i < networkDim; i++) {
440 Teuchos::reduceAll<int, pcoord_t>(comm, Teuchos::REDUCE_SUM,
442 procCoords[i], tmpVect);
443 pcoord_t *tmp = tmpVect;
444 tmpVect = procCoords[i];
bool getMachineExtent(int *nxyz) const
virtual bool getHopCount(int rank1, int rank2, pcoord_t &hops) const override
getHopCount function set hops between rank1 and rank2 return true if coordinates are available ...
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 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;.