并行模式库(Parallel Patterns Library,PPL)是微软的本地C++库用于并发编程[1]Visual Studio 2010引入,很好地兼容于C++11语言标准。

例子 编辑

对于串行的循环:

  for (int x=0; x < width; ++x)
  {
     //Something parallelizable
  }

可以使用parallel_for改为并行循环实现:

  #include <ppl.h>
  // . . .
 Concurrency::parallel_for (0, width, [=](int x)
 {
     //Something parallelizable
 });

MSDN[2]描述该库使用Concurrency Runtime调度与资源管理,提供通用、类型安全算法与容器。从Visual Studio 2015开始,Concurrency Runtime Task Scheduler不再调度在ppltasks.h中的task类与相关类型,而是用Windows ThreadPool以得到更好性能,以及能与Windows同步原语交互。并行算法如parallel_for继续使用Concurrency Runtime Task Scheduler。

参考文献 编辑

  1. ^ The Visual C++ Weekly. March 12, 2011 [2018-10-25]. (原始内容存档于2011-10-08). 
  2. ^ Parallel Patterns Library (PPL) on MSDN. [2018-10-25]. (原始内容存档于2018-03-03).