A thread scheduler test and a similar test for TBB.
This commit is contained in:
44
tbb_task_scheduler_init.cpp
Normal file
44
tbb_task_scheduler_init.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/* Check cf5-opt.vim defs.
|
||||
VIM: let g:lcppflags="-std=c++11 -O2"
|
||||
VIM: let g:cppflags=g:tbb." -ltbbmalloc -ltbbmalloc_proxy"
|
||||
VIM: let g:ldlibpath=g:tbbld
|
||||
*/
|
||||
#include <tbb/enumerable_thread_specific.h>
|
||||
#include <tbb/task_scheduler_init.h>
|
||||
#include <tbb/parallel_for_each.h>
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
#include <vector>
|
||||
|
||||
int main ( void )
|
||||
{try{
|
||||
|
||||
std::vector<int> v(1024*1024*1024);
|
||||
tbb::task_scheduler_init init3(20);
|
||||
tbb::task_scheduler_init init(10);
|
||||
tbb::task_scheduler_init init2(1);
|
||||
tbb::enumerable_thread_specific<int> count;
|
||||
tbb::parallel_for_each( v.begin(), v.end(), [&count](int& v){
|
||||
++count.local();
|
||||
});
|
||||
|
||||
int i = 0;
|
||||
for ( int c : count )
|
||||
{
|
||||
std::cout << "Thread: " << ++i << " counted " << c << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
catch ( const std::exception& e )
|
||||
{
|
||||
std::cerr << std::endl
|
||||
<< "std::exception(\"" << e.what() << "\")." << std::endl;
|
||||
return 2;
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
std::cerr << std::endl
|
||||
<< "unknown exception." << std::endl;
|
||||
return 1;
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user