47 #ifndef __TPETRA_DISTRIBUTION1D_HPP
48 #define __TPETRA_DISTRIBUTION1D_HPP
53 template <
typename gno_t,
typename scalar_t>
54 class DistributionLowerTriangularBlock;
57 template <
typename gno_t,
typename scalar_t>
58 class Distribution1D :
public Distribution<gno_t,scalar_t> {
65 using Distribution<gno_t,scalar_t>::me;
66 using Distribution<gno_t,scalar_t>::np;
67 using Distribution<gno_t,scalar_t>::nrows;
68 using Distribution<gno_t,scalar_t>::Mine;
70 Distribution1D(
size_t nrows_,
71 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm_,
72 const Teuchos::ParameterList ¶ms) :
73 Distribution<gno_t,scalar_t>(nrows_, comm_, params)
77 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"nProcessorRows");
78 if (pe != NULL) npRow = pe->getValue<
int>(&npRow);
80 TEUCHOS_TEST_FOR_EXCEPTION(npRow != -1 && npRow != np, std::logic_error,
81 " nProcessorRows " << npRow <<
" must equal" <<
82 " nProcessors " << np <<
83 " for 1D distribution");
85 if (me == 0) std::cout <<
"\n 1D Distribution: "
86 <<
"\n np = " << np << std::endl;
90 virtual bool VecMine(gno_t i) = 0;
94 inline bool Mine(gno_t i, gno_t j) {
return VecMine(i);}
95 inline bool Mine(gno_t i, gno_t j,
int p) {
return VecMine(i);}
99 template <
typename gno_t,
typename scalar_t>
100 class Distribution1DLinear:
public Distribution1D<gno_t,scalar_t> {
103 using Distribution<gno_t,scalar_t>::me;
104 using Distribution<gno_t,scalar_t>::np;
105 using Distribution<gno_t,scalar_t>::nrows;
107 Distribution1DLinear(
size_t nrows_,
108 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm_,
109 const Teuchos::ParameterList ¶ms) :
110 Distribution1D<gno_t,scalar_t>(nrows_, comm_, params)
112 gno_t nMyRows = getNumRow(me);
113 myFirstRow = getFirstRow(me);
114 myLastRow = myFirstRow + nMyRows - 1;
117 inline enum DistributionType DistType() {
return OneDLinear; }
119 inline bool VecMine(gno_t i) {
return (i >= myFirstRow && i <= myLastRow); }
125 inline size_t getNumRow(
int p) {
126 return (nrows / np + (
int(nrows % np) > p));
129 inline gno_t getFirstRow(
int p) {
130 return (p * (nrows / np) + std::min<int>(
int(nrows % np), p));
134 friend class DistributionLowerTriangularBlock<gno_t,scalar_t>;
139 template <
typename gno_t,
typename scalar_t>
140 class Distribution1DRandom :
public Distribution1D<gno_t,scalar_t> {
144 using Distribution<gno_t,scalar_t>::me;
146 Distribution1DRandom(
size_t nrows_,
147 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm_,
148 const Teuchos::ParameterList ¶ms) :
149 Distribution1D<gno_t,scalar_t>(nrows_, comm_, params)
150 {
if (me == 0) std::cout <<
" randomize = true" << std::endl; }
152 inline enum DistributionType DistType() {
return OneDRandom; }
154 inline bool VecMine(gno_t i) {
return (this->HashToProc(i) == me); }
158 template <
typename gno_t,
typename scalar_t>
159 class Distribution1DVec :
public Distribution1D<gno_t,scalar_t> {
170 using Distribution<gno_t,scalar_t>::me;
171 using Distribution<gno_t,scalar_t>::np;
172 using Distribution<gno_t,scalar_t>::comm;
173 using Distribution<gno_t,scalar_t>::nrows;
174 using Distribution<gno_t,scalar_t>::Mine;
176 Distribution1DVec(
size_t nrows_,
177 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm_,
178 const Teuchos::ParameterList ¶ms,
179 std::string &distributionfile) :
180 Distribution1D<gno_t,scalar_t>(nrows_, comm_, params)
184 fpin.open(distributionfile.c_str(), std::ios::in);
185 if (!fpin.is_open()) {
186 std::cout <<
"Error: distributionfile " << distributionfile
187 <<
" not found" << std::endl;
197 vecpart =
new int[nrows];
199 const int bcastsize = 1000000;
203 for (
size_t i = 0; i < nrows; i++) {
204 if (me == 0) fpin >> vecpart[i];
206 if (cnt == bcastsize || i == nrows-1) {
207 Teuchos::broadcast<int, int>(*comm, 0, cnt, &(vecpart[
start]));
213 if (me == 0) fpin.close();
216 ~Distribution1DVec() {
delete [] vecpart;}
218 inline enum DistributionType DistType() {
return OneDVec; }
221 inline bool VecMine(gno_t i) {
return (vecpart[i] == me); }
void start()
Start the deep_copy counter.