openmp代码执行期间出现“ cygwin_exception :: open_stackdumpfile错误”

时间:2019-06-24 23:03:49

标签: c openmp

在执行附加的OpenMP代码期间,出现以下错误和堆栈跟踪。

Exception: STATUS_STACK_OVERFLOW at rip=00100401966
rax=00000000014EB6A0 rbx=00000000FFFFCC50 rcx=00000000FFE03C00
rdx=00000000FFFFCC50 rsi=000000018027FB40 rdi=00000000FFFFCC7A
r8 =00000006000280A0 r9 =0000000000000000 r10=0000000000000040
r11=0000000000000000 r12=0000000180248C20 r13=00000000FFFFCC7B
r14=0000000000000000 r15=00000000FFFFCC7B
rbp=00000000FFFFCCD0 rsp=00000000FFFFCBE8
program=some_dir...\example.exe, pid 134, thread 
cs=0033 ds=002B es=002B fs=0053 gs=002B ss=002B

0 [] example 134 cygwin_exception::open_stackdumpfile: Dumping stack trace to example.exe.stackdump

Stack trace:
Frame        Function    Args
000FFFFCCD0  00100401966 (0010040108B, 000FFFFCCD0, 0018004A816, 000FFFFCC7B)
000FFFFCCD0  000016E36A0 (000FFFFCCD0, 0018004A816, 000FFFFCC7B, 00000000020)
000FFFFCCD0  00000000001 (0018004A816, 000FFFFCC7B, 00000000020, FF0700010302FF00)
000FFFFCCD0  0010040108B (00000000020, FF0700010302FF00, 0018004A7AA, 00000000000)
000FFFFCCD0  0018004A816 (00000000000, 00000000000, 00000000000, 00000000000)
00000000000  00180048353 (00000000000, 00000000000, 00000000000, 00000000000)
000FFFFFFF0  00180048404 (00000000000, 00000000000, 00000000000, 00000000000)
End of stack trace

我不认为存在编译器问题,因为在没有OpenMP的情况下编译器可以正常工作。我在网上论坛上搜索,其中大多数人都遇到了动态分配的问题,这对我没有帮助。

我知道这是一个凌乱的代码,但我认为此错误与声明否有关。处理器。 Line 16: omp_set_num_threads();可能会抛出错误。同样,这些是我有限经验的一些见解。任何帮助将不胜感激。

#include<stdio.h>
#include<complex.h>
#include<stdlib.h>
#include<math.h>
#include<omp.h>
#include<string.h>

# define n 1000

int main(){


    printf("\n Start of the program\n");
    //printf("\nA random number %f", rand());

    omp_set_num_threads(16);
    int max;

    int k;
    double M[n][n], L[n][n], temp, A[n][n];

    printf("\n1.\n");
    //Generating a random 'n x n' matrix
    for (int i = 0; i<n; i++)
        for(int j = 0; j<n; j++){
            A[i][j] = 1 / (2*(n - i+1 - j+1 + 1.5));
        }   


    double start_time = omp_get_wtime();

    for (k = 0; k < n-1; k++) {
        #pragma omp parallel
        {
            int i;
            temp = 0.0;

            //Finding max in 'k' column
            #pragma omp for schedule(auto) private(i)
                for (i = k; i < n; i++) {
                    if (A[i][k] > temp) {
                        #pragma omp critical
                            temp = A[i][k];
                            max = i;
                        }
                    }
            #pragma omp barrier


            //Swapping A matrix
            #pragma omp for schedule(auto) private(temp)
                for (int i = 0; i < n; i++) {
                    temp = A[k][i];
                    A[k][i] = A[max][i];
                    A[max][i] = temp;
                }
            #pragma omp barrier
        }

            /* Swapping B matrix
            temp = B[k];
            B[k] = B[max];
            B[max] = temp;*/

            #pragma omp parallel
            {
                int i, j, m;
                temp = 0.0;
                if (k == 0)
                {
                    #pragma omp for schedule(auto) private(i,j)
                    for (i = 0; i < n; i++)
                        for (j = 0; j < n; j++) {
                            if (i == j)
                                L[i][j] = 1.0;
                            else
                                L[i][j] = 0.0;
                        }
                #pragma omp barrier
                }

                //Creating and updating Multipliers, M
                #pragma omp for schedule(auto) private(i,j)
                    for (i = k+1; i < n; i++){
                        M[i][k] = A[i][k] / A[k][k];
                    }
                #pragma omp barrier

                //Updating A matrix
                #pragma omp for schedule(auto) private(i,j)
                    for (i = k + 1; i<n; i++)
                        for (j = k; j<n; j++){
                            A[i][j] = A[i][j] - M[i][k] * A[k][j];
                        }
                #pragma omp barrier

                //Updating L matrix
                #pragma omp for schedule(auto) private(i,j)
                    for (i = k+1;i<n; i++)
                        for (j = k; j<n; j++){
                            L[i][j] = L[i][j] + M[i][k] * L[k][j];
                        }
                #pragma omp barrier

                /* Updating B matrix
                #pragma omp for schedule(auto) private(i)
                    for (i = k+1; i<row; i++) {
                        B[i] = B[i] - M[i][k] * B[k];
                    }
                #pragma omp barrier*/  
            }

    }


    printf("\n\nExecution time: %.9f\n", omp_get_wtime() - start_time);


    return 0;
}

1 个答案:

答案 0 :(得分:0)

问题是Exception: STATUS_STACK_OVERFLOW at rip=00100401966

罪魁祸首可能是double M[1000][1000], L[1000][1000], temp, A[1000][1000]

问题是“为什么?”。

问:您使用的是哪个编译器/编译器版本?什么是OpenMP版本?

可能的解决方法:

问:如果您减少到omp_set_num_threads(8),会发生什么?

问:如果您减少到#define n 250,会发生什么?

问:如果用malloc()分配数组而不是在堆栈上声明它们,会发生什么情况?