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) {
44 const Teuchos::ParameterEntry *pe = params.getEntryPtr(
"nProcessorRows");
45 if (pe != NULL) npRow = pe->getValue<
int>(&npRow);
47 TEUCHOS_TEST_FOR_EXCEPTION(npRow != -1 && npRow != np, std::logic_error,
48 " nProcessorRows " << npRow <<
" must equal"
49 <<
" nProcessors " << np <<
" for 1D distribution");
51 if (me == 0) std::cout <<
"\n 1D Distribution: "
52 <<
"\n np = " << np << std::endl;
56 virtual bool VecMine(gno_t i) = 0;
60 inline bool Mine(gno_t i, gno_t j) {
return VecMine(i); }
61 inline bool Mine(gno_t i, gno_t j,
int p) {
return VecMine(i); }
65 template <
typename gno_t,
typename scalar_t>
66 class Distribution1DLinear :
public Distribution1D<gno_t, scalar_t> {
68 using Distribution<gno_t, scalar_t>::me;
69 using Distribution<gno_t, scalar_t>::np;
70 using Distribution<gno_t, scalar_t>::nrows;
72 Distribution1DLinear(
size_t nrows_,
73 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm_,
74 const Teuchos::ParameterList ¶ms)
75 : Distribution1D<gno_t, scalar_t>(nrows_, comm_, params) {
76 gno_t nMyRows = getNumRow(me);
77 myFirstRow = getFirstRow(me);
78 myLastRow = myFirstRow + nMyRows - 1;
81 inline enum DistributionType DistType() {
return OneDLinear; }
83 inline bool VecMine(gno_t i) {
return (i >= myFirstRow && i <= myLastRow); }
89 inline size_t getNumRow(
int p) {
90 return (nrows / np + (
int(nrows % np) > p));
93 inline gno_t getFirstRow(
int p) {
94 return (p * (nrows / np) + std::min<int>(
int(nrows % np), p));
98 friend class DistributionLowerTriangularBlock<gno_t, scalar_t>;
102 template <
typename gno_t,
typename scalar_t>
103 class Distribution1DRandom :
public Distribution1D<gno_t, scalar_t> {
105 using Distribution<gno_t, scalar_t>::me;
107 Distribution1DRandom(
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) {
111 if (me == 0) std::cout <<
" randomize = true" << std::endl;
114 inline enum DistributionType DistType() {
return OneDRandom; }
116 inline bool VecMine(gno_t i) {
return (this->HashToProc(i) == me); }
120 template <
typename gno_t,
typename scalar_t>
121 class Distribution1DVec :
public Distribution1D<gno_t, scalar_t> {
132 using Distribution<gno_t, scalar_t>::me;
133 using Distribution<gno_t, scalar_t>::np;
134 using Distribution<gno_t, scalar_t>::comm;
135 using Distribution<gno_t, scalar_t>::nrows;
136 using Distribution<gno_t, scalar_t>::Mine;
138 Distribution1DVec(
size_t nrows_,
139 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm_,
140 const Teuchos::ParameterList ¶ms,
141 std::string &distributionfile)
142 : Distribution1D<gno_t, scalar_t>(nrows_, comm_, params) {
145 fpin.open(distributionfile.c_str(), std::ios::in);
146 if (!fpin.is_open()) {
147 std::cout <<
"Error: distributionfile " << distributionfile
148 <<
" not found" << std::endl;
158 vecpart =
new int[nrows];
160 const int bcastsize = 1000000;
164 for (
size_t i = 0; i < nrows; i++) {
165 if (me == 0) fpin >> vecpart[i];
167 if (cnt == bcastsize || i == nrows - 1) {
168 Teuchos::broadcast<int, int>(*comm, 0, cnt, &(vecpart[
start]));
174 if (me == 0) fpin.close();
177 ~Distribution1DVec() {
delete[] vecpart; }
179 inline enum DistributionType DistType() {
return OneDVec; }
182 inline bool VecMine(gno_t i) {
return (vecpart[i] == me); }
void start()
Start the deep_copy counter.