Apress / pro-TBB

Source Code for 'Pro TBB: C++ Parallel Programming with Threading Building Blocks' by Michael Voss, Rafael Asenjo, and James Reinders
https://www.apress.com/us/book/9781484243978
Other
171 stars 46 forks source link

error: no matching function for call to ‘for_each Chapter1/fig_1_05.cpp #1

Open NguyenVanThanhHust opened 4 years ago

NguyenVanThanhHust commented 4 years ago

I can't build pstl library so that i use prebuilt from intel: https://github.com/intel/tbb/releases

I replace 2 line from: #include <pstl/algorithm> #include <pstl/execution>

to #include <pstl/experimental/algorithm> #include <pstl/internal/algorithm_impl.h>

Error i encounter is: figure_1_05.cpp: In function ‘int main()’: figure_1_05.cpp:10:3: error: no matching function for call to ‘for_each(const pstl::execution::v1::parallel_policy&, std::vector<std::__cxx11::basic_string<char> >::iterator, std::vector<std::__cxx11::basic_string<char> >::iterator, main()::<lambda(std::__cxx11::string&)>)’ ); ^ In file included from /usr/include/c++/5/algorithm:62:0, from /usr/local/include/pstl/experimental/internal/reduction_impl.h:20, from /usr/local/include/pstl/experimental/internal/reduction.h:23, from /usr/local/include/pstl/experimental/algorithm:21, from figure_1_05.cpp:1: /usr/include/c++/5/bits/stl_algo.h:3761:5: note: candidate: template<class _IIter, class _Funct> _Funct std::for_each(_IIter, _IIter, _Funct) for_each(_InputIterator __first, _InputIterator __last, _Function __f) ^ /usr/include/c++/5/bits/stl_algo.h:3761:5: note: template argument deduction/substitution failed: figure_1_05.cpp:10:3: note: deduced conflicting types for parameter ‘_IIter’ (‘pstl::execution::v1::parallel_policy’ and ‘__gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >’) );

I use Linux: 16.04, g++ : 5.5.0 I'm not C++ expert. Does anyone have any idea what is this error and how can i fix it?

vossmjp commented 4 years ago

If you update the [tbb_install_dir]/bin/tbbvars.sh and [pstl_root_dir]/bin/pstlvars.sh scripts in the pre-built version, replacing the SUBSTITUTE_INSTALL_DIR_HERE properly for each, you can then source the pstlvars.sh script (for example, ". ./pstlvars.sh intel64"). You should then be able to use the original source files unchanged. You should not need to change the #include lines.

After changing the pstlvars.sh file, [pstl_root_dir]/stdlib will be in your CPATH, which will contain pstl/algorithm and pstl/execution.

Please let me know if this does not work for you.

NguyenVanThanhHust commented 4 years ago

I changed 3 file: tbbvars.sh, pstlvars.sh and figure_1_05.cpp

In tbbvars.sh: i changed from TBBROOT=SUBSTITUTE_INSTALL_DIR_HERE to TBBROOT="/home/thanhnv/Downloads/tbb-2020.0-lin/tbb" In pstlvars.sh: i changed from PSTLROOT=SUBSTITUTE_INSTALL_DIR_HERE to PSTLROOT="/home/thanhnv/Downloads/tbb-2020.0-lin/pstl" then i run 2 command: (in this command, i'm in folder tbb-2020.0-lin) source ./tbb/bin/tbbvars.sh intel64 linux auto_tbbroot source ./pstl/bin/pstlvars.sh intel64 auto_pstlroot It doesn't show any error.

Then i compile source code (figure_1_05.cpp) If i keep original (#include <pstl/algorithm>), it shows: figure_1_05.cpp:4:26: fatal error: pstl/algorithm: No such file or directory if i change to #include <pstl/experimental/algorithm>, it shows old error.