According to the libgomp manual, a code in the form:
#pragma omp parallel for
for (i = lb; i <= ub; i++)
body;
becomes
void subfunction (void *data)
{
long _s0, _e0;
while (GOMP_loop_static_next (&_s0, &_e0))
{
long _e1 = _e0, i;
for (i = _s0; i < _e1; i++)
body;
}
GOMP_loop_end_nowait ();
}
GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
subfunction (NULL);
GOMP_parallel_end ();
I did a very tiny program to debug just to see how this implementation works:
int main(int argc, char** argv)
{
int res, i;
# pragma omp parallel for num_threads(4)
for(i = 0; i < 400000; i++)
res = res*argc;
return 0;
}
Next, I ran gdb and set breakpoints to "GOMP_parallel_loop_static" and "GOMP_parallel_end". At the beginning, the library was not loaded, so they were pending. By the time a ran the test program inside gdb, I got the result below:
(gdb) run 2 1 6 5 4 3 8 7
Starting program: ./test 2 1 6 5 4 3 8 7
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-
gnu/libthread_db.so.1".
[New Thread 0x7ffff73c9700 (LWP 5381)]
[New Thread 0x7ffff6bc8700 (LWP 5382)]
[New Thread 0x7ffff63c7700 (LWP 5383)]
Thread 1 "test" hit Breakpoint 2, 0x00007ffff7bc0c00 in GOMP_parallel_end () from /usr/lib/x86_64-linux-gnu/libgomp.so.1
As you can see, It reached the second breakpoint, in "GOMP_parallel_end" but not the first. I would like to know how could this be possible if the libgomp manual shows clearly that "GOMP_parallel_loop_static" comes first.
Thank you.