C++ 致命错误 C1001:使用 openMP 的编译器发生内部错误 [英] C++ fatal error C1001: An internal error has occurred in the compiler with openMP
问题描述
我有一个解决数独谜题的程序,我已经让它按顺序工作,但现在我正在尝试使用 openMP 并行化它.函数 solvePuzzle()
包含算法,我想在其中并行化 for 循环,但是当我在 for 循环之前添加 #pragma omp parallel for
语句时,我收到此错误: fatal error C1001: 编译器出现内部错误.
函数的代码是solvePuzzle()
:
bool sudoku::solvePuzzle(int grid[CELL][CELL]) {整数行,列;if (!findEmptyCell(grid, row, col))返回真;#pragma omp 并行用于for (int num = 1; num <= 9; num++) {if (checkAccuracy(grid, row, col, num)) {网格[行][列] = num;if (solvePuzzle(grid))返回真;网格[行][列] = EMPTY_CELL;}}返回假;}
如果有帮助,这是带有 main 的驱动程序:
#include "SudokuGrid.h"使用命名空间标准;int main() {数独数独;时钟_t t1, t2;t1 = 时钟();if (sudoku.readPuzzle("1.txt")) {sudoku.printGrid(sudoku.grid);}别的 {cout<<不正确的文件"<<结束;}cout<<结束;if (sudoku.solvePuzzle(sudoku.grid) == true)sudoku.printGrid(sudoku.grid);别的printf("无解");t2 = 时钟();printf("执行时间 = %1d ms\n", (t2 - t1));返回0;}
构建时完全错误:
1>------ 构建开始:项目:数独,配置:调试 Win32 ------1>数独网格.cpp1>c:\users\john\source\repos\sudoku\sudoku\sudokugrid.cpp(8): 致命错误C1001: 编译器发生内部错误.1>(编译器文件'f:\dd\vctools\compiler\utc\src\p2\main.c',第258行)1>要解决此问题,请尝试在附近简化或更改程序上面列出的位置.1>请在Visual C++上选择技术支持命令1>帮助菜单,或打开技术支持帮助文件了解更多信息1>1> 已完成构建项目Sudoku.vcxproj" -- 失败.========== 构建:0 成功,1 失败,0 最新,0 跳过 ==========
总而言之,问题是从并行化的 for
循环内部返回.
#pragma omp parallel forfor (int num = 1; num <= 9; num++) {...if (solvePuzzle(grid))返回真;//坏的...}}
<块引用>
OpenMP 要求循环结构处理每次迭代.不允许跳出循环(使用 return、goto、break、throw 或其他方式)."
-- https://bisqwit.iki.fi/story/howto/openmp/
所以解决方案是让循环遍历所有迭代(另见跳出循环).
bool solvePuzzle(int grid[CELL][CELL]) {布尔解决 = 假;整数行,列;if (!findEmptyCell(grid, row, col))返回真;#pragma omp 并行用于for (int num = 1; num <= 9; num++) {#pragma omp flush (已解决)if (!solved && checkAccuracy(grid, row, col, num)) {网格[行][列] = num;if (solvePuzzle(grid)) {解决了=真;#pragma omp flush (已解决)} 别的 {网格[行][列] = EMPTY_CELL;}}}返回解决;}
I have a program that solves sudoku puzzles and I've gotten it to work sequentially, but now I'm trying to parallelize it using openMP. The function solvePuzzle()
includes the algorithm and I want to parallelize the for loop within it however when I add #pragma omp parallel for
statement before my for loop i get this error: fatal error C1001: An internal error has occurred in the compiler.
The code for the function is solvePuzzle()
:
bool sudoku::solvePuzzle(int grid[CELL][CELL]) {
int row, col;
if (!findEmptyCell(grid, row, col))
return true;
#pragma omp parallel for
for (int num = 1; num <= 9; num++) {
if (checkAccuracy(grid, row, col, num)) {
grid[row][col] = num;
if (solvePuzzle(grid))
return true;
grid[row][col] = EMPTY_CELL;
}
}
return false;
}
Here is the driver with main if it helps:
#include "SudokuGrid.h"
using namespace std;
int main() {
sudoku sudoku;
clock_t t1, t2;
t1 = clock();
if (sudoku.readPuzzle("1.txt")) {
sudoku.printGrid(sudoku.grid);
}
else {
cout << "Incorrect file" << endl;
}
cout << endl;
if (sudoku.solvePuzzle(sudoku.grid) == true)
sudoku.printGrid(sudoku.grid);
else
printf("No solution exists");
t2 = clock();
printf("Time to execute = %1d ms\n", (t2 - t1));
return 0;
}
Full error when built:
1>------ Build started: Project: Sudoku, Configuration: Debug Win32 ------
1>SudokuGrid.cpp
1>c:\users\john\source\repos\sudoku\sudoku\sudokugrid.cpp(8): fatal error
C1001: An internal error has occurred in the compiler.
1>(compiler file 'f:\dd\vctools\compiler\utc\src\p2\main.c', line 258)
1> To work around this problem, try simplifying or changing the program near
the locations listed above.
1>Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information
1>
1>Done building project "Sudoku.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
To summarize, the problem is returning from inside the parallelized for
loop.
#pragma omp parallel for
for (int num = 1; num <= 9; num++) {
...
if (solvePuzzle(grid))
return true; // BAD
...
}
}
"OpenMP requires that a loop construct processes each iteration. Breaking out of the loop (using return, goto, break, throw or other means) is not allowed."
So the solution is to let the loop loop through all iterations (See also Breaking Out of Loops).
bool solvePuzzle(int grid[CELL][CELL]) {
bool solved = false;
int row, col;
if (!findEmptyCell(grid, row, col))
return true;
#pragma omp parallel for
for (int num = 1; num <= 9; num++) {
#pragma omp flush (solved)
if (!solved && checkAccuracy(grid, row, col, num)) {
grid[row][col] = num;
if (solvePuzzle(grid)) {
solved = true;
#pragma omp flush (solved)
} else {
grid[row][col] = EMPTY_CELL;
}
}
}
return solved;
}
这篇关于C++ 致命错误 C1001:使用 openMP 的编译器发生内部错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!