public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* OpenMP loop implementation
@ 2011-01-15  7:28 Amittai Aviram
  2011-01-17  9:53 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: Amittai Aviram @ 2011-01-15  7:28 UTC (permalink / raw)
  To: gcc-help

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-01-17  9:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-15  7:28 OpenMP loop implementation Amittai Aviram
2011-01-17  9:53 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).