首先下载:
http://www.threadingbuildingblocks.org/uploads/77/111/2.1/tbb21_20080605oss_win.zip
当前是2.1版本
解压到c盘,打开vs2005,设置vc++的项目目录
include:
C:\tbb21oss_win\include
执行文件:
C:\tbb21oss_win\ia32\vc8\bin
库文件:
C:\tbb21oss_win\ia32\vc8\lib
最后设置 我的电脑--环境变量设置
添加下面到path部分的最前面,记得加上一个“;”:C:\tbb21oss_win\ia32\vc8\bin
然后添加一个变量:
TBB21_INSTALL_DIR 为C:\tbb21oss_win
开启vs2005的命令行工具,进入到C:\tbb21oss_win\ia32\vc8\bin路径,执行tbbvars.bat文件
可以开始第一个程序了,记得带上tbb.lib对应的是release编译模式
-
-
-
-
-
-
#include"tbb/pipeline.h"
-
#include"tbb/tick_count.h"
-
#include"tbb/task_scheduler_init.h"
-
#include<cstring>
-
#include<cstdlib>
-
#include<cstdio>
-
#include<cctype>
-
usingnamespacestd;
-
-
classMyBuffer{
-
staticconstsize_tbuffer_size=10000;
-
char*my_end;
-
-
charstorage[1+buffer_size];
-
public:
-
-
char*begin(){returnstorage+1;}
-
constchar*begin()const{returnstorage+1;}
-
-
char*end()const{returnmy_end;}
-
-
voidset_end(char*new_ptr){my_end=new_ptr;}
-
-
size_tmax_size()const{returnbuffer_size;}
-
-
size_tsize()const{returnmy_end-begin();}
- };
-
classMyInputFilter:publictbb::filter{
-
public:
-
staticconstsize_tn_buffer=8;
- MyInputFilter(FILE*input_file_);
-
private:
- FILE*input_file;
- size_tnext_buffer;
-
charlast_char_of_previous_buffer;
- MyBufferbuffer[n_buffer];
-
void*operator()(void*);
- };
- MyInputFilter::MyInputFilter(FILE*input_file_):
-
filter(true),
- next_buffer(0),
- input_file(input_file_),
-
last_char_of_previous_buffer('')
- {
- }
-
void*MyInputFilter::operator()(void*){
- MyBuffer&b=buffer[next_buffer];
- next_buffer=(next_buffer+1)%n_buffer;
- size_tn=fread(b.begin(),1,b.max_size(),input_file);
-
if(!n){
-
-
returnNULL;
-
}else{
- b.begin()[-1]=last_char_of_previous_buffer;
- last_char_of_previous_buffer=b.begin()[n-1];
- b.set_end(b.begin()+n);
-
return&b;
- }
- }
-
-
classMyTransformFilter:publictbb::filter{
-
public:
- MyTransformFilter();
-
void*operator()(void*item);
- };
- MyTransformFilter::MyTransformFilter():
-
tbb::filter(false)
- {}
-
void*MyTransformFilter::operator()(void*item){
- MyBuffer&b=*static_cast<MyBuffer*>(item);
-
intprev_char_is_space=b.begin()[-1]=='';
-
for(char*s=b.begin();s!=b.end();++s){
-
if(prev_char_is_space&&islower((unsignedchar)*s))
- *s=toupper(*s);
-
prev_char_is_space=isspace((unsignedchar)*s);
- }
-
return&b;
- }
-
-
classMyOutputFilter:publictbb::filter{
- FILE*my_output_file;
-
public:
- MyOutputFilter(FILE*output_file);
-
void*operator()(void*item);
- };
- MyOutputFilter::MyOutputFilter(FILE*output_file):
-
tbb::filter(true),
- my_output_file(output_file)
- {
- }
-
void*MyOutputFilter::operator()(void*item){
- MyBuffer&b=*static_cast<MyBuffer*>(item);
- fwrite(b.begin(),1,b.size(),my_output_file);
-
returnNULL;
- }
-
staticintNThread=tbb::task_scheduler_init::automatic;
-
staticconstchar*InputFileName="input.txt";
-
staticconstchar*OutputFileName="output.txt";
-
staticboolis_number_of_threads_set=false;
-
voidUsage()
- {
-
fprintf(stderr,"Usage:\ttext_filter[input-file[output-file[nthread]]]\n");
- }
-
intParseCommandLine(intargc,char*argv[]){
-
-
if(argc>4){
- Usage();
-
return0;
- }
-
if(argc>=2)InputFileName=argv[1];
-
if(argc>=3)OutputFileName=argv[2];
-
if(argc>=4){
- NThread=strtol(argv[3],0,0);
-
if(NThread<1){
-
fprintf(stderr,"nthreadsetto%d,butmustbeatleast1\n",NThread);
-
return0;
- }
-
is_number_of_threads_set=true;
- }
-
return1;
- }
-
intrun_pipeline(intnthreads)
- {
-
FILE*input_file=fopen(InputFileName,"r");
-
if(!input_file){
- perror(InputFileName);
- Usage();
-
return0;
- }
-
FILE*output_file=fopen(OutputFileName,"w");
-
if(!output_file){
- perror(OutputFileName);
-
return0;
- }
-
- tbb::pipelinepipeline;
-
- MyInputFilterinput_filter(input_file);
- pipeline.add_filter(input_filter);
-
- MyTransformFiltertransform_filter;
- pipeline.add_filter(transform_filter);
-
- MyOutputFilteroutput_filter(output_file);
- pipeline.add_filter(output_filter);
-
- tbb::tick_countt0=tbb::tick_count::now();
- pipeline.run(MyInputFilter::n_buffer);
- tbb::tick_countt1=tbb::tick_count::now();
-
- pipeline.clear();
- fclose(output_file);
- fclose(input_file);
-
if(is_number_of_threads_set){
-
printf("threads=%dtime=%g\n",nthreads,(t1-t0).seconds());
-
}else{
-
if(nthreads==1){
-
printf("serialruntime=%g\n",(t1-t0).seconds());
-
}else{
-
printf("parallelruntime=%g\n",(t1-t0).seconds());
- }
- }
-
return1;
- }
-
intmain(intargc,char*argv[]){
-
if(!ParseCommandLine(argc,argv))
-
return1;
-
if(is_number_of_threads_set){
-
- tbb::task_scheduler_initinit(NThread);
-
if(!run_pipeline(NThread))
-
return1;
-
}else{
-
{
- tbb::task_scheduler_initinit_serial(1);
-
if(!run_pipeline(1))
-
return1;
- }
-
{
- tbb::task_scheduler_initinit_parallel;
-
if(!run_pipeline(0))
-
return1;
- }
- }
-
return0;
- }
第二个程序,对应debug模式,带上tbb_debug.lib:
-
#include"tbb/task_scheduler_init.h"
-
#include"tbb/blocked_range.h"
-
#include"tbb/parallel_for.h"
-
-
-
usingnamespacetbb;
-
-
voidFoo(floatvalue)
- {
-
printf("%.2f\n",value);
- }
-
classApplyFoo
- {
-
float*constmy_a;
-
public:
-
voidoperator()(constblocked_range<size_t>&r)const
- {
-
float*a=my_a;
-
for(size_ti=r.begin();i!=r.end();++i)
- Foo(a[i]);
- }
-
ApplyFoo(floata[]):my_a(a){}
- };
-
int_tmain(intargc,_TCHAR*argv[])
- {
-
-
- task_scheduler_initinit;
-
floata[100];
-
for(inti=0;i<100;i++)
-
a[i]=(float)i;
-
-
- parallel_for(blocked_range<size_t>(0,100),ApplyFoo(a));
-
return0;
- }
分享到:
相关推荐
intel弄的多线程C++开发库,挺漂亮的,值得一用
TBB,Thread Building Blocks,线程构建模块,是Intel公司开发的并行编程开发的工具。 OSCON 上,Intel 宣布,Threading Building Blocks,Intel 众多软件开发工具中的一个,open source了。协议是 GPLv2。 TBB 获得过...
TBB,Thread Building Blocks,线程构建模块,是Intel公司开发的并行编程开发的工具。 OSCON 上,Intel 宣布,Threading Building Blocks,Intel 众多软件开发工具中的一个,open source了。协议是 GPLv2。 TBB 获得过...
tbb, Intel r5与CMake构建系统 Intel(R) 线程生成块 这是目前基于TBB更新,并且将不时更新以跟踪最新版本的git知识库。 唯一的修改是添加基于的构建系统。因为r5可以很容易地使用git子模块和简单的add_subdirectory ...
TBB,Thread Building Blocks,线程构建模块,是Intel公司开发的并行编程开发的工具。 OSCON 上,Intel 宣布,Threading Building Blocks,Intel 众多软件开发工具中的一个,open source了。协议是 GPLv2。 TBB 获得过...
在多核的平台上开发并行化的程序,必须合理地利用系统的资源 - 如与内核数目相匹配的线程,内存的合理访问...d)线程库的接口适合于跨平台的移植(Linux, Windows, Mac) e)支持的C++编译器 – Microsoft, GNU and Intel
TBB是Intel公司的用于C++多线程和并行计算程序的库文件,该书是2019年新版,内容是英文版的,请注意下载。
并基于Intel同构多核平台,运用intel并行时库TBB(Intel Thread Building Blocks)进行相应的并行化改造,并在调试和优化阶段运用Intel Thread Checker(线程检测器)检测发现看似正确的程序的潜在错误。实验结果表明,...
TBB 2021.7.0版本windows x64运行库
本文是基于为实施Burrows-Wheeler转换(BWT)算法提供并行可伸缩代码的示例使用C ++的英特尔:registered:线程构建模块(TBB)和OpenMP库的实用指南。
标准版编译器和专业版有着相同的效能和特性, 但是不提供多线程库。 特性: -------------------------------------------------------------------------------- 效能: 考虑使用Intel C++编译器专业版来最佳化效能。...
RcppParallel支持Intel TBB的新接口,并且可以使用TBB_LIB和TBB_INC环境变量配置为使用TBB的外部副本(例如,带有或系统TBB库)。 使用构建RcppParallel的开发版本: 安装 。 例如,在Linux 64位( x86_64 ) ...
本课程使用线程构建模块更详细地探讨并行性。 您将在一个比CW1更复杂的示例中看到线性加速,即性能与CPU内核数成正比。 该发行版包含一个用于创建和使用傅立叶变换的基本对象框架,以及两个实现: 直接傅立叶变换,...
InertialFlowCutter 算法的 C++ 实现...要编译代码,您需要最新的 C++14 编译器(例如 g++ 版本 >= 8.2)和英特尔线程构建模块 (TBB) 库。您还需要 readline 库https://tiswww.case.edu/php/chet/readline/rltop.html。
FFT算法的一些想法,主要是对不同库(例如OpenMP,Intel TBB,OpenCL和C ++ 11线程)的性能进行基准测试。 摘自Wikipedia:“以JW Cooley和John Tukey命名的Cooley-Tukey算法是最常见的快速傅立叶变换(FFT)算法。...
基于Intel并行库TBB(线程构建模块)和OpenMP运行时库函数,对多核平台下的串行程序进行循环并行化和任务分配的并行化设计。 并行性主要是指同时性或并发性,并行处理是指对一种相对于串行处理的处理方式,它着重...
基于Intel并行库TBB(线程构建模块)和OpenMP运行时库函数,对多核平台下的串行程序进行循环并行化和任务分配的并行化设计。 并行性主要是指同时性或并发性,并行处理是指对一种相对于串行处理的处理方式,它着重...
使用Intel Parallel Amplifier高性能工具,针对模糊C均值聚类算法在多核平台的性能问题,找...基于Intel并行库TBB(线程构建模块)和OpenMP运行时库函数,对多核平台下的串行程序进行循环并行化和任务分配的并行化设计。
英特尔TBB:线程构建基块 Kokkos:用于在 HPC 平台上编写高性能便携式应用程序的 C++ 编程模型 OpenMP:C/C++ 和 Fortran 中的多平台共享内存并行编程 RaftLib:用于启用流和数据流并行计算的 C++ 库 STAPL:C++ 中...
TBB(英特尔(R)线程构建模块)版本4.1或更高版本( ) cmake( ) C ++编译器:g ++> = 4.4,icc> = 11.0,Microsoft Visual Studio *> = 10(2010) make(Linux *),nmake或Microsoft Visual Studio *...