简体   繁体   English

没有ExecutionPolicy的std :: transform或std :: generate可以并行吗?

[英]Can std::transform or std::generate without ExecutionPolicy be parallel?

In C++17 parallel std algorithms were introduced (overloads with ExecutionPolicy arguments), where strict rules of execution order, interleaving and paralelization were defined, for example ([algorithm.parallel.exec/3]): 在C ++中引入了17个并行std算法(使用ExecutionPolicy参数重载),其中定义了严格的执行顺序,交错和并行化规则,例如([algorithm.parallel.exec / 3]):

The invocations of element access functions in parallel algorithms invoked with an execution policy object of type execution::sequenced_policy all occur in the calling thread of execution. 使用类型为execute :: sequenced_policy的执行策略对象调用的并行算法中的元素访问函数的调用都发生在执行的调用线程中。 [ Note: The invocations are not interleaved; [注意:调用不是交错的; see 4.6. 见4.6。 — end note ] - 结束说明]

(same thing in current draft ) 目前草案中的情况相同)

The problem is that I can't find any such requirement for old, non-parallel overloads of these algorithms. 问题是我找不到这些算法的旧的非并行重载的任何这样的要求。

Question: Can this mean that library implementers can, since C++11 when thread of execution term was introduced, implement std::transform and std::generate using SIMD/multithreading/other(?)? 问:这是否意味着库实现者可以在引入执行术语线程时使用C ++ 11,使用SIMD /多线程/其他(?)实现std :: transform和std :: generate? Is there a reason for that? 这有什么理由吗?

[res.on.data.races]/8 Unless otherwise specified, C++ standard library functions shall perform all operations solely within the current thread if those operations have effects that are visible (4.7) to users. [res.on.data.races] / 8除非另有说明,否则C ++标准库函数应仅在当前线程内执行所有操作,如果这些操作具有对用户可见(4.7)的效果。

This precludes any kind of behind-the-scenes multithreading that touches any user-defined entities. 这排除了触及任何用户定义实体的任何类型的幕后多线程。

I suppose, in principle, something like std::sort working on a vector<int> can prove that no user-defined class is involved, and send work to multiple threads. 我想,原则上,像vector<int>这样的std::sort东西可以证明不涉及用户定义的类,并将工作发送到多个线程。 That's rather far-fetched, it's difficult to imagine any implementation doing this in practice. 这是相当牵强的,很难想象在实践中这样做的任何实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM