1
votes

I got the following output with error message while executing the program that uses openmp in VS2008 C++

thread number: 0

thread number: 1

Fatal User Error 1002: 'for' loop executed with inconsistent parameters between threads

My program does the following:

    omp_set_dynamic(0);
    omp_set_num_threads(2);

    int i = 0;
    int start_pos   = 0;
    int end_pos     = 0;

#pragma omp parallel default(none) private(i, start_pos, end_pos)
    {
        int nThreadNum = omp_get_thread_num();
        printf("thread number: %d\n", nThreadNum);
        start_pos   = 0;
        end_pos     = (number_of_model_points / 2 + 1);
        if (nThreadNum != 0) {
            start_pos   = (number_of_model_points / 2) + 1;
            end_pos     = (number_of_model_points);
        }

#pragma omp for
        for(i = start_pos; i < end_pos; i++) {
                      ...some code here...
        }
}

What is the problem here? Please correct me if I made a mistake.

2

2 Answers

1
votes

So why there is an additional pragma for the for loop? You already did fork your processes. If you really want to fork again (don't do that, please!) then "i" needs to be set private again. However I think you just would want to remove the "omp for" pragma.

0
votes

Jonathan Dursi is right, so in summary, for loop bounding parameters can not be private. In your example, for(i = start_pos; i < end_pos; i++), start_pos and end_pos are private per omp thread, hence consistency is not guaranteed and you get error 1002. Otherwise you can definitely have #pragma omp for inside #pragma omp parallel.