1 #ifndef _ZOLTAN2_MACHINE_RCALIBTEST_HPP_
2 #define _ZOLTAN2_MACHINE_RCALIBTEST_HPP_
4 #include <Teuchos_Comm.hpp>
5 #include <Teuchos_CommHelpers.hpp>
17 template <
typename pcoord_t,
typename part_t>
27 networkDim(3), actual_networkDim(3),
28 procCoords(NULL), actual_procCoords(NULL),
29 machine_extent(NULL),actual_machine_extent(NULL),
30 is_transformed(false), pl(NULL)
32 actual_machine_extent = machine_extent =
new int[networkDim];
34 actual_machine_extent = machine_extent;
37 actual_procCoords = procCoords =
new pcoord_t *[networkDim];
38 for (
int i = 0; i < networkDim; ++i){
39 procCoords[i] =
new pcoord_t[this->
numRanks];
40 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
44 pcoord_t *xyz =
new pcoord_t[networkDim];
46 for (
int i = 0; i < networkDim; i++)
47 procCoords[i][this->
myRank] = xyz[i];
52 gatherMachineCoordinates(comm);
57 int transformed_network_dim = networkDim;
58 if (dim < transformed_network_dim)
59 wrap_around[dim++] =
true;
60 if (dim < transformed_network_dim)
61 wrap_around[dim++] =
true;
62 if (dim < transformed_network_dim)
63 wrap_around[dim++] =
true;
67 MachineRCATest(
const Teuchos::Comm<int> &comm,
const Teuchos::ParameterList &pl_ ):
69 networkDim(3), actual_networkDim(3),
70 procCoords(NULL), actual_procCoords(NULL),
71 machine_extent(NULL),actual_machine_extent(NULL),
72 is_transformed(false), pl(&pl_)
75 actual_machine_extent = machine_extent =
new int[networkDim];
77 actual_machine_extent = machine_extent;
80 actual_procCoords = procCoords =
new pcoord_t *[networkDim];
83 const Teuchos::ParameterEntry *pe1 = this->pl->getEntryPtr(
"Input_RCA_Machine_Coords");
85 std::string input_coord_file;
86 input_coord_file = pe1->getValue<std::string>(&input_coord_file);
87 if (input_coord_file !=
""){
90 std::vector < std::vector <pcoord_t> > proc_coords(networkDim);
91 std::fstream machine_coord_file(input_coord_file.c_str());
95 machine_coord_file >> a >> b >> c;
96 while(!machine_coord_file.eof()){
97 proc_coords[0].push_back(a);
98 proc_coords[1].push_back(b);
99 proc_coords[2].push_back(c);
101 machine_coord_file >> a >> b >> c;
104 machine_coord_file.close();
105 std::cout <<
"Rewriting numprocs from:" << this->
numRanks <<
" to:" << i << std::endl;
108 for(
int ii = 0; ii < networkDim; ++ii){
109 procCoords[ii] =
new pcoord_t[this->
numRanks];
110 for (
int j = 0; j < this->
numRanks; ++j){
111 procCoords[ii][j] = proc_coords[ii][j];
115 comm.broadcast(0,
sizeof(
int), (
char *) &(this->
numRanks));
118 for (
int i = 0; i < networkDim; ++i){
119 procCoords[i] =
new pcoord_t[this->
numRanks];
120 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
126 for (
int i = 0; i < networkDim; ++i){
127 procCoords[i] =
new pcoord_t[this->
numRanks];
128 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
131 pcoord_t *xyz =
new pcoord_t[networkDim];
133 for (
int i = 0; i < networkDim; i++)
134 procCoords[i][this->
myRank] = xyz[i];
139 gatherMachineCoordinates(comm);
141 const Teuchos::ParameterEntry *pe2 = this->pl->getEntryPtr(
"Machine_Optimization_Level");
144 int optimization_level;
145 optimization_level = pe2->getValue<
int>(&optimization_level);
147 if (optimization_level == 1){
148 is_transformed =
true;
149 this->networkDim = 3;
150 procCoords =
new pcoord_t * [networkDim];
151 for(
int i = 0; i < networkDim; ++i){
152 procCoords[i] =
new pcoord_t[this->
numRanks] ;
154 for (
int i = 0; i < this->
numRanks; ++i){
155 procCoords[0][i] = this->actual_procCoords[0][i] * 8;
156 int yordinal = this->actual_procCoords[1][i];
157 procCoords[1][i] = yordinal/2 * (16 + 8) + (yordinal %2) * 8;
158 int zordinal = this->actual_procCoords[2][i];
159 procCoords[2][i] = zordinal * 5 + (zordinal / 8) * 3;
161 int mx = this->machine_extent[0];
162 int my = this->machine_extent[1];
163 int mz = this->machine_extent[2];
166 this->machine_extent =
new int[networkDim];
167 this->machine_extent[0] = mx * 8;
168 this->machine_extent[1] = my/2 * (16 + 8) + (my %2) * 8;
169 this->machine_extent[2] = mz * 5 + (mz / 8) * 3;
170 if(this->
myRank == 0) std::cout <<
"Transforming the coordinates" << std::endl;
173 else if(optimization_level >= 3){
174 is_transformed =
true;
175 this->networkDim = 6;
176 procCoords =
new pcoord_t * [networkDim];
177 for(
int i = 0; i < networkDim; ++i){
178 procCoords[i] =
new pcoord_t[this->
numRanks] ;
182 this->machine_extent =
new int[networkDim];
184 this->machine_extent[0] = ceil (
int (this->actual_machine_extent[0]) / 2.0) * 64 ;
185 this->machine_extent[3] = 2 * 8 ;
186 this->machine_extent[1] = ceil(
int (this->actual_machine_extent[1]) / 2.0) * 8 * 2400;
187 this->machine_extent[4] = 2 * 8;
188 this->machine_extent[2] = ceil((
int (this->actual_machine_extent[2])) / 8.0) * 160;
189 this->machine_extent[5] = 8 * 5;
191 for (
int k = 0; k < this->
numRanks ; k++){
202 procCoords[0][k] = (int (this->actual_procCoords[0][k]) / 2) * 64;
204 procCoords[3][k] = (int (this->actual_procCoords[0][k]) % 2) * 8 ;
208 procCoords[1][k] = (int (this->actual_procCoords[1][k]) / 2) * 8 * 2400;
210 procCoords[4][k] = (int (this->actual_procCoords[1][k]) % 2) * 8;
217 procCoords[2][k] = ((int (this->actual_procCoords[2][k])) / 8) * 160;
219 procCoords[5][k] = ((int (this->actual_procCoords[2][k])) % 8) * 5;
222 else if(optimization_level == 2){
224 is_transformed =
true;
225 this->networkDim = 6;
226 procCoords =
new pcoord_t * [networkDim];
227 for(
int i = 0; i < networkDim; ++i){
228 procCoords[i] =
new pcoord_t[this->
numRanks] ;
232 this->machine_extent =
new int[networkDim];
234 this->machine_extent[0] = ceil(
int (this->actual_machine_extent[0]) / 3.0) * 128 ;
235 this->machine_extent[3] = 3 * 8 ;
236 this->machine_extent[1] = ceil(
int (this->actual_machine_extent[1]) / 2.0) * 8 * 2400;
237 this->machine_extent[4] = 2 * 8;
238 this->machine_extent[2] = ceil((
int (this->actual_machine_extent[2])) / 8.0) * 160;
239 this->machine_extent[5] = 8 * 5;
242 for (
int k = 0; k < this->
numRanks ; k++){
252 procCoords[0][k] = (int (this->actual_procCoords[0][k]) / 3) * 128;
254 procCoords[3][k] = (int (this->actual_procCoords[0][k]) % 3) * 8 ;
258 procCoords[1][k] = (int (this->actual_procCoords[1][k]) / 2) * 8 * 2400;
260 procCoords[4][k] = (int (this->actual_procCoords[1][k]) % 2) * 8;
263 procCoords[2][k] = ((int (this->actual_procCoords[2][k])) / 8) * 160;
265 procCoords[5][k] = ((int (this->actual_procCoords[2][k])) % 8) * 5;
276 is_transformed =
false;
277 for (
int i = 0; i < actual_networkDim; i++){
278 delete [] actual_procCoords[i];
280 delete [] actual_procCoords;
281 delete [] actual_machine_extent;
283 for (
int i = 0; i < networkDim; i++){
284 delete [] procCoords[i];
286 delete [] procCoords;
287 delete [] machine_extent;
301 nxyz[dim++] = this->machine_extent[0];
302 nxyz[dim++] = this->machine_extent[1];
303 nxyz[dim++] = this->machine_extent[2];
319 for (
int i = 0; i < this->
numRanks; ++i){
320 std::cout <<
"Rank:" << i <<
" " << procCoords[0][i] <<
" " << procCoords[1][i] <<
" " << procCoords[2][i] << std::endl;
322 std::cout <<
"Machine Extent:" <<
" " << this->machine_extent[0] <<
" " << this->machine_extent[1] <<
" " << this->machine_extent[2] << std::endl;
327 for (
int i = 0; i < this->networkDim; ++i){
328 xyz[i] = procCoords[i][this->
myRank];
334 xyz[0] = rand() % 25;
335 xyz[1] = rand() % 16;
336 xyz[2] = rand() % 24;
341 pcoord_t *xyz)
const {
342 for (
int i = 0; i < this->networkDim; ++i){
343 xyz[i] = procCoords[i][rank];
354 allCoords = procCoords;
360 for (
int i = 0; i < networkDim; ++i){
361 pcoord_t distance = procCoords[i][rank1] - procCoords[i][rank2];
362 if (distance < 0 ) distance = -distance;
363 if (machine_extent[i] - distance < distance) distance = machine_extent[i] - distance;
373 int actual_networkDim;
375 pcoord_t **procCoords;
376 pcoord_t **actual_procCoords;
379 part_t *actual_machine_extent;
383 const Teuchos::ParameterList *pl;
391 void gatherMachineCoordinates(
const Teuchos::Comm<int> &comm) {
393 pcoord_t *tmpVect =
new pcoord_t [this->
numRanks];
395 for (
int i = 0; i < networkDim; i++) {
396 Teuchos::reduceAll<int, pcoord_t>(comm, Teuchos::REDUCE_SUM,
397 this->
numRanks, procCoords[i], tmpVect);
398 pcoord_t *tmp = tmpVect;
399 tmpVect = procCoords[i];
bool getMachineCoordinate(const int rank, pcoord_t *xyz) const
bool getMyMachineCoordinate(pcoord_t *xyz)
bool getMachineExtent(int *nxyz) const
bool getAllMachineCoordinatesView(pcoord_t **&allCoords) const
virtual ~MachineRCATest()
int getMachineDim() const
A Machine Class for testing only A more realistic machine should be used for task mapping...
MachineClass Base class for representing machine coordinates, networks, etc.
bool getMyActualMachineCoordinate(pcoord_t *xyz)
virtual bool getMachineExtentWrapArounds(bool *wrap_around) const
MachineRCATest(const Teuchos::Comm< int > &comm)
Constructor: A BlueGeneQ network machine description;.
SparseMatrixAdapter_t::part_t part_t
bool getMachineCoordinate(const char *nodename, pcoord_t *xyz)
int getRealMachineDim() const
virtual bool getHopCount(int rank1, int rank2, pcoord_t &hops)
bool hasMachineCoordinates() const
bool getRealMachineExtent(int *nxyz) const
MachineRCATest(const Teuchos::Comm< int > &comm, const Teuchos::ParameterList &pl_)