Anasazi Version of the Day
TbbTsqr_CacheBlockTask.hpp
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //                 Anasazi: Block Eigensolvers Package
00005 //                 Copyright (2010) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00025 //
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #ifndef __TSQR_TBB_CacheBlockTask_hpp
00030 #define __TSQR_TBB_CacheBlockTask_hpp
00031 
00032 #include <tbb/task.h>
00033 #include <TbbTsqr_Partitioner.hpp>
00034 #include <Tsqr_SequentialTsqr.hpp>
00035 
00038 
00039 namespace TSQR {
00040   namespace TBB {
00041     
00042     template< class LocalOrdinal, class Scalar >
00043     class CacheBlockTask : public tbb::task {
00044     public:
00045       typedef MatView< LocalOrdinal, Scalar > mat_view;
00046       typedef ConstMatView< LocalOrdinal, Scalar > const_mat_view;
00047       typedef std::pair< mat_view, mat_view > split_t;
00048       typedef std::pair< const_mat_view, const_mat_view > const_split_t;
00049 
00050       CacheBlockTask (const size_t P_first__, 
00051           const size_t P_last__,
00052           mat_view& A_out,
00053           const_mat_view& A_in,
00054           const SequentialTsqr< LocalOrdinal, Scalar >& seq) :
00055   P_first_ (P_first__), 
00056   P_last_ (P_last__), 
00057   A_out_ (A_out), 
00058   A_in_ (A_in), 
00059   seq_ (seq)
00060       {}
00061 
00062       tbb::task* execute () {
00063   using tbb::task;
00064 
00065   if (P_first_ > P_last_ || A_out_.empty() || A_in_.empty())
00066     return NULL;
00067   else if (P_first_ == P_last_)
00068     {
00069       seq_.cache_block (A_out_.nrows(), A_out_.ncols(), 
00070             A_out_.get(), A_in_.get(), A_in_.lda());
00071       return NULL;
00072     }
00073   else
00074     {
00075       // "c": continuation task
00076       tbb::empty_task& c = *new( allocate_continuation() ) tbb::empty_task;
00077 
00078       // Recurse on two intervals: [P_first, P_mid] and [P_mid+1, P_last]
00079       const size_t P_mid = (P_first_ + P_last_) / 2;
00080       split_t out_split = 
00081         partitioner_.split (A_out_, P_first_, P_mid, P_last_, true);
00082       const_split_t in_split = 
00083         partitioner_.split (A_in_, P_first_, P_mid, P_last_, false);
00084 
00085       CacheBlockTask& topTask = *new( c.allocate_child() )
00086         CacheBlockTask (P_first_, P_mid, out_split.first, 
00087             in_split.first, seq_);
00088       CacheBlockTask& botTask = *new( c.allocate_child() )
00089         CacheBlockTask (P_mid+1, P_last_, out_split.second, 
00090             in_split.second, seq_);
00091       // Set reference count of parent (in this case, the
00092       // continuation task) to 2 (since 2 children -- no
00093       // additional task since no waiting).
00094       c.set_ref_count (2);
00095       c.spawn (botTask);
00096       return &topTask; // scheduler bypass optimization
00097     }
00098       }
00099 
00100     private:
00101       size_t P_first_, P_last_;
00102       mat_view A_out_;
00103       const_mat_view A_in_;
00104       SequentialTsqr< LocalOrdinal, Scalar > seq_;
00105       Partitioner< LocalOrdinal, Scalar > partitioner_;
00106     };
00107 
00108   } // namespace TBB
00109 } // namespace TSQR
00110 
00111 
00112 #endif // __TSQR_TBB_CacheBlockTask_hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends