tbb的应用问题,大家帮帮忙呀(冷清的多核版居然没人回答我)

woaixinrong 2010-08-05 11:27:06

#include "tbb/task.h"
#include "tbb/task_scheduler_init.h"
#include <stdio.h>
#include <stdlib.h>

//! Some busywork
void TwiddleThumbs( const char * message, int n ) {
for( int i=0; i<n; ++i ) {
printf(" %s: i=%d\n",message,i);
static volatile int x;
for( int j=0; j<20000000; ++j )
++x;
}
}

//! SideShow task
class SideShow: public tbb::task {
tbb::task* execute() {
TwiddleThumbs("Sideshow task",4);
return NULL;
}
};

//! Start up a SideShow task.
//! Return pointer to dummy task that acts as parent of the SideShow.
tbb::empty_task* StartSideShow() {
tbb::empty_task* parent = new( tbb::task::allocate_root() ) tbb::empty_task;
// 2 = 1 for SideShow and C
parent->set_ref_count(2);
SideShow* s = new( parent->allocate_child() ) SideShow;
parent->spawn(*s);
return parent;
}

//! Wait for SideShow task. Argument is dummy parent of the SideShow.
void WaitForSideShow( tbb::empty_task* parent ) {
parent->wait_for_all();
// parent not actually run, so we need to destroy it explicitly.
// (If you forget this line, the debug version of tbb reports a task leak.)
parent->destroy(*parent);
}

//! Optional command-line argument is number of threads to use. Default is 2.
int main( int argc, char* argv[] ) {
tbb::task_scheduler_init init( argc>1 ? strtol(argv[1],0,0) : 2 );
// Loop over n tests various cases where SideShow/Main finish twiddling first.
for( int n=3; n<=5; ++n ) {
printf("\ntest with n=%d\n",n);

// Start up a Sideshow task
tbb::empty_task* e = StartSideShow();

// Do some useful work
TwiddleThumbs("master",n);

// Wait for Sideshow task to complete
WaitForSideShow(e);
}
return 0;
}


这是intel threading budilding blocks中的一个例程。运行没有问题,但是我将其中相应的代码复制我到我的mfc工程中,发现tbb::empty_task* parent = new ( tbb::task::allocate_root() ) tbb::empty_task;和SideShow* s = new ( parent->allocate_child() )SideShow ;红色部分不能识别,实在想不出是什么原因,求教各位。在多核板块问了,居然没人回答我。各位帮忙呀。
...全文
71 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
woaixinrong 2010-08-06
  • 打赏
  • 举报
回复
已经确定include库文件的了。[Quote=引用 2 楼 weichaojie 的回复:]
是不是头文件没有包含,或者是有库没有包含,不能识别一般是找不到声明引起的吧。
[/Quote]
weichaojie 2010-08-06
  • 打赏
  • 举报
回复
是不是头文件没有包含,或者是有库没有包含,不能识别一般是找不到声明引起的吧。
woaixinrong 2010-08-06
  • 打赏
  • 举报
回复
这里怎么也没人回答我呀,呀呀呀

65,190

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧