并行迭代器 [英] Parallel Iterators

查看:98
本文介绍了并行迭代器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个由并行代码(使用OpenMP)使用的C ++数据结构(用于图形)。

I am designing a C++ data structure (for graphs) which is to be used by parallel code (using OpenMP).

假设我想要一个方法来对所有元素(节点)进行迭代。当然,这个迭代将被并行化。

Suppose I want to have a method which enables iteration over all elements (nodes). Of course, this iteration is going to be parallelized.

是否可以为此目的使用迭代器?迭代器应该如何实现并行访问?你会建议在这种情况下使用迭代器吗?

Is it possible to use an iterator for this purpose? How should an iterator look like that enables parallel access? Would you advise for or against using iterators in this case?

推荐答案

OpenMP并行循环不能很好地使用迭代器。您将需要在图类上实现一个索引机制( operator [] 采用一个整数参数)。

OpenMP parallel loops don't play nicely with iterators. You'll want to implement an indexing mechanism (operator[] taking an integral argument) on your graph class.

如果你确实想使用OpenMP 3.0迭代器支持,请确保你有一个随机访问迭代器。将它实现为指向节点或边的指针是最简单的选择。

If you do want to use OpenMP 3.0 iterator support, make sure you have a random access iterator. Implementing it as an pointer to a node or edge is the simplest choice.

这篇关于并行迭代器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆