|
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_FillWithZerosTask_hpp 00030 #define __TSQR_TBB_FillWithZerosTask_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 FillWithZerosTask : public tbb::task { 00044 private: 00045 typedef MatView< LocalOrdinal, Scalar > mat_view; 00046 typedef std::pair< mat_view, mat_view > split_type; 00047 00048 public: 00049 FillWithZerosTask (const size_t P_first, 00050 const size_t P_last, 00051 MatView< LocalOrdinal, Scalar > C, 00052 const SequentialTsqr< LocalOrdinal, Scalar >& seq, 00053 const bool contiguous_cache_blocks = false) 00054 : P_first_ (P_first), 00055 P_last_ (P_last), 00056 C_ (C), 00057 seq_ (seq), 00058 contiguous_cache_blocks_ (contiguous_cache_blocks) 00059 {} 00060 00061 tbb::task* 00062 execute () 00063 { 00064 if (P_first_ > P_last_ || C_.empty()) 00065 return NULL; 00066 else if (P_first_ == P_last_) 00067 { 00068 // Fill my partition with zeros. 00069 seq_.fill_with_zeros (C_.nrows(), C_.ncols(), C_.get(), 00070 C_.lda(), contiguous_cache_blocks_); 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_type C_split = 00081 partitioner_.split (C_, P_first_, P_mid, P_last_, 00082 contiguous_cache_blocks_); 00083 FillWithZerosTask& topTask = *new( c.allocate_child() ) 00084 FillWithZerosTask (P_first_, P_mid, C_split.first, seq_, 00085 contiguous_cache_blocks_); 00086 FillWithZerosTask& botTask = *new( c.allocate_child() ) 00087 FillWithZerosTask (P_mid+1, P_last_, C_split.second, seq_, 00088 contiguous_cache_blocks_); 00089 00090 // Set reference count of parent (in this case, the 00091 // continuation task) to 2 (since 2 children -- no 00092 // additional task since no waiting). 00093 c.set_ref_count (2); 00094 c.spawn (botTask); 00095 return &topTask; // scheduler bypass optimization 00096 } 00097 } 00098 00099 private: 00100 size_t P_first_, P_last_; 00101 mat_view C_; 00102 SequentialTsqr< LocalOrdinal, Scalar > seq_; 00103 Partitioner< LocalOrdinal, Scalar > partitioner_; 00104 bool contiguous_cache_blocks_; 00105 }; 00106 } // namespace TBB 00107 } // namespace TSQR 00108 00109 00110 #endif // __TSQR_TBB_FillWithZerosTask_hpp
1.7.4