Zoltan2
Toggle main menu visibility
Loading...
Searching...
No Matches
Zoltan2_MachineForTesting.hpp
Go to the documentation of this file.
1
#ifndef _ZOLTAN2_MACHINEFORTESTING_HPP_
2
#define _ZOLTAN2_MACHINEFORTESTING_HPP_
3
4
#include <Teuchos_Comm.hpp>
5
#include <Teuchos_CommHelpers.hpp>
6
#include <
Zoltan2_Machine.hpp
>
7
8
namespace
Zoltan2
{
9
13
14
template
<
typename
pcoord_t,
typename
part_t>
15
class
MachineForTesting
:
public
Machine
<pcoord_t, part_t> {
16
17
public
:
22
23
MachineForTesting
(
const
Teuchos::Comm<int> &comm):
24
Machine
<pcoord_t,
part_t
>(comm),
25
networkDim(3),
26
procCoords(NULL)
27
{
28
//allocate memory for processor coordinates.
29
procCoords =
new
pcoord_t *[networkDim];
30
for
(
int
i = 0; i < networkDim; ++i){
31
procCoords[i] =
new
pcoord_t[this->
numRanks
];
32
memset(procCoords[i], 0,
sizeof
(pcoord_t) * this->
numRanks
);
33
}
34
35
//obtain the coordinate of the processor.
36
pcoord_t *xyz =
new
pcoord_t[networkDim];
37
getMyMachineCoordinate
(xyz);
38
for
(
int
i = 0; i < networkDim; i++)
39
procCoords[i][this->
myRank
] = xyz[i];
40
delete
[] xyz;
41
42
//reduceAll the coordinates of each processor.
43
gatherMachineCoordinates(comm);
44
}
45
46
MachineForTesting
(
const
Teuchos::Comm<int> &comm,
const
Teuchos::ParameterList &pl):
47
Machine
<pcoord_t,
part_t
>(comm),
48
networkDim(3),
49
procCoords(NULL)
50
{
51
//allocate memory for processor coordinates.
52
procCoords =
new
pcoord_t *[networkDim];
53
for
(
int
i = 0; i < networkDim; ++i){
54
procCoords[i] =
new
pcoord_t[this->
numRanks
];
55
memset(procCoords[i], 0,
sizeof
(pcoord_t) * this->
numRanks
);
56
}
57
58
//obtain the coordinate of the processor.
59
pcoord_t *xyz =
new
pcoord_t[networkDim];
60
getMyMachineCoordinate
(xyz);
61
for
(
int
i = 0; i < networkDim; i++)
62
procCoords[i][this->
myRank
] = xyz[i];
63
delete
[] xyz;
64
65
//reduceAll the coordinates of each processor.
66
gatherMachineCoordinates(comm);
67
}
68
69
virtual
~MachineForTesting
() {
70
for
(
int
i = 0; i < networkDim; i++){
71
delete
[] procCoords[i];
72
}
73
delete
[] procCoords;
74
}
75
76
bool
hasMachineCoordinates
()
const
{
return
true
; }
77
78
int
getMachineDim
()
const
{
return
networkDim; }
79
80
bool
getMachineExtent
(
int
*nxyz)
const
{
81
// Ficticious machine extent
82
nxyz[0] = this->
numRanks
;
83
nxyz[1] = 2*this->
numRanks
;
84
nxyz[2] = 3*this->
numRanks
;
85
return
true
;
86
}
87
88
bool
getMyMachineCoordinate
(pcoord_t *xyz) {
89
return
getMachineCoordinate
(this->
myRank
, xyz);
90
}
91
92
bool
getMachineCoordinate
(
const
int
rank, pcoord_t *xyz) {
93
// Ficticious machine coordinates
94
// part_t slice = part_t(pow(double(this->numRanks), double(1.0/networkDim))
95
// + 0.5);
96
// part_t m = rank;
97
// for (int i = 0; i < networkDim; ++i){
98
// xyz[i] = m / part_t(pow(slice, double(networkDim - i - 1)));
99
// m = m % part_t(pow(double(slice), double(networkDim - i - 1)));
100
// }
101
102
xyz[0] = rank;
103
xyz[1] = this->
numRanks
;
104
xyz[2] = this->
numRanks
+1;
105
return
true
;
106
}
107
108
bool
getMachineCoordinate
(
const
char
*nodename, pcoord_t *xyz) {
109
return
false
;
// cannot yet return from nodename
110
}
111
112
bool
getAllMachineCoordinatesView
(pcoord_t **&allCoords)
const
{
113
allCoords = procCoords;
114
return
true
;
115
}
116
117
private
:
118
119
int
networkDim;
120
121
pcoord_t **procCoords;
// KDD Maybe should be RCP?
122
123
void
gatherMachineCoordinates(
const
Teuchos::Comm<int> &comm) {
124
// reduces and stores all machine coordinates.
125
pcoord_t *tmpVect =
new
pcoord_t [this->
numRanks
];
126
127
for
(
int
i = 0; i < networkDim; i++) {
128
Teuchos::reduceAll<int, pcoord_t>(comm, Teuchos::REDUCE_SUM,
129
this->
numRanks
, procCoords[i], tmpVect);
130
pcoord_t *tmp = tmpVect;
131
tmpVect = procCoords[i];
132
procCoords[i] = tmp;
133
}
134
delete
[] tmpVect;
135
}
136
};
137
}
138
#endif
Zoltan2_Machine.hpp
Zoltan2::MachineForTesting::getAllMachineCoordinatesView
bool getAllMachineCoordinatesView(pcoord_t **&allCoords) const
Definition
Zoltan2_MachineForTesting.hpp:112
Zoltan2::MachineForTesting::hasMachineCoordinates
bool hasMachineCoordinates() const
Definition
Zoltan2_MachineForTesting.hpp:76
Zoltan2::MachineForTesting::~MachineForTesting
virtual ~MachineForTesting()
Definition
Zoltan2_MachineForTesting.hpp:69
Zoltan2::MachineForTesting::getMyMachineCoordinate
bool getMyMachineCoordinate(pcoord_t *xyz)
Definition
Zoltan2_MachineForTesting.hpp:88
Zoltan2::MachineForTesting::getMachineCoordinate
bool getMachineCoordinate(const int rank, pcoord_t *xyz)
Definition
Zoltan2_MachineForTesting.hpp:92
Zoltan2::MachineForTesting::getMachineCoordinate
bool getMachineCoordinate(const char *nodename, pcoord_t *xyz)
Definition
Zoltan2_MachineForTesting.hpp:108
Zoltan2::MachineForTesting::MachineForTesting
MachineForTesting(const Teuchos::Comm< int > &comm, const Teuchos::ParameterList &pl)
Definition
Zoltan2_MachineForTesting.hpp:46
Zoltan2::MachineForTesting::getMachineExtent
bool getMachineExtent(int *nxyz) const
Definition
Zoltan2_MachineForTesting.hpp:80
Zoltan2::MachineForTesting::getMachineDim
int getMachineDim() const
Definition
Zoltan2_MachineForTesting.hpp:78
Zoltan2::MachineForTesting::MachineForTesting
MachineForTesting(const Teuchos::Comm< int > &comm)
Constructor: A default machine description used only for testing; it does not contain actual machine ...
Definition
Zoltan2_MachineForTesting.hpp:23
Zoltan2::Machine::Machine
Machine(const Teuchos::Comm< int > &comm)
Constructor MachineRepresentation Class.
Definition
Zoltan2_Machine.hpp:23
Zoltan2::Machine::myRank
int myRank
Definition
Zoltan2_Machine.hpp:16
Zoltan2::Machine::numRanks
int numRanks
Definition
Zoltan2_Machine.hpp:15
Zoltan2
Created by mbenlioglu on Aug 31, 2020.
Definition
Zoltan2_AlgHybrid2GL.hpp:38
Zoltan2::part_t
core
src
environment
Zoltan2_MachineForTesting.hpp
Generated by
1.17.0