10 #ifndef IFPACK2_LINE_PARTITIONER_DEF_HPP
11 #define IFPACK2_LINE_PARTITIONER_DEF_HPP
13 #include "Tpetra_CrsGraph.hpp"
14 #include "Tpetra_Util.hpp"
25 template<
class GraphType,
class Scalar>
32 template<
class GraphType,
class Scalar>
36 template<
class GraphType,
class Scalar>
40 threshold_ = List.
get(
"partitioner: line detection threshold",threshold_);
42 std::runtime_error,
"Ifpack2::LinePartitioner: threshold not valid");
44 NumEqns_ = List.
get(
"partitioner: PDE equations",NumEqns_);
47 coord_ = List.
get(
"partitioner: coordinates",coord_);
52 template<
class GraphType,
class Scalar>
58 TEUCHOS_TEST_FOR_EXCEPTION((
size_t)this->Partition_.size() != this->Graph_->getLocalNumRows(),std::runtime_error,
"Ifpack2::LinePartitioner: partition size error");
61 if(this->Partition_.size() == 0) {this->NumLocalParts_ = 0;
return;}
64 for(
size_t i=0; i<this->Graph_->getLocalNumRows(); i++)
65 this->Partition_[i] = invalid;
68 this->NumLocalParts_ = this->Compute_Blocks_AutoLine(this->Partition_());
71 this->Parts_.resize(this->NumLocalParts_);
76 template<
class GraphType,
class Scalar>
78 typedef local_ordinal_type LO;
79 typedef magnitude_type MT;
85 xvalsRCP = coord_->getData(0); xvals = xvalsRCP();
86 if(coord_->getNumVectors() > 1) { yvalsRCP = coord_->getData(1); yvals = yvalsRCP(); }
87 if(coord_->getNumVectors() > 2) { zvalsRCP = coord_->getData(2); zvals = zvalsRCP(); }
89 double tol = threshold_;
90 size_t N = this->Graph_->getLocalNumRows();
91 size_t allocated_space = this->Graph_->getLocalMaxNumRowEntries();
93 nonconst_local_inds_host_view_type cols(
"cols",allocated_space);
102 for(LO i=0; i<(LO)N; i+=NumEqns_) {
105 if(blockIndices[i] != invalid)
continue;
108 this->Graph_->getLocalRowCopy(i,cols,nz);
109 MT x0 = (!xvals.
is_null()) ? xvals[i/NumEqns_] : zero;
110 MT y0 = (!yvals.
is_null()) ? yvals[i/NumEqns_] : zero;
111 MT z0 = (!zvals.
is_null()) ? zvals[i/NumEqns_] : zero;
114 for(
size_t j=0; j<nz; j+=NumEqns_) {
116 LO nn = cols[j] / NumEqns_;
117 if(cols[j] >=(LO)N)
continue;
118 if(!xvals.
is_null()) mydist += square<MT>(x0 - xvals[nn]);
119 if(!yvals.
is_null()) mydist += square<MT>(y0 - yvals[nn]);
120 if(!zvals.
is_null()) mydist += square<MT>(z0 - zvals[nn]);
122 indices[neighbor_len]=cols[j];
127 Tpetra::sort2(dist_view.
begin(),dist_view.
end(),indices.begin());
130 for(LO k=0; k<NumEqns_; k++)
131 blockIndices[i + k] = num_lines;
134 if(neighbor_len > 2 && dist[1]/dist[neighbor_len-1] < tol) {
135 local_automatic_line_search(NumEqns_,blockIndices,i,indices[1],num_lines,tol,itemp,dtemp);
138 if(neighbor_len > 3 && dist[2]/dist[neighbor_len-1] < tol) {
139 local_automatic_line_search(NumEqns_,blockIndices,i,indices[2],num_lines,tol,itemp,dtemp);
147 template<
class GraphType,
class Scalar>
149 typedef local_ordinal_type LO;
150 typedef magnitude_type MT;
156 xvalsRCP = coord_->getData(0); xvals = xvalsRCP();
157 if(coord_->getNumVectors() > 1) { yvalsRCP = coord_->getData(1); yvals = yvalsRCP(); }
158 if(coord_->getNumVectors() > 2) { zvalsRCP = coord_->getData(2); zvals = zvalsRCP(); }
160 size_t N = this->Graph_->getLocalNumRows();
161 size_t allocated_space = this->Graph_->getLocalMaxNumRowEntries();
163 nonconst_local_inds_host_view_type cols(itemp.
data(),allocated_space);
167 while (blockIndices[next] == invalid) {
170 LO neighbors_in_line=0;
172 this->Graph_->getLocalRowCopy(next,cols,nz);
173 MT x0 = (!xvals.
is_null()) ? xvals[next/NumEqns_] : zero;
174 MT y0 = (!yvals.
is_null()) ? yvals[next/NumEqns_] : zero;
175 MT z0 = (!zvals.
is_null()) ? zvals[next/NumEqns_] : zero;
179 for(
size_t i=0; i<nz; i+=NumEqns) {
181 if(cols[i] >=(LO)N)
continue;
182 LO nn = cols[i] / NumEqns;
183 if(blockIndices[nn]==LineID) neighbors_in_line++;
184 if(!xvals.
is_null()) mydist += square<MT>(x0 - xvals[nn]);
185 if(!yvals.
is_null()) mydist += square<MT>(y0 - yvals[nn]);
186 if(!zvals.
is_null()) mydist += square<MT>(z0 - zvals[nn]);
188 indices[neighbor_len]=cols[i];
193 if(neighbors_in_line > 1)
break;
196 for(LO k=0; k<NumEqns; k++)
197 blockIndices[next + k] = LineID;
201 Tpetra::sort2(dist_view.
begin(),dist_view.
end(),indices.begin());
203 if(neighbor_len > 2 && indices[1] != last && blockIndices[indices[1]] == -1 && dist[1]/dist[neighbor_len-1] < tol) {
207 else if(neighbor_len > 3 && indices[2] != last && blockIndices[indices[2]] == -1 && dist[2]/dist[neighbor_len-1] < tol) {
222 #define IFPACK2_LINEPARTITIONER_INSTANT(S,LO,GO,N) \
223 template class Ifpack2::LinePartitioner<Tpetra::CrsGraph< LO, GO, N >,S >; \
224 template class Ifpack2::LinePartitioner<Tpetra::RowGraph< LO, GO, N >,S >;
226 #endif // IFPACK2_LINEPARTITIONER_DEF_HPP
LinePartitioner(const Teuchos::RCP< const row_graph_type > &graph)
Constructor.
Definition: Ifpack2_LinePartitioner_def.hpp:27
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:53
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual ~LinePartitioner()
Destructor.
Definition: Ifpack2_LinePartitioner_def.hpp:33
static magnitudeType magnitude(T a)
Create overlapping partitions of a local graph.
Definition: Ifpack2_OverlappingPartitioner_decl.hpp:45
void setPartitionParameters(Teuchos::ParameterList &List)
Set the partitioner's parameters (none for linear partitioning).
Definition: Ifpack2_LinePartitioner_def.hpp:39
Ifpack2::LinePartitioner: A class to define partitions into a set of lines.
Definition: Ifpack2_LinePartitioner_decl.hpp:45