This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: OpenMP loop implementation


Amittai Aviram <amittai.aviram@yale.edu> 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@gcc.gnu.org mailing list.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]