本文介绍了是否可能将我的循环转换为parallel_for fnc调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个for循环,我想转换为parallel_for fnc调用。我的代码符合所有的条件(描述在Parallel_Programming_with_Microsoft_Visual_C_plus_plus,第7页),这个转换是成功的,但我发现很难实现。这是我的例子:

I'm having a for loop which I would like to convert into parallel_for fnc invocation. My code meets all the criteria (described in Parallel_Programming_with_Microsoft_Visual_C_plus_plus,p.7) for this conversion to be successfull, yet I find it difficult to implement. Here is my example:

//"Oridinary" for
//numbers_from_file_ is a vector<Big_Int> loaded with Big_Int 
//results_ is a vector<Big_Int>

for (unsigned i = 0; i < numbers_from_file_.size(); i += 2)//+2 to skip to another pair
{
    results_.push_back( numbers_from_file_[i] * numbers_from_file_[i + 1]);
}

这种情况是,来自numbers_from_file_的每对数字都被放大并存储在results_。为了使其工作,变量i必须递增2(跳到另一对)。不幸的是,在这本书中的例子显示如何将for循环的主体转换为parallel_for fnc调用,只有当i增加1时。

是否可以将我的循环转换为parallel_for fnc调用?

The scenario is that each pair of numbers from numbers_from_file_ is multiplied out and stored in results_. In order to make it work the variable i has to be incremented by two (to skip to another pair). Unfortunately example in this book is showing how to convert body of for loop into parallel_for fnc invocation only if i is being incremented by one.
Is it possible to convert my loop into parallel_for fnc invocation?

推荐答案

说,有一个步骤参数。使用它。

MSDN says that there is a step parameter. Use it.

这篇关于是否可能将我的循环转换为parallel_for fnc调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 09:22