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