按照libgomp手冊,形式代碼:無法理解libgomp實現FOR結構
#pragma omp parallel for
for (i = lb; i <= ub; i++)
body;
成爲
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();
我做了一個非常微小的程序調試只是爲了看看此實現原理:
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;
}
接下來,我跑了GDB,並設置斷點 「GOMP_parallel_loop_static」 和「GOMP _parallel_end」。開始時,圖書館沒有裝入,所以他們正在等待。到時候一跑了GDB內部測試程序,我得到下面的結果:
(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
正如你所看到的,它達到了第二個斷點,在「GOMP_parallel_end」,但不是第一個。我想知道如果libgomp手冊清楚地顯示「GOMP_parallel_loop_static」是第一個,這怎麼可能。
謝謝。
您以錯誤的順序得到了'main'的形參'argv'和'argc'。 – tschwinge