1 #ifndef _ZOLTAN2_MACHINE_TORUS_RCALIB_HPP_
2 #define _ZOLTAN2_MACHINE_TORUS_RCALIB_HPP_
4 #include <Teuchos_Comm.hpp>
5 #include <Teuchos_CommHelpers.hpp>
8 #ifdef HAVE_ZOLTAN2_RCALIB
20 template <
typename pcoord_t,
typename part_t>
33 actual_procCoords(NULL),
35 actual_machine_extent(NULL),
36 is_transformed(false),
39 actual_machine_extent = machine_extent =
new int[networkDim];
41 actual_machine_extent = machine_extent;
44 actual_procCoords = procCoords =
new pcoord_t *[networkDim];
45 for (
int i = 0; i < networkDim; ++i) {
46 procCoords[i] =
new pcoord_t[this->
numRanks];
47 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
51 pcoord_t *xyz =
new pcoord_t[networkDim];
53 for (
int i = 0; i < networkDim; i++)
54 procCoords[i][this->
myRank] = xyz[i];
58 gatherMachineCoordinates(comm);
63 int transformed_network_dim = networkDim;
64 if (dim < transformed_network_dim)
65 wrap_around[dim++] =
true;
66 if (dim < transformed_network_dim)
67 wrap_around[dim++] =
true;
68 if (dim < transformed_network_dim)
69 wrap_around[dim++] =
true;
74 const Teuchos::ParameterList &pl_):
79 actual_procCoords(NULL),
81 actual_machine_extent(NULL),
82 is_transformed(false),
85 actual_machine_extent = machine_extent =
new int[networkDim];
87 actual_machine_extent = machine_extent;
90 actual_procCoords = procCoords =
new pcoord_t *[networkDim];
91 for (
int i = 0; i < networkDim; ++i) {
92 procCoords[i] =
new pcoord_t[this->
numRanks];
93 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
96 pcoord_t *xyz =
new pcoord_t[networkDim];
98 for (
int i = 0; i < networkDim; i++)
99 procCoords[i][this->
myRank] = xyz[i];
104 gatherMachineCoordinates(comm);
106 const Teuchos::ParameterEntry *pe2 =
107 this->pl->getEntryPtr(
"Machine_Optimization_Level");
111 int optimization_level;
112 optimization_level = pe2->getValue<
int>(&optimization_level);
114 if (optimization_level == 1) {
115 is_transformed =
true;
116 this->networkDim = 3;
117 procCoords =
new pcoord_t * [networkDim];
118 for(
int i = 0; i < networkDim; ++i) {
119 procCoords[i] =
new pcoord_t[this->
numRanks] ;
122 for (
int i = 0; i < this->
numRanks; ++i) {
123 procCoords[0][i] = this->actual_procCoords[0][i] * 8;
124 int yordinal = this->actual_procCoords[1][i];
125 procCoords[1][i] = yordinal/2 * (16 + 8) + (yordinal %2) * 8;
126 int zordinal = this->actual_procCoords[2][i];
127 procCoords[2][i] = zordinal * 5 + (zordinal / 8) * 3;
129 int mx = this->machine_extent[0];
130 int my = this->machine_extent[1];
131 int mz = this->machine_extent[2];
134 this->machine_extent =
new int[networkDim];
135 this->machine_extent[0] = mx * 8;
136 this->machine_extent[1] = my/2 * (16 + 8) + (my %2) * 8;
137 this->machine_extent[2] = mz * 5 + (mz / 8) * 3;
139 std::cout <<
"Transforming the coordinates" << std::endl;
142 else if(optimization_level >= 3) {
143 is_transformed =
true;
144 this->networkDim = 6;
145 procCoords =
new pcoord_t * [networkDim];
146 for(
int i = 0; i < networkDim; ++i) {
147 procCoords[i] =
new pcoord_t[this->
numRanks] ;
152 this->machine_extent =
new int[networkDim];
154 this->machine_extent[0] =
155 ceil (
int (this->actual_machine_extent[0]) / 2.0) * 64 ;
156 this->machine_extent[3] = 2 * 8 ;
157 this->machine_extent[1] =
158 ceil(
int (this->actual_machine_extent[1]) / 2.0) * 8 * 2400;
159 this->machine_extent[4] = 2 * 8;
160 this->machine_extent[2] =
161 ceil((
int (this->actual_machine_extent[2])) / 8.0) * 160;
162 this->machine_extent[5] = 8 * 5;
164 for (
int k = 0; k < this->
numRanks ; k++) {
176 procCoords[0][k] = (int (this->actual_procCoords[0][k]) / 2) * 64;
179 procCoords[3][k] = (int (this->actual_procCoords[0][k]) % 2) * 8 ;
186 (int (this->actual_procCoords[1][k]) / 2) * 8 * 2400;
188 procCoords[4][k] = (int (this->actual_procCoords[1][k]) % 2) * 8;
199 ((int (this->actual_procCoords[2][k])) / 8) * 160;
202 ((int (this->actual_procCoords[2][k])) % 8) * 5;
205 else if(optimization_level == 2) {
207 is_transformed =
true;
208 this->networkDim = 6;
209 procCoords =
new pcoord_t * [networkDim];
210 for(
int i = 0; i < networkDim; ++i) {
211 procCoords[i] =
new pcoord_t[this->
numRanks] ;
216 this->machine_extent =
new int[networkDim];
218 this->machine_extent[0] =
219 ceil(
int (this->actual_machine_extent[0]) / 3.0) * 128 ;
220 this->machine_extent[3] = 3 * 8 ;
221 this->machine_extent[1] =
222 ceil(
int (this->actual_machine_extent[1]) / 2.0) * 8 * 2400;
223 this->machine_extent[4] = 2 * 8;
224 this->machine_extent[2] =
225 ceil((
int (this->actual_machine_extent[2])) / 8.0) * 160;
226 this->machine_extent[5] = 8 * 5;
229 for (
int k = 0; k < this->
numRanks ; k++) {
240 procCoords[0][k] = (int (this->actual_procCoords[0][k]) / 3) * 128;
243 procCoords[3][k] = (int (this->actual_procCoords[0][k]) % 3) * 8 ;
250 (int (this->actual_procCoords[1][k]) / 2) * 8 * 2400;
252 procCoords[4][k] = (int (this->actual_procCoords[1][k]) % 2) * 8;
256 ((int (this->actual_procCoords[2][k])) / 8) * 160;
258 procCoords[5][k] = ((int (this->actual_procCoords[2][k])) % 8) * 5;
268 if (is_transformed) {
269 is_transformed =
false;
270 for (
int i = 0; i < actual_networkDim; i++) {
271 delete [] actual_procCoords[i];
273 delete [] actual_procCoords;
274 delete [] actual_machine_extent;
276 for (
int i = 0; i < networkDim; i++) {
277 delete [] procCoords[i];
279 delete [] procCoords;
280 delete [] machine_extent;
289 if (is_transformed) {
294 nxyz[dim++] = this->machine_extent[0];
295 nxyz[dim++] = this->machine_extent[1];
296 nxyz[dim++] = this->machine_extent[2];
302 #if defined (HAVE_ZOLTAN2_RCALIB)
304 rca_get_max_dimension(&mxyz);
306 nxyz[dim++] = mxyz.mesh_x + 1;
307 nxyz[dim++] = mxyz.mesh_y + 1;
308 nxyz[dim++] = mxyz.mesh_z + 1;
318 for (
int i = 0; i < this->
numRanks; ++i) {
319 std::cout <<
"Rank:" << i
320 <<
" " << procCoords[0][i]
321 <<
" " << procCoords[1][i]
322 <<
" " << procCoords[2][i] << std::endl;
324 std::cout <<
"Machine Extent:"
325 <<
" " << this->machine_extent[0]
326 <<
" " << this->machine_extent[1]
327 <<
" " << this->machine_extent[2] << std::endl;
332 for (
int i = 0; i < this->networkDim; ++i) {
333 xyz[i] = procCoords[i][this->
myRank];
339 #if defined (HAVE_ZOLTAN2_RCALIB)
341 rca_get_nodeid(&nodeInfo);
342 int NIDs = (int)nodeInfo.rs_node_s._node_id;
344 mesh_coord_t node_coord;
345 int returnval = rca_get_meshcoord((uint16_t)NIDs, &node_coord);
346 if (returnval == -1) {
349 xyz[0] = node_coord.mesh_x;
350 xyz[1] = node_coord.mesh_y;
351 xyz[2] = node_coord.mesh_z;
359 pcoord_t *xyz)
const {
360 for (
int i = 0; i < this->networkDim; ++i) {
361 xyz[i] = procCoords[i][rank];
372 allCoords = procCoords;
378 for (
int i = 0; i < networkDim; ++i) {
379 pcoord_t distance = procCoords[i][rank1] - procCoords[i][rank2];
381 distance = -distance;
382 if (machine_extent[i] - distance < distance)
383 distance = machine_extent[i] - distance;
393 int actual_networkDim;
395 pcoord_t **procCoords;
396 pcoord_t **actual_procCoords;
399 part_t *actual_machine_extent;
403 const Teuchos::ParameterList *pl;
411 void gatherMachineCoordinates(
const Teuchos::Comm<int> &comm) {
413 pcoord_t *tmpVect =
new pcoord_t [this->
numRanks];
415 for (
int i = 0; i < networkDim; i++) {
416 Teuchos::reduceAll<int, pcoord_t>(comm, Teuchos::REDUCE_SUM,
418 procCoords[i], tmpVect);
419 pcoord_t *tmp = tmpVect;
420 tmpVect = procCoords[i];
int getRealMachineDim() const
bool getRealMachineExtent(int *nxyz) const
MachineTorusRCA(const Teuchos::Comm< int > &comm, const Teuchos::ParameterList &pl_)
MachineClass Base class for representing machine coordinates, networks, etc.
bool getAllMachineCoordinatesView(pcoord_t **&allCoords) const
bool getMachineCoordinate(const int rank, pcoord_t *xyz) const
MachineTorusRCA(const Teuchos::Comm< int > &comm)
Constructor: A BlueGeneQ network machine description;.
bool getMachineExtent(int *nxyz) const
SparseMatrixAdapter_t::part_t part_t
bool getMyMachineCoordinate(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
bool getMachineCoordinate(const char *nodename, pcoord_t *xyz)
int getMachineDim() const
virtual ~MachineTorusRCA()
An RCA Machine class on Torus Networks.
bool hasMachineCoordinates() const
bool getMyActualMachineCoordinate(pcoord_t *xyz)