|
Anasazi Version of the Day
|
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_ExplicitQTask_hpp 00030 #define __TSQR_TBB_ExplicitQTask_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 ExplicitQTask : public tbb::task { 00044 private: 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 public: 00051 ExplicitQTask (const size_t P_first__, 00052 const size_t P_last__, 00053 MatView< LocalOrdinal, Scalar > Q_out, 00054 const SequentialTsqr< LocalOrdinal, Scalar >& seq, 00055 const bool contiguous_cache_blocks) : 00056 P_first_ (P_first__), P_last_ (P_last__), Q_out_ (Q_out), 00057 seq_ (seq), contiguous_cache_blocks_ (contiguous_cache_blocks) 00058 {} 00059 00060 tbb::task* execute () { 00061 if (P_first_ > P_last_ || Q_out_.empty()) 00062 return NULL; 00063 else if (P_first_ == P_last_) 00064 { 00065 // Fill my partition with zeros. 00066 seq_.fill_with_zeros (Q_out_.nrows(), Q_out_.ncols(), Q_out_.get(), 00067 Q_out_.lda(), contiguous_cache_blocks_); 00068 00069 // If our partition is the first (topmost), fill it with 00070 // the first Q_out.ncols() columns of the identity matrix. 00071 if (P_first_ == 0) 00072 { 00073 // Fetch the topmost cache block of my partition. Its 00074 // leading dimension should be set correctly by 00075 // top_block(). 00076 mat_view Q_out_top = seq_.top_block (Q_out_, contiguous_cache_blocks_); 00077 // Set the top block of Q_out to the first ncols 00078 // columns of the identity matrix. 00079 for (LocalOrdinal j = 0; j < Q_out_top.ncols(); ++j) 00080 Q_out_top(j,j) = Scalar(1); 00081 } 00082 return NULL; 00083 } 00084 else 00085 { 00086 // "c": continuation task 00087 tbb::empty_task& c = *new( allocate_continuation() ) tbb::empty_task; 00088 00089 // Recurse on two intervals: [P_first, P_mid] and [P_mid+1, P_last] 00090 const size_t P_mid = (P_first_ + P_last_) / 2; 00091 split_t Q_split = 00092 partitioner_.split (Q_out_, P_first_, P_mid, P_last_, 00093 contiguous_cache_blocks_); 00094 00095 ExplicitQTask& topTask = *new( c.allocate_child() ) 00096 ExplicitQTask (P_first_, P_mid, Q_split.first, seq_, 00097 contiguous_cache_blocks_); 00098 ExplicitQTask& botTask = *new( c.allocate_child() ) 00099 ExplicitQTask (P_mid+1, P_last_, Q_split.second, seq_, 00100 contiguous_cache_blocks_); 00101 00102 // Set reference count of parent (in this case, the 00103 // continuation task) to 2 (since 2 children -- no 00104 // additional task since no waiting). 00105 c.set_ref_count (2); 00106 c.spawn (botTask); 00107 return &topTask; // scheduler bypass optimization 00108 } 00109 } 00110 00111 private: 00112 size_t P_first_, P_last_; 00113 mat_view Q_out_; 00114 SequentialTsqr< LocalOrdinal, Scalar > seq_; 00115 Partitioner< LocalOrdinal, Scalar > partitioner_; 00116 bool contiguous_cache_blocks_; 00117 }; 00118 00119 } // namespace TBB 00120 } // namespace TSQR 00121 00122 00123 #endif // __TSQR_TBB_ExplicitQTask_hpp
1.7.4