fork(3) download
  1. #include <boost/exception/detail/type_info.hpp>
  2. #include <boost/mpl/for_each.hpp>
  3. #include <boost/mpl/vector.hpp>
  4. #include <boost/progress.hpp>
  5. #include <tbb/tbb.h>
  6. #include <iostream>
  7. #include <ostream>
  8. #include <vector>
  9. #include <string>
  10. #include <omp.h>
  11. #include <ppl.h>
  12.  
  13. using namespace boost;
  14. using namespace std;
  15.  
  16. const auto Width = 3264;
  17. const auto Height = 2540*8;
  18.  
  19. struct MS_PPL_For
  20. {
  21. template<typename F,typename Index>
  22. void operator()(Index first,Index last,F f) const
  23. {
  24. concurrency::parallel_for(first,last,f);
  25. }
  26. };
  27.  
  28. struct Intel_TBB_For
  29. {
  30. template<typename F,typename Index>
  31. void operator()(Index first,Index last,F f) const
  32. {
  33. tbb::parallel_for(first,last,f);
  34. }
  35. };
  36.  
  37. struct Native_For
  38. {
  39. template<typename F,typename Index>
  40. void operator()(Index first,Index last,F f) const
  41. {
  42. for(; first!=last; ++first) f(first);
  43. }
  44. };
  45.  
  46. struct OpenMP_For
  47. {
  48. template<typename F,typename Index>
  49. void operator()(Index first,Index last,F f) const
  50. {
  51. #pragma omp parallel for
  52. for(auto i=first; i<last; ++i) f(i);
  53. }
  54. };
  55.  
  56. template<typename T>
  57. struct ConvertBayerToRgbImageAsIs
  58. {
  59. const T* BayerChannel;
  60. T* RgbChannel;
  61. template<typename For>
  62. void operator()(For for_)
  63. {
  64. cout << type_name<For>() << "\t";
  65. progress_timer t;
  66. int offsets[] = {2,1,1,0};
  67. //memset(RgbChannel, 0, Width * Height * 3 * sizeof(T));
  68. for_(0, Height, [&] (int row)
  69. {
  70. for (auto col = 0, bayerIndex = row * Width; col < Width; col++, bayerIndex++)
  71. {
  72. auto offset = (row % 2)*2 + (col % 2); //0...3
  73. auto rgbIndex = bayerIndex * 3 + offsets[offset];
  74. RgbChannel[rgbIndex] = BayerChannel[bayerIndex];
  75. }
  76. });
  77. }
  78. };
  79.  
  80. int main()
  81. {
  82. vector<float> bayer(Width*Height);
  83. vector<float> rgb(Width*Height*3);
  84. ConvertBayerToRgbImageAsIs<float> work = {&bayer[0],&rgb[0]};
  85. for(auto i=0;i!=4;++i)
  86. {
  87. mpl::for_each<mpl::vector<Native_For, OpenMP_For,Intel_TBB_For,MS_PPL_For>>(work);
  88. cout << string(16,'_') << endl;
  89. }
  90. }
  91.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty