parallel_for 函数

parallel_for 循环访问一个索引范围,并在每次迭代时以并行方式执行用户提供的函数。

template <
   typename _Index_type,
   typename _Function,
   typename _Partitioner
>
void parallel_for(
   _Index_type_First,
   _Index_type_Last,
   _Index_type_Step,
   const _Function& _Func,
   _Partitioner&& _Part
);

template <
   typename _Index_type,
   typename _Function
>
void parallel_for(
   _Index_type_First,
   _Index_type_Last,
   _Index_type_Step,
   const _Function& _Func
);

template <
   typename _Index_type,
   typename _Function
>
void parallel_for(
   _Index_type_First,
   _Index_type_Last,
   const _Function& _Func,
   const auto_partitioner& _Part = auto_partitioner()
);

template <
   typename _Index_type,
   typename _Function
>
void parallel_for(
   _Index_type_First,
   _Index_type_Last,
   const _Function& _Func,
   const static_partitioner& _Part
);

template <
   typename _Index_type,
   typename _Function
>
void parallel_for(
   _Index_type_First,
   _Index_type_Last,
   const _Function& _Func,
   const simple_partitioner& _Part
);

template <
   typename _Index_type,
   typename _Function
>
void parallel_for(
   _Index_type_First,
   _Index_type_Last,
   const _Function& _Func,
   affinity_partitioner& _Part
);

参数

  • _Index_type
    用于迭代的索引类型。

  • _Function
    每次迭代时将执行的函数的类型。

  • _Partitioner
    使用进行分区所提供的范围分区程序的类型。

  • _First
    要包含在迭代中的第一个索引。

  • _Last
    索引一超过了要包含在迭代中的最后一个索引。

  • _Step
    从 _First 至 _Last 迭代时的步长值。 此步长必须是正数。 如果该步骤小于 1,则会引发 invalid_argument

  • _Func
    要在每次迭代时执行的函数。 这可以是 lambda 表达式、函数指针或支持函数调用运算符某个版本的任意对象,具有签名 void operator()(_Index_type**)**。

  • _Part
    对分区程序对象的引用。 参数可以是一个 constauto_partitioner&conststatic_partitioner&constsimple_partitioner&affinity_partitioner& ,如果使用 affinity_partitioner 对象,引用必须是一个非常量左值引用,因此,算法可以存储将来的循环的状态可以重用。

备注

有关更多信息,请参见 并行算法

要求

**标头:**ppl.h

命名空间: 并发

请参见

参考

concurrency 命名空间