42 #ifndef __TSQR_Tsqr_TwoLevelDistTsqr_hpp
43 #define __TSQR_Tsqr_TwoLevelDistTsqr_hpp
45 #include <Tsqr_DistTsqr.hpp>
46 #include <Tsqr_MpiCommFactory.hpp>
60 template<
class LocalOrdinal,
62 class DistTsqrType = DistTsqr< LocalOrdinal, Scalar > >
65 typedef Scalar scalar_type;
66 typedef LocalOrdinal ordinal_type;
67 typedef DistTsqrType dist_tsqr_type;
68 typedef typename dist_tsqr_type::rank_type rank_type;
70 typedef typename dist_tsqr_type::FactorOutput DistTsqrFactorOutput;
71 typedef std::pair< DistTsqrFactorOutput, DistTsqrFactorOutput > FactorOutput;
76 worldMess_ (TSQR::MPI::makeMpiCommWorld()),
77 nodeDistTsqr_ (TSQR::MPI::makeMpiCommNode()),
78 networkDistTsqr_ (TSQR::MPI::makeMpiCommNetwork())
89 return nodeDistTsqr_->QR_produces_R_factor_with_nonnegative_diagonal() &&
90 networkDistTsqr_->QR_produces_R_factor_with_nonnegative_diagonal();
111 factor (MatView< LocalOrdinal, Scalar > R_mine)
113 DistTsqrFactorOutput nodeOutput = nodeDistTsqr_->factor (R_mine);
114 DistTsqrFactorOutput networkOutput = networkDistTsqr_->factor (R_mine);
115 return std::make_pair (nodeOutput, networkOutput);
119 apply (
const ApplyType& applyType,
120 const LocalOrdinal ncols_C,
121 const LocalOrdinal ncols_Q,
123 const LocalOrdinal ldc_mine,
124 const FactorOutput& factorOutput)
126 if (applyType.transposed())
128 nodeDistTsqr_->apply (applyType, ncols_C, ncols_Q,
129 C_mine, ldc_mine, factorOutput.first);
130 networkDistTsqr_->apply (applyType, ncols_C, ncols_Q,
131 C_mine, ldc_mine, factorOutput.second);
135 networkDistTsqr_->apply (applyType, ncols_C, ncols_Q,
136 C_mine, ldc_mine, factorOutput.second);
137 nodeDistTsqr_->apply (applyType, ncols_C, ncols_Q,
138 C_mine, ldc_mine, factorOutput.first);
143 explicit_Q (
const LocalOrdinal ncols_Q,
145 const LocalOrdinal ldq_mine,
146 const FactorOutput& factorOutput)
148 typedef MatView< LocalOrdinal, Scalar > matview_type;
149 matview_type Q_view (ncols_Q, ncols_Q, Q_mine, ldq_mine, Scalar(0));
150 Q_view.fill (Scalar(0));
152 const rank_type myRank = worldMess_->rank();
155 if (networkMess_->rank() != 0)
157 std::ostringstream os;
158 os <<
"My rank with respect to MPI_COMM_WORLD is 0, but my rank "
159 "with respect to MPI_COMM_NETWORK is nonzero (= "
160 << networkMess_->rank() <<
"). We could deal with this by "
161 "swapping data between those two ranks, but we haven\'t "
162 "implemented that fix yet.";
163 throw std::logic_error (os.str());
165 for (LocalOrdinal j = 0; j < ncols_Q; ++j)
166 Q_view(j, j) = Scalar (1);
168 apply (ApplyType::NoTranspose, ncols_Q, ncols_Q,
169 Q_mine, ldq_mine, factorOutput);
174 dist_tsqr_ptr nodeDistTsqr_, networkDistTsqr_;
179 #endif // __TSQR_Tsqr_TwoLevelDistTsqr_hpp
~TwoLevelDistTsqr()
Destructor.
FactorOutput factor(MatView< LocalOrdinal, Scalar > R_mine)
Compute QR factorization of R factors, one per MPI process.
bool QR_produces_R_factor_with_nonnegative_diagonal() const
Interprocess part of TSQR.
TwoLevelDistTsqr()
Constructor.