加为好友
发送私信
在线聊天
发表于:2008-04-01 09:11:43 4 楼 得分:0
抛砖引玉,详析部分代码从parall_for.h namespace tbb { //! @cond INTERNAL namespace internal { //! Task type used in parallel_for /** @ingroup algorithms */ template <typename Range, typename Body, typename Partitioner=simple_partitioner> class start_for: public task { // class “start_for" 私有数据 Range my_range; const Body my_body; Partitioner my_partitioner; /*override*/ task* execute(); public: start_for( const Range& range, const Body& body, const Partitioner &partitioner ) : my_range(range), my_body(body), my_partitioner(partitioner) // class "start_for" 构造函数 { } }; template <typename Range, typename Body, typename Partitioner> task* start_for <Range,Body,Partitioner>::execute() { // "start_for" 执行部分 for "Range" if( my_partitioner.should_execute_range(my_range, *this) ) { my_body( my_range ); // 直接执行 return NULL; } else { empty_task& c = *new( allocate_continuation() ) empty_task; recycle_as_child_of(c); // 回收作为子任务 c.set_ref_count(2); start_for& b = *new( c.allocate_child() ) start_for(Range(my_range,split()),my_body,Partitioner(my_partitioner,split())); // 嵌套使用class "start_for"作为子任务 c.spawn(b); return this; } } } // namespace internal //! @endcond
修改
删除
举报
引用
回复