并行$ C $下next_permutation() [英] Parallel code for next_permutation()

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

问题描述

我想知道如果我可以并行使用OpenMP对于此为例code?如果它会使其运行速度更快,或者存在一些其他的方式,使其更快...

I am wondering if I can parallelize this code using OpenMP for exemple ? If it will make it run faster or if it exists some other way to make it faster ...

vector<int> t; // already initialized
do{
    // Something with current permutation

} while(next_permutation(t.begin(), t.end()));

我知道我可以很容易地并行化的指令,但在这里我有一段时间(条件=真)

I know I can easily parallelize a for instruction but here I have a while(condition=true)

感谢您在您的帮助!

推荐答案

使用<一个href="http://stackoverflow.com/questions/7918806/finding-n-th-permutation-without-computing-others">Finding n次置换不计算其他来获得的第k个排列,对 K = 1 * N /计数 0 >到计数,其中 N 是排列数,是索引,而计数的线程数。

Use Finding n-th permutation without computing others to get the kth permutation, for k=i*n/count, i from 0 to count, where n is the number of permutations, i is an index, and count is the number of threads.

此为您提供了计数块或间隔。在平行的一个单独的线程每个间隔内循环,调用 next_permutation 多次在每个线程。

This gives you count blocks or intervals. Iterate within each interval in a separate thread in parallel, calling next_permutation repeatedly in each thread.

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

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