Ifpack2 Templated Preconditioning Package Version 1.0
Loading...
Searching...
No Matches
Ifpack2_Details_UserPartitioner_def.hpp
1// @HEADER
2// *****************************************************************************
3// Ifpack2: Templated Object-Oriented Algebraic Preconditioner Package
4//
5// Copyright 2009 NTESS and the Ifpack2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef IFPACK2_USER_PARTITIONER_DEF_HPP
11#define IFPACK2_USER_PARTITIONER_DEF_HPP
12
13#include <Ifpack2_ConfigDefs.hpp>
15#include <Ifpack2_OverlappingPartitioner.hpp>
16
17namespace Ifpack2 {
18namespace Details {
19
20template<class GraphType>
22UserPartitioner (const Teuchos::RCP<const row_graph_type>& graph) :
23 OverlappingPartitioner<GraphType> (graph),
24 userProvidedParts_(false),
25 userProvidedMap_(false)
26{}
27
28template<class GraphType>
30
31template<class GraphType>
32void
34setPartitionParameters (Teuchos::ParameterList& List)
35{
36 int partCount = 0;
37 bool globalProvidedParts;
38 userProvidedParts_ = List.isParameter("partitioner: parts");
39 globalProvidedParts = List.isParameter("partitioner: global ID parts");
40 if ( userProvidedParts_) partCount++;
41 if (globalProvidedParts ) { partCount++; userProvidedParts_ = true; }
42
43 userProvidedMap_ = List.isParameter("partitioner: map");
44 if ( userProvidedMap_) partCount++;
45 if (partCount > 1) {
46 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Ifpack2::UserPartitioner::setPartitionParameters: "
47 "you may specify only one of \"partitioner: parts\", \"partitioner: global ID parts\" and \"partitioner: map\","
48 " not two of them");
49 }
50 if (userProvidedMap_) {
51 map_ = List.get ("partitioner: map", map_);
52 TEUCHOS_TEST_FOR_EXCEPTION(
53 map_.is_null (), std::runtime_error, "Ifpack2::UserPartitioner::"
54 "setPartitionParameters: map_ is null.");
55 }
56 if (userProvidedParts_) {
57 typedef Teuchos::Array<typename Teuchos::ArrayRCP<typename GraphType::local_ordinal_type>> parts_type;
58 typedef Teuchos::Array<typename Teuchos::ArrayRCP<typename GraphType::global_ordinal_type>> gparts_type;
59 //FIXME JJH 9-Dec-2015 - This is a potentially expensive deep copy. Use an ArrayRCP<ArrayRCP<int>> instead.
60
61 // convert glboal ids to local ids before storing in Parts_
62 if (globalProvidedParts ) {
63 gparts_type gparts;
64 gparts = List.get<gparts_type>("partitioner: global ID parts");
65 typedef Teuchos::RCP< Tpetra::Map<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type> const > map_type;
66 map_type OverlapMap = List.get<map_type>("OverlapRowMap");
67 this->Parts_.resize(gparts.size());
68 for (int ii = 0; ii < (int) gparts.size(); ii++) {
69 this->Parts_[ii].resize(gparts[ii].size());
70 for (int jj = 0; jj < (int) gparts[ii].size(); jj++) {
71 local_ordinal_type itmp = (int) OverlapMap->getLocalElement( gparts[ii][jj] );
72 if (itmp == Teuchos::OrdinalTraits<local_ordinal_type>::invalid()) printf("global id %d (%d,%d) not found\n",(int) gparts[ii][jj],(int) ii, (int) jj);
73 TEUCHOS_TEST_FOR_EXCEPTION(itmp == Teuchos::OrdinalTraits<local_ordinal_type>::invalid(), std::runtime_error, " \"partitioner: global ID parts\" requires that all global IDs within a block reside on the MPI rank owning the block. This can be done using overlapping Schwarz with a BLOCK_RELAXATION subdomain solver making sure that \"schwarz: overlap level\" is sufficient. Note: zeroed out Dirichlet columns will never be included in overlap parts of domains.");
74 this->Parts_[ii][jj] = itmp;
75 }
76 }
77 List.remove("partitioner: global ID parts"); //JJH I observed that iterating through the ParameterList is much more
78 //expensive when "partitioner: collection" is a Parameter object.
79 //Thus, I remove it once it's fetched from the list.
80 }
81 else {
82 this->Parts_ = List.get<parts_type>("partitioner: parts");
83 List.remove("partitioner: parts"); //JJH I observed that iterating through the ParameterList is much more
84 //expensive when "partitioner: collection" is a Parameter object.
85 //Thus, I remove it once it's fetched from the list.
86 }
87 }
88
89}
90
91template<class GraphType>
93{
94 if (userProvidedParts_) {
95 this->NumLocalParts_ = this->Parts_.size();
96 //The user has explicitly defined Parts_, so there is no need to for Partition_.
97 this->Partition_.resize(0);
98 } else {
99 TEUCHOS_TEST_FOR_EXCEPTION(
100 map_.is_null (), std::logic_error, "Ifpack2::UserPartitioner::"
101 "computePartitions: map_ is null.");
102 const size_t localNumRows = this->Graph_->getLocalNumRows ();
103 for (size_t ii = 0; ii < localNumRows; ++ii) {
104 this->Partition_[ii] = map_[ii];
105 }
106 }
107 // IGNORING ALL THE SINGLETON STUFF IN IFPACK_USERPARTITIONER.CPP BY
108 // ORDERS OF CHRIS SIEFERT
109}
110
111}// namespace Details
112}// namespace Ifpack2
113
114#endif // IFPACK2_USERPARTITIONER_DEF_HPP
115
116
Declaration of a user-defined partitioner in which the user can define a partition of the graph....
virtual ~UserPartitioner()
Destructor.
Definition Ifpack2_Details_UserPartitioner_def.hpp:29
void computePartitions()
Compute the partitions.
Definition Ifpack2_Details_UserPartitioner_def.hpp:92
void setPartitionParameters(Teuchos::ParameterList &List)
Sets all the parameters for the partitioner. The only valid parameters are:
Definition Ifpack2_Details_UserPartitioner_def.hpp:34
UserPartitioner(const Teuchos::RCP< const row_graph_type > &graph)
Constructor.
Definition Ifpack2_Details_UserPartitioner_def.hpp:22
Teuchos::Array< local_ordinal_type > Partition_
Mapping from local row to partition number.
Definition Ifpack2_OverlappingPartitioner_decl.hpp:145
OverlappingPartitioner(const Teuchos::RCP< const row_graph_type > &graph)
Constructor.
Definition Ifpack2_OverlappingPartitioner_def.hpp:24
Teuchos::RCP< const row_graph_type > Graph_
The graph to be partitioned.
Definition Ifpack2_OverlappingPartitioner_decl.hpp:155
Teuchos::Array< Teuchos::ArrayRCP< local_ordinal_type > > Parts_
Mapping from partition to all rows it contains.
Definition Ifpack2_OverlappingPartitioner_decl.hpp:152
int NumLocalParts_
Number of local subgraphs.
Definition Ifpack2_OverlappingPartitioner_decl.hpp:138
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:41