开发者

Ideal data structure with OpenMP

What is an ideal data structure in parallel programing, in my cas开发者_运维技巧e OpenMP.

#pragma omp parallel for
for(int i = 0; i < N; i++)
{
    if(table[i] == true)
        container.insert(i); // ?? what kind
}

In this example it might be simple if we use a table of similar size. What is a more general data structure for shared-memory parallel programing in C++?


It is best not to rely on shared data structures at all (because you'll have to rely on locks at some point, which will slow things down). Instead, have each thread write to its own structure, and coalesce the results once the parallel section has completed.


The array is the ideal data structure for parallel programming.

I don't share @Oli Charlesworth's reluctance to rely on shared data structures -- after all OpenMP is about shared-memory parallelisation and it provides the tools a programmer needs to ensure data safety.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜