15 #ifndef __TPETRA_DISTRIBUTION1D_HPP
16 #define __TPETRA_DISTRIBUTION1D_HPP
21 template <
typename gno_t,
typename scalar_t>
22 class DistributionLowerTriangularBlock;
25 template <
typename gno_t,
typename scalar_t>
26 class Distribution1D :
public Distribution<gno_t,scalar_t> {
33 using Distribution<gno_t,scalar_t>::me;
34 using Distribution<gno_t,scalar_t>::np;
35 using Distribution<gno_t,scalar_t>::nrows;
36 using Distribution<gno_t,scalar_t>::Mine;
38 Distribution1D(
size_t nrows_,
39 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm_,
40 const Teuchos::ParameterList ¶ms) :
41 Distribution<gno_t,scalar_t>(nrows_, comm_, params)
45 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"nProcessorRows");
46 if (pe != NULL) npRow = pe->getValue<
int>(&npRow);
48 TEUCHOS_TEST_FOR_EXCEPTION(npRow != -1 && npRow != np, std::logic_error,
49 " nProcessorRows " << npRow <<
" must equal" <<
50 " nProcessors " << np <<
51 " for 1D distribution");
53 if (me == 0) std::cout <<
"\n 1D Distribution: "
54 <<
"\n np = " << np << std::endl;
58 virtual bool VecMine(gno_t i) = 0;
62 inline bool Mine(gno_t i, gno_t j) {
return VecMine(i);}
63 inline bool Mine(gno_t i, gno_t j,
int p) {
return VecMine(i);}
67 template <
typename gno_t,
typename scalar_t>
68 class Distribution1DLinear:
public Distribution1D<gno_t,scalar_t> {
71 using Distribution<gno_t,scalar_t>::me;
72 using Distribution<gno_t,scalar_t>::np;
73 using Distribution<gno_t,scalar_t>::nrows;
75 Distribution1DLinear(
size_t nrows_,
76 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm_,
77 const Teuchos::ParameterList ¶ms) :
78 Distribution1D<gno_t,scalar_t>(nrows_, comm_, params)
80 gno_t nMyRows = getNumRow(me);
81 myFirstRow = getFirstRow(me);
82 myLastRow = myFirstRow + nMyRows - 1;
85 inline enum DistributionType DistType() {
return OneDLinear; }
87 inline bool VecMine(gno_t i) {
return (i >= myFirstRow && i <= myLastRow); }
93 inline size_t getNumRow(
int p) {
94 return (nrows / np + (
int(nrows % np) > p));
97 inline gno_t getFirstRow(
int p) {
98 return (p * (nrows / np) + std::min<int>(
int(nrows % np), p));
102 friend class DistributionLowerTriangularBlock<gno_t,scalar_t>;
107 template <
typename gno_t,
typename scalar_t>
108 class Distribution1DRandom :
public Distribution1D<gno_t,scalar_t> {
112 using Distribution<gno_t,scalar_t>::me;
114 Distribution1DRandom(
size_t nrows_,
115 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm_,
116 const Teuchos::ParameterList ¶ms) :
117 Distribution1D<gno_t,scalar_t>(nrows_, comm_, params)
118 {
if (me == 0) std::cout <<
" randomize = true" << std::endl; }
120 inline enum DistributionType DistType() {
return OneDRandom; }
122 inline bool VecMine(gno_t i) {
return (this->HashToProc(i) == me); }
126 template <
typename gno_t,
typename scalar_t>
127 class Distribution1DVec :
public Distribution1D<gno_t,scalar_t> {
138 using Distribution<gno_t,scalar_t>::me;
139 using Distribution<gno_t,scalar_t>::np;
140 using Distribution<gno_t,scalar_t>::comm;
141 using Distribution<gno_t,scalar_t>::nrows;
142 using Distribution<gno_t,scalar_t>::Mine;
144 Distribution1DVec(
size_t nrows_,
145 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm_,
146 const Teuchos::ParameterList ¶ms,
147 std::string &distributionfile) :
148 Distribution1D<gno_t,scalar_t>(nrows_, comm_, params)
152 fpin.open(distributionfile.c_str(), std::ios::in);
153 if (!fpin.is_open()) {
154 std::cout <<
"Error: distributionfile " << distributionfile
155 <<
" not found" << std::endl;
165 vecpart =
new int[nrows];
167 const int bcastsize = 1000000;
171 for (
size_t i = 0; i < nrows; i++) {
172 if (me == 0) fpin >> vecpart[i];
174 if (cnt == bcastsize || i == nrows-1) {
175 Teuchos::broadcast<int, int>(*comm, 0, cnt, &(vecpart[
start]));
181 if (me == 0) fpin.close();
184 ~Distribution1DVec() {
delete [] vecpart;}
186 inline enum DistributionType DistType() {
return OneDVec; }
189 inline bool VecMine(gno_t i) {
return (vecpart[i] == me); }
void start()
Start the deep_copy counter.