Re: OpenMP loop implementation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Amittai Aviram <amittai.aviram@xxxxxxxx> writes:

> I am trying to understand better how GCC handles OpenMP LOOP constructs such as the "parallel for" construct in C.  Here is a short test program in file test_prog.c:
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <omp.h>
>
> #define NUM_ELEMS 8
>
>
> int main(void) {
>
>         int array[NUM_ELEMS];
>         int i;
>
> #pragma omp parallel for
>         for (i = 0; i < NUM_ELEMS; i++)
>                 array[i] = i + 1;
>
>         for (i = 0; i < NUM_ELEMS; i++)
>                 printf("%d ", array[i]);
>         printf("\n");
>         return EXIT_SUCCESS;
> }
>
> According to this GCC internals document
> http://gcc.gnu.org/onlinedocs/libgomp/Implementing-FOR-construct.html#Implementing-FOR-construct
> GCC should put the code through a couple of transformations:
>
> 1.  The loop body goes into a separate function (say, "subfunction").
> 2. The outer function (e.g., main) has
>
> GOMP_parallel_loop_static(subfunction, args, 0, lb, ub + 1, 1, 0);
> subfunction(args);
> GOMP_parallel_end();
>
> However, this is not what I see if I compile test_prog.c down to Assembly code (gcc -fopenmp -S test_prog.c).  Instead, here is the sequence of call instructions (with everything else omitted; "subfunction" here is main.omp_fn.0):
>
> main:
>         movl    $main.omp_fn.0, %edi
>         call    GOMP_parallel_start
>         call    main.omp_fn.0
>         call    GOMP_parallel_end
>
>
> Then, if I look at the source code in loop.c, it looks as if the sequence should be
>
> GOMP_parallel_loop_static_start
> subfunction
> GOMP_parallel_end
>
> Why does the Assembly code have GOMP_parallel_start rather than GOMP_parallel_loop_static_start?

It would be nice if we had perfect documentation, but we don't.

The choice of whether to use GOMP_parallel_start or
GOMP_parallel_loop_static_start is a decision made when generating OMP
code based on the characteristics of the loop(s).  To see why one is
chosen rather than the other, you're going to have to look at the code
in gcc/omp-low.c and figure it out.  I don't know myself.

If you think this is a bug or an inefficiency, then please feel free to
bring it up on the gcc@xxxxxxxxxxx mailing list.

Ian


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux