tab to space tbb_task_scheduler_init.cpp
This commit is contained in:
@@ -12,43 +12,43 @@ VIM: let b:ldlibpath=g:Bboost.g:Btbb
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Conclusion:
|
* Conclusion:
|
||||||
* The first task_sheduler_init is configuring number of threads in
|
* The first task_sheduler_init is configuring number of threads in
|
||||||
* the thread pool. If the task scheduler initialised implicitly then
|
* the thread pool. If the task scheduler initialised implicitly then
|
||||||
* the number of threads is the number of cores. To ensure uncomment
|
* the number of threads is the number of cores. To ensure uncomment
|
||||||
* the commented line below.
|
* the commented line below.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int main ( void )
|
int main ( void )
|
||||||
{try{
|
{try{
|
||||||
|
|
||||||
std::vector<int> v(1024*1024);
|
std::vector<int> v(1024*1024);
|
||||||
//tbb::enumerable_thread_specific<int> count;
|
//tbb::enumerable_thread_specific<int> count;
|
||||||
tbb::task_scheduler_init init3(5);
|
tbb::task_scheduler_init init3(5);
|
||||||
tbb::task_scheduler_init init(10);
|
tbb::task_scheduler_init init(10);
|
||||||
tbb::task_scheduler_init init2(1);
|
tbb::task_scheduler_init init2(1);
|
||||||
tbb::enumerable_thread_specific<int> count;
|
tbb::enumerable_thread_specific<int> count;
|
||||||
tbb::parallel_for_each( v.begin(), v.end(), [&count](int& v){
|
tbb::parallel_for_each( v.begin(), v.end(), [&count](int& v){
|
||||||
++count.local();
|
++count.local();
|
||||||
});
|
});
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for ( int c : count )
|
for ( int c : count )
|
||||||
{
|
{
|
||||||
std::cout << "Thread: " << ++i << " counted " << c << std::endl;
|
std::cout << "Thread: " << ++i << " counted " << c << std::endl;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
catch ( const std::exception& e )
|
catch ( const std::exception& e )
|
||||||
{
|
{
|
||||||
std::cerr << std::endl
|
std::cerr << std::endl
|
||||||
<< "std::exception(\"" << e.what() << "\")." << std::endl;
|
<< "std::exception(\"" << e.what() << "\")." << std::endl;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
catch ( ... )
|
catch ( ... )
|
||||||
{
|
{
|
||||||
std::cerr << std::endl
|
std::cerr << std::endl
|
||||||
<< "unknown exception." << std::endl;
|
<< "unknown exception." << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user