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 ;红色部分不能识别,实在想不出是什么原因,求教各位。在多核板块问了,居然没人回答我。各位帮忙呀。
...全文
62 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
woaixinrong 2010-08-06
  • 打赏
  • 举报
回复
已经确定include库文件的了。[Quote=引用 2 楼 weichaojie 的回复:]
是不是头文件没有包含,或者是有库没有包含,不能识别一般是找不到声明引起的吧。
[/Quote]
weichaojie 2010-08-06
  • 打赏
  • 举报
回复
是不是头文件没有包含,或者是有库没有包含,不能识别一般是找不到声明引起的吧。
woaixinrong 2010-08-06
  • 打赏
  • 举报
回复
这里怎么也没人回答我呀,呀呀呀
深度学习之卷积神经网络CNN做手写体识别的VS代码。支持linux本和VS2012本。 tiny-cnn: A C++11 implementation of convolutional neural networks ======== tiny-cnn is a C++11 implementation of convolutional neural networks. design principle ----- * fast, without GPU 98.8% accuracy on MNIST in 13 minutes training (@Core i7-3520M) * header only, policy-based design supported networks ----- ### layer-types * fully-connected layer * convolutional layer * average pooling layer ### activation functions * tanh * sigmoid * rectified linear * identity ### loss functions * cross-entropy * mean-squared-error ### optimization algorithm * stochastic gradient descent (with/without L2 normalization) * stochastic gradient levenberg marquardt dependencies ----- * boost C++ library * Intel TBB sample code ------ ```cpp #include "tiny_cnn.h" using namespace tiny_cnn; // specify loss-function and optimization-algorithm typedef network CNN; // tanh, 32x32 input, 5x5 window, 1-6 feature-maps convolution convolutional_layer C1(32, 32, 5, 1, 6); // tanh, 28x28 input, 6 feature-maps, 2x2 subsampling average_pooling_layer S2(28, 28, 6, 2); // fully-connected layers fully_connected_layer F3(14*14*6, 120); fully_connected_layer F4(120, 10); // connect all CNN mynet; mynet.add(&C1); mynet.add(&S2); mynet.add(&F3); mynet.add(&F4); assert(mynet.in_dim() == 32*32); assert(mynet.out_dim() == 10); ``` more sample, read main.cpp build sample program ------ ### gcc(4.6~) without tbb ./waf configure --BOOST_ROOT=your-boost-root ./waf build with tbb ./waf configure --TBB --TBB_ROOT=your-tbb-root --BOOST_ROOT=your-boost-root ./waf build with tbb and SSE/AVX ./waf configure --AVX --TBB --TBB_ROOT=your-tbb-root --BOOST_ROOT=your-boost-root ./waf build ./waf configure --SSE --TBB --TBB_ROOT=your-tbb-root --BOOST_ROOT=your-boost-root ./waf build or edit inlude/config.h to customize default behavior. ### vc(2012~) open vc/tiny_cnn.sln and build in release mode.

64,648

社区成员

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

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