首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C++致命错误C1001:在带有openMP的编译器中发生了内部错误

C++致命错误C1001:在带有openMP的编译器中发生了内部错误
EN

Stack Overflow用户
提问于 2018-03-28 17:00:26
回答 1查看 2K关注 0票数 0

我有一个解决sudoku难题的程序,我已经让它按顺序工作,但是现在我尝试使用openMP并行化它。函数solvePuzzle()包括算法,我希望并行化其中的for循环,但是当我在for循环之前添加#pragma omp parallel for语句时,我会得到以下错误:fatal error C1001: An internal error has occurred in the compiler.

函数的代码是solvePuzzle()

代码语言:javascript
复制
    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;
    }

下面是具有main的驱动程序,如果有帮助的话:

代码语言:javascript
复制
#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;
}

生成时完全错误:

代码语言:javascript
复制
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 ==========
EN

回答 1

Stack Overflow用户

发布于 2018-03-28 18:31:54

总之,问题是从并行化的for循环内部返回。

代码语言:javascript
复制
#pragma omp parallel for
    for (int num = 1; num <= 9; num++) {
            ...
            if (solvePuzzle(grid))
                return true;           // BAD

            ...
        }
    }

"OpenMP要求循环构造处理每一次迭代。不允许突破循环(使用返回、goto、中断、抛出或其他方式)。“ -- https://bisqwit.iki.fi/story/howto/openmp/

因此,解决方案是让循环循环通过所有的迭代(也请参阅挣脱圈圈)。

代码语言:javascript
复制
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;
}

雷普

演示

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49540292

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档