1 #ifndef _ZOLTAN2_MACHINE_RCALIB_HPP_
2 #define _ZOLTAN2_MACHINE_RCALIB_HPP_
4 #include <Teuchos_Comm.hpp>
5 #include <Teuchos_CommHelpers.hpp>
8 #ifdef HAVE_ZOLTAN2_RCALIB
21 template <
typename pcoord_t,
typename part_t>
31 networkDim(3), actual_networkDim(3),
32 procCoords(NULL), actual_procCoords(NULL),
33 machine_extent(NULL),actual_machine_extent(NULL),
34 is_transformed(false), pl(NULL)
36 actual_machine_extent = machine_extent =
new int[networkDim];
38 actual_machine_extent = machine_extent;
41 actual_procCoords = procCoords =
new pcoord_t *[networkDim];
42 for (
int i = 0; i < networkDim; ++i){
43 procCoords[i] =
new pcoord_t[this->
numRanks];
44 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
48 pcoord_t *xyz =
new pcoord_t[networkDim];
50 for (
int i = 0; i < networkDim; i++)
51 procCoords[i][this->
myRank] = xyz[i];
56 gatherMachineCoordinates(comm);
61 int transformed_network_dim = networkDim;
62 if (dim < transformed_network_dim)
63 wrap_around[dim++] =
true;
64 if (dim < transformed_network_dim)
65 wrap_around[dim++] =
true;
66 if (dim < transformed_network_dim)
67 wrap_around[dim++] =
true;
71 MachineRCA(
const Teuchos::Comm<int> &comm,
const Teuchos::ParameterList &pl_ ):
73 networkDim(3), actual_networkDim(3),
74 procCoords(NULL), actual_procCoords(NULL),
75 machine_extent(NULL),actual_machine_extent(NULL),
76 is_transformed(false), pl(&pl_)
79 actual_machine_extent = machine_extent =
new int[networkDim];
81 actual_machine_extent = machine_extent;
84 actual_procCoords = procCoords =
new pcoord_t *[networkDim];
85 for (
int i = 0; i < networkDim; ++i){
86 procCoords[i] =
new pcoord_t[this->
numRanks];
87 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
90 pcoord_t *xyz =
new pcoord_t[networkDim];
92 for (
int i = 0; i < networkDim; i++)
93 procCoords[i][this->
myRank] = xyz[i];
98 gatherMachineCoordinates(comm);
100 const Teuchos::ParameterEntry *pe2 = this->pl->getEntryPtr(
"Machine_Optimization_Level");
103 int optimization_level;
104 optimization_level = pe2->getValue<
int>(&optimization_level);
106 if (optimization_level == 1){
107 is_transformed =
true;
108 this->networkDim = 3;
109 procCoords =
new pcoord_t * [networkDim];
110 for(
int i = 0; i < networkDim; ++i){
111 procCoords[i] =
new pcoord_t[this->
numRanks] ;
113 for (
int i = 0; i < this->
numRanks; ++i){
114 procCoords[0][i] = this->actual_procCoords[0][i] * 8;
115 int yordinal = this->actual_procCoords[1][i];
116 procCoords[1][i] = yordinal/2 * (16 + 8) + (yordinal %2) * 8;
117 int zordinal = this->actual_procCoords[2][i];
118 procCoords[2][i] = zordinal * 5 + (zordinal / 8) * 3;
120 int mx = this->machine_extent[0];
121 int my = this->machine_extent[1];
122 int mz = this->machine_extent[2];
125 this->machine_extent =
new int[networkDim];
126 this->machine_extent[0] = mx * 8;
127 this->machine_extent[1] = my/2 * (16 + 8) + (my %2) * 8;
128 this->machine_extent[2] = mz * 5 + (mz / 8) * 3;
129 if(this->
myRank == 0) std::cout <<
"Transforming the coordinates" << std::endl;
132 else if(optimization_level >= 3){
133 is_transformed =
true;
134 this->networkDim = 6;
135 procCoords =
new pcoord_t * [networkDim];
136 for(
int i = 0; i < networkDim; ++i){
137 procCoords[i] =
new pcoord_t[this->
numRanks] ;
141 this->machine_extent =
new int[networkDim];
143 this->machine_extent[0] = ceil (
int (this->actual_machine_extent[0]) / 2.0) * 64 ;
144 this->machine_extent[3] = 2 * 8 ;
145 this->machine_extent[1] = ceil(
int (this->actual_machine_extent[1]) / 2.0) * 8 * 2400;
146 this->machine_extent[4] = 2 * 8;
147 this->machine_extent[2] = ceil((
int (this->actual_machine_extent[2])) / 8.0) * 160;
148 this->machine_extent[5] = 8 * 5;
150 for (
int k = 0; k < this->
numRanks ; k++){
161 procCoords[0][k] = (int (this->actual_procCoords[0][k]) / 2) * 64;
163 procCoords[3][k] = (int (this->actual_procCoords[0][k]) % 2) * 8 ;
167 procCoords[1][k] = (int (this->actual_procCoords[1][k]) / 2) * 8 * 2400;
169 procCoords[4][k] = (int (this->actual_procCoords[1][k]) % 2) * 8;
176 procCoords[2][k] = ((int (this->actual_procCoords[2][k])) / 8) * 160;
178 procCoords[5][k] = ((int (this->actual_procCoords[2][k])) % 8) * 5;
181 else if(optimization_level == 2){
183 is_transformed =
true;
184 this->networkDim = 6;
185 procCoords =
new pcoord_t * [networkDim];
186 for(
int i = 0; i < networkDim; ++i){
187 procCoords[i] =
new pcoord_t[this->
numRanks] ;
191 this->machine_extent =
new int[networkDim];
193 this->machine_extent[0] = ceil(
int (this->actual_machine_extent[0]) / 3.0) * 128 ;
194 this->machine_extent[3] = 3 * 8 ;
195 this->machine_extent[1] = ceil(
int (this->actual_machine_extent[1]) / 2.0) * 8 * 2400;
196 this->machine_extent[4] = 2 * 8;
197 this->machine_extent[2] = ceil((
int (this->actual_machine_extent[2])) / 8.0) * 160;
198 this->machine_extent[5] = 8 * 5;
201 for (
int k = 0; k < this->
numRanks ; k++){
211 procCoords[0][k] = (int (this->actual_procCoords[0][k]) / 3) * 128;
213 procCoords[3][k] = (int (this->actual_procCoords[0][k]) % 3) * 8 ;
217 procCoords[1][k] = (int (this->actual_procCoords[1][k]) / 2) * 8 * 2400;
219 procCoords[4][k] = (int (this->actual_procCoords[1][k]) % 2) * 8;
222 procCoords[2][k] = ((int (this->actual_procCoords[2][k])) / 8) * 160;
224 procCoords[5][k] = ((int (this->actual_procCoords[2][k])) % 8) * 5;
235 is_transformed =
false;
236 for (
int i = 0; i < actual_networkDim; i++){
237 delete [] actual_procCoords[i];
239 delete [] actual_procCoords;
240 delete [] actual_machine_extent;
242 for (
int i = 0; i < networkDim; i++){
243 delete [] procCoords[i];
245 delete [] procCoords;
246 delete [] machine_extent;
260 nxyz[dim++] = this->machine_extent[0];
261 nxyz[dim++] = this->machine_extent[1];
262 nxyz[dim++] = this->machine_extent[2];
268 #if defined (HAVE_ZOLTAN2_RCALIB)
270 rca_get_max_dimension(&mxyz);
272 nxyz[dim++] = mxyz.mesh_x + 1;
273 nxyz[dim++] = mxyz.mesh_y + 1;
274 nxyz[dim++] = mxyz.mesh_z + 1;
284 for (
int i = 0; i < this->
numRanks; ++i){
285 std::cout <<
"Rank:" << i <<
" " << procCoords[0][i] <<
" " << procCoords[1][i] <<
" " << procCoords[2][i] << std::endl;
287 std::cout <<
"Machine Extent:" <<
" " << this->machine_extent[0] <<
" " << this->machine_extent[1] <<
" " << this->machine_extent[2] << std::endl;
292 for (
int i = 0; i < this->networkDim; ++i){
293 xyz[i] = procCoords[i][this->
myRank];
299 #if defined (HAVE_ZOLTAN2_RCALIB)
301 rca_get_nodeid(&nodeInfo);
302 int NIDs = (int)nodeInfo.rs_node_s._node_id;
304 mesh_coord_t node_coord;
305 int returnval = rca_get_meshcoord((uint16_t)NIDs, &node_coord);
306 if (returnval == -1){
309 xyz[0] = node_coord.mesh_x;
310 xyz[1] = node_coord.mesh_y;
311 xyz[2] = node_coord.mesh_z;
319 pcoord_t *xyz)
const {
320 for (
int i = 0; i < this->networkDim; ++i){
321 xyz[i] = procCoords[i][rank];
332 allCoords = procCoords;
338 for (
int i = 0; i < networkDim; ++i){
339 pcoord_t distance = procCoords[i][rank1] - procCoords[i][rank2];
340 if (distance < 0 ) distance = -distance;
341 if (machine_extent[i] - distance < distance) distance = machine_extent[i] - distance;
351 int actual_networkDim;
353 pcoord_t **procCoords;
354 pcoord_t **actual_procCoords;
357 part_t *actual_machine_extent;
361 const Teuchos::ParameterList *pl;
369 void gatherMachineCoordinates(
const Teuchos::Comm<int> &comm) {
371 pcoord_t *tmpVect =
new pcoord_t [this->
numRanks];
373 for (
int i = 0; i < networkDim; i++) {
374 Teuchos::reduceAll<int, pcoord_t>(comm, Teuchos::REDUCE_SUM,
375 this->
numRanks, procCoords[i], tmpVect);
376 pcoord_t *tmp = tmpVect;
377 tmpVect = procCoords[i];
bool getMachineExtent(int *nxyz) const
A Machine Class for testing only A more realistic machine should be used for task mapping...
bool getRealMachineExtent(int *nxyz) const
virtual bool getHopCount(int rank1, int rank2, pcoord_t &hops)
MachineRCA(const Teuchos::Comm< int > &comm, const Teuchos::ParameterList &pl_)
MachineClass Base class for representing machine coordinates, networks, etc.
bool getMachineCoordinate(const int rank, pcoord_t *xyz) const
bool getMyActualMachineCoordinate(pcoord_t *xyz)
MachineRCA(const Teuchos::Comm< int > &comm)
Constructor: A BlueGeneQ network machine description;.
bool getAllMachineCoordinatesView(pcoord_t **&allCoords) const
SparseMatrixAdapter_t::part_t part_t
bool getMachineCoordinate(const char *nodename, pcoord_t *xyz)
int getRealMachineDim() const
bool getMyMachineCoordinate(pcoord_t *xyz)
virtual bool getMachineExtentWrapArounds(bool *wrap_around) const
int getMachineDim() const
bool hasMachineCoordinates() const