我正在尝试使用这种方法在 C++11 中并行化动态编程算法:
void buildBaseCases() {
cout << "Building base cases" << endl;
for (unsigned int i = 0; i < BOARD_SIZE; ++i)
{
buildBaseCase(i);
}
cout << "Done building base cases" << endl;
}
因此,我的并行化版本将类似于:
void buildBaseCases() {
cout << "Building base cases" << endl;
#pragma omp parallel
{
#pragma omp for
for (unsigned int i = 0; i < BOARD_SIZE; ++i)
{
buildBaseCase(i);
}
}
cout << "Done building base cases" << endl;
}
然而,这导致 valgrind 抱怨内存泄漏。我是否误解了您应该使用 openMP 的方式,还是发生了什么可疑的事情?