Kokkos Node API and Local Linear Algebra Kernels Version of the Day
TbbTsqr_TbbRecursiveTsqr.hpp
00001 //@HEADER
00002 // ************************************************************************
00003 // 
00004 //          Kokkos: Node API and Parallel Node Kernels
00005 //              Copyright (2008) Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 // 
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00038 // 
00039 // ************************************************************************
00040 //@HEADER
00041 
00042 #ifndef __TSQR_TbbRecursiveTsqr_hpp
00043 #define __TSQR_TbbRecursiveTsqr_hpp
00044 
00045 #include <Tsqr_ApplyType.hpp>
00046 #include <Tsqr_CacheBlocker.hpp>
00047 #include <Tsqr_SequentialTsqr.hpp>
00048 #include <TbbTsqr_Partitioner.hpp>
00049 
00050 #include <stdexcept>
00051 #include <string>
00052 #include <utility> // std::pair
00053 #include <vector>
00054 
00057 
00058 namespace TSQR {
00059   namespace TBB {
00060 
00064     template< class LocalOrdinal, class Scalar >
00065     class TbbRecursiveTsqr {
00066     public:
00076       TbbRecursiveTsqr (const size_t num_cores = 1,
00077       const size_t cache_size_hint = 0);
00078 
00082       size_t ncores() const { return ncores_; }
00083 
00088       size_t TEUCHOS_DEPRECATED cache_block_size() const { 
00089   return seq_.cache_size_hint(); 
00090       }
00091 
00093       size_t cache_size_hint() const { return seq_.cache_size_hint(); }
00094 
00096       typedef typename SequentialTsqr<LocalOrdinal, Scalar>::FactorOutput SeqOutput;
00097 
00102       typedef std::vector<std::vector<Scalar> > ParOutput;
00103 
00110       typedef typename std::pair<std::vector<SeqOutput>, ParOutput> FactorOutput;
00111 
00115       void
00116       cache_block (const LocalOrdinal nrows,
00117        const LocalOrdinal ncols, 
00118        Scalar A_out[],
00119        const Scalar A_in[],
00120        const LocalOrdinal lda_in) const;
00121 
00126       void
00127       un_cache_block (const LocalOrdinal nrows,
00128           const LocalOrdinal ncols,
00129           Scalar A_out[],
00130           const LocalOrdinal lda_out,       
00131           const Scalar A_in[]) const;
00132 
00139       FactorOutput 
00140       factor (const LocalOrdinal nrows,
00141         const LocalOrdinal ncols, 
00142         Scalar A[],
00143         const LocalOrdinal lda,
00144         Scalar R[],
00145         const LocalOrdinal ldr,
00146         const bool contiguous_cache_blocks) const;
00147 
00151       void
00152       apply (const std::string& op,
00153        const LocalOrdinal nrows,
00154        const LocalOrdinal ncols_C,
00155        Scalar C[],
00156        const LocalOrdinal ldc,
00157        const LocalOrdinal ncols_Q,
00158        const Scalar Q[],
00159        const LocalOrdinal ldq,
00160        const FactorOutput& factor_output,
00161        const bool contiguous_cache_blocks) const;
00162 
00165       void 
00166       explicit_Q (const LocalOrdinal nrows,
00167       const LocalOrdinal ncols_Q_in,
00168       const Scalar Q_in[],
00169       const LocalOrdinal ldq_in,
00170       const LocalOrdinal ncols_Q_out,
00171       Scalar Q_out[],
00172       const LocalOrdinal ldq_out,
00173       const FactorOutput& factor_output,
00174       const bool contiguous_cache_blocks) const;
00175 
00176     private:
00177       size_t ncores_;
00178       TSQR::SequentialTsqr<LocalOrdinal, Scalar> seq_;
00179       Partitioner<LocalOrdinal, Scalar> partitioner_;
00180 
00181       typedef MatView<LocalOrdinal, Scalar> mat_view;
00182       typedef ConstMatView<LocalOrdinal, Scalar> const_mat_view;
00183       typedef std::pair<const_mat_view, const_mat_view> const_split_t;
00184       typedef std::pair<mat_view, mat_view> split_t;
00185       typedef std::pair<const_mat_view, mat_view> top_blocks_t;
00186       typedef std::vector<top_blocks_t> array_top_blocks_t;
00187 
00188       void
00189       explicit_Q_helper (const size_t P_first, 
00190        const size_t P_last,
00191        MatView< LocalOrdinal, Scalar >& Q_out,
00192        const bool contiguous_cache_blocks) const;
00193 
00196       MatView<LocalOrdinal, Scalar>
00197       factor_helper (const size_t P_first, 
00198          const size_t P_last,
00199          const size_t depth,
00200          MatView< LocalOrdinal, Scalar > A,
00201          std::vector< SeqOutput >& seq_outputs,
00202          ParOutput& par_outputs,
00203          Scalar R[],
00204          const LocalOrdinal ldr,
00205          const bool contiguous_cache_blocks) const;
00206 
00207       bool
00208       apply_helper_empty (const size_t P_first,
00209         const size_t P_last,
00210         const_mat_view &Q,
00211         mat_view& C) const;
00212 
00216       void
00217       build_partition_array (const size_t P_first,
00218            const size_t P_last,
00219            array_top_blocks_t& top_blocks,
00220            const_mat_view& Q,
00221            mat_view& C,
00222            const bool contiguous_cache_blocks) const;
00223 
00226       void
00227       apply_helper (const size_t P_first, 
00228         const size_t P_last,
00229         const_mat_view Q,
00230         mat_view C,
00231         array_top_blocks_t& top_blocks, 
00232         const FactorOutput& factor_output,
00233         const bool contiguous_cache_blocks) const;
00234 
00238       std::pair< ConstMatView< LocalOrdinal, Scalar >, MatView< LocalOrdinal, Scalar > >
00239       apply_transpose_helper (const std::string& op,
00240             const size_t P_first, 
00241             const size_t P_last,
00242             const_mat_view Q,
00243             mat_view C,
00244             const FactorOutput& factor_output,
00245             const bool contiguous_cache_blocks) const;
00246 
00247       void 
00248       factor_pair (const size_t P_top,
00249        const size_t P_bot,
00250        mat_view& A_top,
00251        mat_view& A_bot,
00252        std::vector< std::vector< Scalar > >& par_outputs,
00253        const bool contiguous_cache_blocks) const;
00254 
00255       void
00256       apply_pair (const std::string& trans,
00257       const size_t P_top,
00258       const size_t P_bot,
00259       const_mat_view& Q_bot,
00260       const std::vector< std::vector< Scalar > >& tau_arrays,
00261       mat_view& C_top,
00262       mat_view& C_bot,
00263       const bool contiguous_cache_blocks) const;
00264 
00265       void 
00266       cache_block_helper (MatView< LocalOrdinal, Scalar >& A_out,
00267         ConstMatView< LocalOrdinal, Scalar >& A_in,
00268         const size_t P_first,
00269         const size_t P_last) const;
00270 
00271       void 
00272       un_cache_block_helper (MatView< LocalOrdinal, Scalar >& A_out,
00273            const ConstMatView< LocalOrdinal, Scalar >& A_in,
00274            const size_t P_first,
00275            const size_t P_last) const;
00276 
00277     }; // class TbbRecursiveTsqr
00278   } // namespace TBB
00279 } // namespace TSQR
00280 
00281 #include <TSQR/TBB/TbbRecursiveTsqr_Def.hpp>
00282 
00283 #endif // __TSQR_TbbRecursiveTsqr_hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends