niXman / mingw-builds

Scripts for building the 32 and 64-bit MinGW-W64 compilers for Windows
Other
295 stars 107 forks source link

OpenMP issue #610

Closed magicse closed 2 years ago

magicse commented 2 years ago

Hi thank You for Your work. Windows 7 Core 2 Quard MinGW64 GCC 12.1.0

I have some issue with OpenMP support. When I compile the following example it works fine:

  #pragma omp parallel
    {
        printf("thread num %d: first hello world!\n",omp_get_thread_num());
        printf("thread num %d; second hello world!\n",omp_get_thread_num());
    }

But when I try run compiled next example (Recursive QuickSort with OpenMP ). I get segmentation fault error. I tried different examples of QuickSort with OpenMP and always I get segmentation fault error.

   static void qsort_descent_inplace(std::vector<FaceObject>& faceobjects, int left, int right)
   {
    int i = left;
    int j = right;
    float p = faceobjects[(left + right) / 2].prob;

    while (i <= j)
    {
        while (faceobjects[i].prob > p)
            i++;

        while (faceobjects[j].prob < p)
            j--;

        if (i <= j)
        {
            // swap
            std::swap(faceobjects[i], faceobjects[j]);

            i++;
            j--;
        }
    }

    #pragma omp parallel sections
    {
        #pragma omp section
        {
            if (left < j) qsort_descent_inplace(faceobjects, left, j);
        }
        #pragma omp section
        {
            if (i < right) qsort_descent_inplace(faceobjects, i, right);
        }
    }
}

Also when I compile the NCNN library with OpenMP support I also get segmentation fault error when I use this library, and without OpenMP support it all work Ok.

magicse commented 2 years ago

If make this changes in source above, than it work correct with "OpenMP support" without fault error.

    #pragma omp taskq
     {
         #pragma omp task shared(faceobjects)
        {
            if (left < j) qsort_descent_inplace(faceobjects, left, j);
         }
         #pragma omp task shared(faceobjects)
        {
            if (i < right) qsort_descent_inplace(faceobjects, i, right);
         }
    }
niXman commented 2 years ago

great!

please close.