STL algorithms and concurrent programming

后端 未结 4 653
无人共我
无人共我 2020-12-08 06:01

Can any of STL algorithms/container operations like std::fill, std::transform be executed in parallel if I enable OpenMP for my compiler? I am working with

4条回答
  •  感情败类
    2020-12-08 06:32

    Current C++ standards don't talk about threads at all, so no. Here is more or less original statement about STL thread safety.

    Edit:

    Look at one common (GCC) implementation of std::fill:

    template
      void
      fill(_ForwardIter __first, _ForwardIter __last, const _Tp& __value)
      {
          for ( ; __first != __last; ++__first)
              *__first = __value; 
      }
    

    It's obvious that it's not safe for parallel execution (which would require specialized implementation.)

    And here is GCC extension for Parallel Mode.

提交回复
热议问题