10 #ifndef __TSQR_Tsqr_TwoLevelDistTsqr_hpp
11 #define __TSQR_Tsqr_TwoLevelDistTsqr_hpp
13 #include <Tsqr_DistTsqr.hpp>
14 #include <Tsqr_MpiCommFactory.hpp>
28 template<
class LocalOrdinal,
30 class DistTsqrType = DistTsqr< LocalOrdinal, Scalar > >
33 typedef Scalar scalar_type;
34 typedef LocalOrdinal ordinal_type;
35 typedef DistTsqrType dist_tsqr_type;
36 typedef typename dist_tsqr_type::rank_type rank_type;
38 typedef typename dist_tsqr_type::FactorOutput DistTsqrFactorOutput;
39 typedef std::pair< DistTsqrFactorOutput, DistTsqrFactorOutput > FactorOutput;
44 worldMess_ (TSQR::MPI::makeMpiCommWorld()),
45 nodeDistTsqr_ (TSQR::MPI::makeMpiCommNode()),
46 networkDistTsqr_ (TSQR::MPI::makeMpiCommNetwork())
57 return nodeDistTsqr_->QR_produces_R_factor_with_nonnegative_diagonal() &&
58 networkDistTsqr_->QR_produces_R_factor_with_nonnegative_diagonal();
79 factor (MatView< LocalOrdinal, Scalar > R_mine)
81 DistTsqrFactorOutput nodeOutput = nodeDistTsqr_->factor (R_mine);
82 DistTsqrFactorOutput networkOutput = networkDistTsqr_->factor (R_mine);
83 return std::make_pair (nodeOutput, networkOutput);
87 apply (
const ApplyType& applyType,
88 const LocalOrdinal ncols_C,
89 const LocalOrdinal ncols_Q,
91 const LocalOrdinal ldc_mine,
92 const FactorOutput& factorOutput)
94 if (applyType.transposed())
96 nodeDistTsqr_->apply (applyType, ncols_C, ncols_Q,
97 C_mine, ldc_mine, factorOutput.first);
98 networkDistTsqr_->apply (applyType, ncols_C, ncols_Q,
99 C_mine, ldc_mine, factorOutput.second);
103 networkDistTsqr_->apply (applyType, ncols_C, ncols_Q,
104 C_mine, ldc_mine, factorOutput.second);
105 nodeDistTsqr_->apply (applyType, ncols_C, ncols_Q,
106 C_mine, ldc_mine, factorOutput.first);
111 explicit_Q (
const LocalOrdinal ncols_Q,
113 const LocalOrdinal ldq_mine,
114 const FactorOutput& factorOutput)
116 typedef MatView< LocalOrdinal, Scalar > matview_type;
117 matview_type Q_view (ncols_Q, ncols_Q, Q_mine, ldq_mine, Scalar(0));
118 Q_view.fill (Scalar(0));
120 const rank_type myRank = worldMess_->rank();
123 if (networkMess_->rank() != 0)
125 std::ostringstream os;
126 os <<
"My rank with respect to MPI_COMM_WORLD is 0, but my rank "
127 "with respect to MPI_COMM_NETWORK is nonzero (= "
128 << networkMess_->rank() <<
"). We could deal with this by "
129 "swapping data between those two ranks, but we haven\'t "
130 "implemented that fix yet.";
131 throw std::logic_error (os.str());
133 for (LocalOrdinal j = 0; j < ncols_Q; ++j)
134 Q_view(j, j) = Scalar (1);
136 apply (ApplyType::NoTranspose, ncols_Q, ncols_Q,
137 Q_mine, ldq_mine, factorOutput);
142 dist_tsqr_ptr nodeDistTsqr_, networkDistTsqr_;
147 #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.