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]

OpenMP loop implementation


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?

Thanks!



Amittai Aviram
PhD Student in Computer Science
Yale University
646 483 2639
amittai.aviram@yale.edu
http://www.amittai.com


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