在我的c++应用程序开始时,我的主线程使用OMP并行化几个for循环。在第一个并行化的for循环之后,我发现所使用的线程在整个应用程序的持续时间内保持存在,并且在从主线程执行的后续OMP for循环中被重复使用,使用以下命令(在CentOS 7中工作):
for i in $(pgrep myApplication); do ps -mo pid,tid,fname,user,psr -p $i;done
在我的程序中,我从主线程启动了一个boost线程,在这个线程中使用OMP并行化for循环。此时,我看到完全创建了一组新的线程,其中有相当大的开销。
是否可能使boost线程内的OMP并行for循环重用主线程创建的原始OMP线程池?
编辑:一些伪代码:
myFun(data)
{
// Want to reuse OMP thread pool from main here.
omp parallel for
for(int i = 0; i < N; ++i)
{
// Work on data
}
}
main
{
// Thread pool created here.
omp parallel for
for(int i = 0; i < N; ++i)
{
// do stuff
}
boost::thread myThread(myFun) // Constructor starts thread.
// Do some serial stuff, no OMP.
myThread.join();
}
pthread_create
(或boost::thread
或std::thread
)启动的线程不会继承该指针,因此会生成一个新的线程池。其他 OpenMP 运行时也可能存在这种情况。 - Hristo Iliev