/usr/include/trilinos/Zoltan2_MachineRepresentation.hpp is in libtrilinos-zoltan2-dev 12.4.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | #ifndef _ZOLTAN2_MACHINEREPRESENTATION_HPP_
#define _ZOLTAN2_MACHINEREPRESENTATION_HPP_
#include <Teuchos_Comm.hpp>
#include <Teuchos_CommHelpers.hpp>
namespace Zoltan2{
/*! \brief MachineRepresentation Class
* Finds the coordinate of the processor.
* Used to find the processor coordinates or graph.
*/
template <typename pcoord_t>
class MachineRepresentation{
private:
int networkDim;
int numProcs;
pcoord_t **procCoords;
const RCP<const Comm<int> > comm;
public:
/*! \brief Constructor MachineRepresentation Class
* \param comm_ Communication object.
*/
MachineRepresentation(const RCP<const Comm<int> > &comm_):
networkDim(0), numProcs(comm_->getSize()), procCoords(0), comm(comm_){
// WIll need this constructor to be specific to RAAMP (MD).
// Will need a default constructor using, e.g., GeometricGenerator
// or nothing at all, for when RAAMP is not available as TPL.
//
// (AG) In addition, need to be able to run without special
// privileges in system (e.g., on hopper).
// Notes: For now, all cores connected to same NIC will get the
// same coordinates; later, we could add extra coordinate dimensions
// to represent nodes or dies (using hwloc info through RAAMP
// data object).
// (MD) will modify mapping test to use machine representation
// #ifdef HAVE_ZOLTAN2_OVIS
// Call initializer for RAAMP data object (AG)
//get network dimension.
//TODO change.
// Call RAAMP Data Object to get the network dimension (AG)
networkDim = 3;
//allocate memory for processor coordinates.
procCoords = new pcoord_t *[networkDim];
for (int i = 0; i < networkDim; ++i){
procCoords[i] = new pcoord_t [numProcs];
memset (procCoords[i], 0, sizeof(pcoord_t) * numProcs);
}
//obtain the coordinate of the processor.
this->getMyCoordinate(/*pcoord_t &xyz[networkDim]*/);
// copy xyz into appropriate spot in procCoords. (MD)
//reduceAll the coordinates of each processor.
this->gatherMachineCoordinates();
}
/*! \brief Constructor MachineRepresentation Class
* \param comm_ Communication object.
*/
MachineRepresentation(const RCP<Comm<int> > &comm_):
networkDim(0), numProcs(comm_->getSize()), procCoords(0), comm(comm_){
// WIll need this constructor to be specific to RAAMP (MD).
// Will need a default constructor using, e.g., GeometricGenerator
// or nothing at all, for when RAAMP is not available as TPL.
//
// (AG) In addition, need to be able to run without special
// privileges in system (e.g., on hopper).
// Notes: For now, all cores connected to same NIC will get the
// same coordinates; later, we could add extra coordinate dimensions
// to represent nodes or dies (using hwloc info through RAAMP
// data object).
// (MD) will modify mapping test to use machine representation
// #ifdef HAVE_ZOLTAN2_OVIS
// Call initializer for RAAMP data object (AG)
//get network dimension.
//TODO change.
// Call RAAMP Data Object to get the network dimension (AG)
networkDim = 3;
//allocate memory for processor coordinates.
procCoords = new pcoord_t *[networkDim];
for (int i = 0; i < networkDim; ++i){
procCoords[i] = new pcoord_t [numProcs];
memset (procCoords[i], 0, sizeof(pcoord_t) * numProcs);
}
//obtain the coordinate of the processor.
this->getMyCoordinate(/*pcoord_t &xyz[networkDim]*/);
// copy xyz into appropriate spot in procCoords. (MD)
//reduceAll the coordinates of each processor.
this->gatherMachineCoordinates();
}
/*! \brief getMyCoordinate function
* stores the coordinate of the current processor in procCoords[*][rank]
*/
void getMyCoordinate(/* pcoord_t &xyz[networkDim]*/){
// Call RAAMP system to get coordinates and store in xyz (MD)
// What is the RAAMP call? (AG)
// AG will return a view (pointer) to RAAMP's data.
// We will copy it into xyz.
// The code below may be good for the default constructor, perhaps,
// but it should copy the data into xyz instead of the procCoords.
int myRank = comm->getRank();
int slice = int (pow( double(numProcs), double(1.0 / networkDim)) + 0.5 );
int m = myRank;
for (int i = 0; i < networkDim; ++i){
procCoords[i][myRank] = m / int(pow(slice, double(networkDim - i - 1)));
m = m % int(pow(double(slice), double(networkDim - i - 1)));
}
}
/*! \brief gatherMachineCoordinates function
* reduces and stores all machine coordinates.
*/
void gatherMachineCoordinates(){
pcoord_t *tmpVect = new pcoord_t [numProcs];
for (int i = 0; i < networkDim; ++i){
reduceAll<int, pcoord_t>(
*comm,
Teuchos::REDUCE_SUM,
numProcs,
procCoords[i],
tmpVect);
pcoord_t *tmp = tmpVect;
tmpVect = procCoords[i];
procCoords[i] = tmp;
}
delete [] tmpVect;
}
/*! \brief destructor of the class
* free memory in procCoords.
*/
~MachineRepresentation() {
for (int i = 0; i < networkDim; ++i){
delete [] procCoords[i];
}
delete []procCoords;
// Free/release THE RAAMP Data Object.
// Deinitialize/finalize/whatever (AG)
}
/*! \brief getProcDim function
* returns the dimension of the physical processor layout.
*/
int getProcDim() const{
return networkDim;
}
/*! \brief getProcDim function
* returns the coordinates of processors in two dimensional array.
*/
pcoord_t** getProcCoords() const{
return procCoords;
}
/*! \brief getNumProcs function
* returns the number of processors.
*/
int getNumProcs() const{
return numProcs;
}
};
}
#endif
|