43 #ifndef IFPACK2_LINE_PARTITIONER_DEF_HPP
44 #define IFPACK2_LINE_PARTITIONER_DEF_HPP
46 #include "Tpetra_CrsGraph.hpp"
47 #include "Tpetra_Util.hpp"
58 template<
class GraphType,
class Scalar>
65 template<
class GraphType,
class Scalar>
69 template<
class GraphType,
class Scalar>
73 threshold_ = List.
get(
"partitioner: line detection threshold",threshold_);
75 std::runtime_error,
"Ifpack2::LinePartitioner: threshold not valid");
77 NumEqns_ = List.
get(
"partitioner: PDE equations",NumEqns_);
80 coord_ = List.
get(
"partitioner: coordinates",coord_);
85 template<
class GraphType,
class Scalar>
91 TEUCHOS_TEST_FOR_EXCEPTION((
size_t)this->Partition_.size() != this->Graph_->getLocalNumRows(),std::runtime_error,
"Ifpack2::LinePartitioner: partition size error");
94 if(this->Partition_.size() == 0) {this->NumLocalParts_ = 0;
return;}
97 for(
size_t i=0; i<this->Graph_->getLocalNumRows(); i++)
98 this->Partition_[i] = invalid;
101 this->NumLocalParts_ = this->Compute_Blocks_AutoLine(this->Partition_());
104 this->Parts_.resize(this->NumLocalParts_);
109 template<
class GraphType,
class Scalar>
111 typedef local_ordinal_type LO;
112 typedef magnitude_type MT;
118 xvalsRCP = coord_->getData(0); xvals = xvalsRCP();
119 if(coord_->getNumVectors() > 1) { yvalsRCP = coord_->getData(1); yvals = yvalsRCP(); }
120 if(coord_->getNumVectors() > 2) { zvalsRCP = coord_->getData(2); zvals = zvalsRCP(); }
122 double tol = threshold_;
123 size_t N = this->Graph_->getLocalNumRows();
124 size_t allocated_space = this->Graph_->getLocalMaxNumRowEntries();
126 nonconst_local_inds_host_view_type cols(
"cols",allocated_space);
135 for(LO i=0; i<(LO)N; i+=NumEqns_) {
138 if(blockIndices[i] != invalid)
continue;
141 this->Graph_->getLocalRowCopy(i,cols,nz);
142 MT x0 = (!xvals.
is_null()) ? xvals[i/NumEqns_] : zero;
143 MT y0 = (!yvals.
is_null()) ? yvals[i/NumEqns_] : zero;
144 MT z0 = (!zvals.
is_null()) ? zvals[i/NumEqns_] : zero;
147 for(
size_t j=0; j<nz; j+=NumEqns_) {
149 LO nn = cols[j] / NumEqns_;
150 if(cols[j] >=(LO)N)
continue;
151 if(!xvals.
is_null()) mydist += square<MT>(x0 - xvals[nn]);
152 if(!yvals.
is_null()) mydist += square<MT>(y0 - yvals[nn]);
153 if(!zvals.
is_null()) mydist += square<MT>(z0 - zvals[nn]);
155 indices[neighbor_len]=cols[j];
160 Tpetra::sort2(dist_view.
begin(),dist_view.
end(),indices.begin());
163 for(LO k=0; k<NumEqns_; k++)
164 blockIndices[i + k] = num_lines;
167 if(neighbor_len > 2 && dist[1]/dist[neighbor_len-1] < tol) {
168 local_automatic_line_search(NumEqns_,blockIndices,i,indices[1],num_lines,tol,itemp,dtemp);
171 if(neighbor_len > 3 && dist[2]/dist[neighbor_len-1] < tol) {
172 local_automatic_line_search(NumEqns_,blockIndices,i,indices[2],num_lines,tol,itemp,dtemp);
180 template<
class GraphType,
class Scalar>
182 typedef local_ordinal_type LO;
183 typedef magnitude_type MT;
189 xvalsRCP = coord_->getData(0); xvals = xvalsRCP();
190 if(coord_->getNumVectors() > 1) { yvalsRCP = coord_->getData(1); yvals = yvalsRCP(); }
191 if(coord_->getNumVectors() > 2) { zvalsRCP = coord_->getData(2); zvals = zvalsRCP(); }
193 size_t N = this->Graph_->getLocalNumRows();
194 size_t allocated_space = this->Graph_->getLocalMaxNumRowEntries();
196 nonconst_local_inds_host_view_type cols(itemp.
data(),allocated_space);
200 while (blockIndices[next] == invalid) {
203 LO neighbors_in_line=0;
205 this->Graph_->getLocalRowCopy(next,cols,nz);
206 MT x0 = (!xvals.
is_null()) ? xvals[next/NumEqns_] : zero;
207 MT y0 = (!yvals.
is_null()) ? yvals[next/NumEqns_] : zero;
208 MT z0 = (!zvals.
is_null()) ? zvals[next/NumEqns_] : zero;
212 for(
size_t i=0; i<nz; i+=NumEqns) {
214 if(cols[i] >=(LO)N)
continue;
215 LO nn = cols[i] / NumEqns;
216 if(blockIndices[nn]==LineID) neighbors_in_line++;
217 if(!xvals.
is_null()) mydist += square<MT>(x0 - xvals[nn]);
218 if(!yvals.
is_null()) mydist += square<MT>(y0 - yvals[nn]);
219 if(!zvals.
is_null()) mydist += square<MT>(z0 - zvals[nn]);
221 indices[neighbor_len]=cols[i];
226 if(neighbors_in_line > 1)
break;
229 for(LO k=0; k<NumEqns; k++)
230 blockIndices[next + k] = LineID;
234 Tpetra::sort2(dist_view.
begin(),dist_view.
end(),indices.begin());
236 if(neighbor_len > 2 && indices[1] != last && blockIndices[indices[1]] == -1 && dist[1]/dist[neighbor_len-1] < tol) {
240 else if(neighbor_len > 3 && indices[2] != last && blockIndices[indices[2]] == -1 && dist[2]/dist[neighbor_len-1] < tol) {
255 #define IFPACK2_LINEPARTITIONER_INSTANT(S,LO,GO,N) \
256 template class Ifpack2::LinePartitioner<Tpetra::CrsGraph< LO, GO, N >,S >; \
257 template class Ifpack2::LinePartitioner<Tpetra::RowGraph< LO, GO, N >,S >;
259 #endif // IFPACK2_LINEPARTITIONER_DEF_HPP
LinePartitioner(const Teuchos::RCP< const row_graph_type > &graph)
Constructor.
Definition: Ifpack2_LinePartitioner_def.hpp:60
T & get(const std::string &name, T def_value)
ArrayView< T > view(size_type offset, size_type size)
void computePartitions()
Compute the partitions.
Definition: Ifpack2_LinePartitioner_def.hpp:86
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual ~LinePartitioner()
Destructor.
Definition: Ifpack2_LinePartitioner_def.hpp:66
static magnitudeType magnitude(T a)
Create overlapping partitions of a local graph.
Definition: Ifpack2_OverlappingPartitioner_decl.hpp:78
void setPartitionParameters(Teuchos::ParameterList &List)
Set the partitioner's parameters (none for linear partitioning).
Definition: Ifpack2_LinePartitioner_def.hpp:72
Ifpack2::LinePartitioner: A class to define partitions into a set of lines.
Definition: Ifpack2_LinePartitioner_decl.hpp:78