Zoltan2
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
17namespace Zoltan2{
18
23template <typename pcoord_t, typename part_t>
24class MachineForTesting : public Machine<pcoord_t, part_t> {
25
26public:
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];
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];
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
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
126private:
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
A Machine Class for testing only A more realistic machine should be used for task mapping.
bool getAllMachineCoordinatesView(pcoord_t **&allCoords) const
bool getMachineCoordinate(const int rank, pcoord_t *xyz)
bool getMachineCoordinate(const char *nodename, pcoord_t *xyz)
MachineForTesting(const Teuchos::Comm< int > &comm, const Teuchos::ParameterList &pl)
MachineForTesting(const Teuchos::Comm< int > &comm)
Constructor: A default machine description used only for testing; it does not contain actual machine ...
MachineClass Base class for representing machine coordinates, networks, etc.
Created by mbenlioglu on Aug 31, 2020.
SparseMatrixAdapter_t::part_t part_t