未找到具有策略执行的 c++ std::accumulate

c++ std::accumulate with policy execution is not found

我想使用 C++17 的新并行工具,但我的电脑没有。

这行得通:

finalOutline.push_back(std::accumulate(intermediateCoefs.begin(), intermediateCoefs.end(),origin,[](sf::Vector2f prev, sf::Vector2f current) {
            return sf::Vector2f(current.x + prev.x, current.y + prev.y);
        }));

但这不起作用:

finalOutline.push_back(std::accumulate(std::execution::seq, intermediateCoefs.begin(), intermediateCoefs.end(),origin,[](sf::Vector2f prev, sf::Vector2f current) {
            return sf::Vector2f(current.x + prev.x, current.y + prev.y);
        }));

这里是错误信息:

/home/mbs/Bureau/cplusplusWorkspace/sauvegardeGit/compresse-moi-ces-cercles/src/Model.cpp: In member function ‘void Model::computeFinalOutline(int)’:
/home/mbs/Bureau/cplusplusWorkspace/sauvegardeGit/compresse-moi-ces-cercles/src/Model.cpp:246:47: error: no matching function for call to ‘accumulate(const __pstl::execution::v1::sequenced_policy&, std::vector<sf::Vector2<float> >::iterator, std::vector<sf::Vector2<float> >::iterator, sf::Vector2f&, Model::computeFinalOutline(int)::<lambda(sf::Vector2f, sf::Vector2f)>)’
  246 |         finalOutline.push_back(std::accumulate(std::execution::seq, intermediateCoefs.begin(), intermediateCoefs.end(),origin,[](sf::Vector2f prev, sf::Vector2f current) {
      |                                ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  247 |             return sf::Vector2f(current.x + prev.x, current.y + prev.y);
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  248 |         }));
      |         ~~                                     

我确实包括了需要的东西(我猜):

#include <numeric>
#include <execution>

我执行程序时总是显示__cplusplus的版本,它的值是:202002

这是我的 CMAKE 文件(但我认为它没有用):

cmake_minimum_required(VERSION 3.22) # way overkill

project(Taratari)

set (CMAKE_CXX_STANDARD 20) 
set (CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_CXX_FLAGS_DEBUG_INIT "-g -Wall -Wextra -pedantic -Werror") 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++2a") 


include_directories(
    $(PROJECT_SOURCE_DIR)/include
    $(PROJECT_SOURCE_DIR)/src
)

file(GLOB all_SRCS
    "${PROJECT_SOURCE_DIR}/include/*.h"
    "${PROJECT_SOURCE_DIR}/src/*.cpp"
)
    
add_compile_options(
       -mavx
)
    
#sfml
find_package(SFML REQUIRED system graphics network audio window) #too much flag no ?


add_executable(exe ${all_SRCS})

target_link_libraries(exe PRIVATE sfml-audio sfml-graphics sfml-network sfml-system sfml-window) 

可以肯定的是,这里是 gcc -v :

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.1.0-1ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --disable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-2V7zgg/gcc-11-11.1.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-2V7zgg/gcc-11-11.1.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.1.0 (Ubuntu 11.1.0-1ubuntu1~20.04) 

所以,我不明白发生了什么。我需要一个编译标志吗? (但文档没有提及)。

感谢您的帮助,祝您有愉快的一天:-)

std::accumulate 是为了应用二进制操作 in-order,因此使用执行策略没有任何意义。它没有接受任何重载(参见 https://en.cppreference.com/w/cpp/algorithm/accumulate)。

如果您想允许 out-of-order 评估某些执行策略,请将 std::accumulate 替换为 std::reducestd::reduce 可以假定运算的交换性和结合性,将其重新排序为任何排列,并将其应用于元素的任何分组。