Module: wine Branch: master Commit: bc10d127b472d456e5308903e3556b72d8c80fca URL: http://source.winehq.org/git/wine.git/?a=commit;h=bc10d127b472d456e5308903e3...
Author: Sebastian Lackner sebastian@fds-team.de Date: Mon Jul 20 05:16:12 2015 +0200
vcomp: Implement omp_in_parallel and add tests.
---
dlls/vcomp/main.c | 6 +++++ dlls/vcomp/tests/vcomp.c | 61 +++++++++++++++++++++++++++++++++------------ dlls/vcomp/vcomp.spec | 2 +- dlls/vcomp100/vcomp100.spec | 2 +- dlls/vcomp90/vcomp90.spec | 2 +- 5 files changed, 54 insertions(+), 19 deletions(-)
diff --git a/dlls/vcomp/main.c b/dlls/vcomp/main.c index 1dad029..d76df1e 100644 --- a/dlls/vcomp/main.c +++ b/dlls/vcomp/main.c @@ -361,6 +361,12 @@ int CDECL _vcomp_sections_next(void) return i; }
+int CDECL omp_in_parallel(void) +{ + TRACE("()\n"); + return vcomp_init_thread_data()->parallel; +} + static DWORD WINAPI _vcomp_fork_worker(void *param) { struct vcomp_thread_data *thread_data = param; diff --git a/dlls/vcomp/tests/vcomp.c b/dlls/vcomp/tests/vcomp.c index dd91b4f..7346655 100644 --- a/dlls/vcomp/tests/vcomp.c +++ b/dlls/vcomp/tests/vcomp.c @@ -40,6 +40,7 @@ static int (CDECL *pomp_get_max_threads)(void); static int (CDECL *pomp_get_nested)(void); static int (CDECL *pomp_get_num_threads)(void); static int (CDECL *pomp_get_thread_num)(void); +static int (CDECL *pomp_in_parallel)(void); static void (CDECL *pomp_set_nested)(int nested); static void (CDECL *pomp_set_num_threads)(int num_threads);
@@ -178,6 +179,7 @@ static BOOL init_vcomp(void) VCOMP_GET_PROC(omp_get_nested); VCOMP_GET_PROC(omp_get_num_threads); VCOMP_GET_PROC(omp_get_thread_num); + VCOMP_GET_PROC(omp_in_parallel); VCOMP_GET_PROC(omp_set_nested); VCOMP_GET_PROC(omp_set_num_threads);
@@ -186,14 +188,17 @@ static BOOL init_vcomp(void)
#undef VCOMP_GET_PROC
-static void CDECL num_threads_cb2(LONG *count) +static void CDECL num_threads_cb2(int parallel, LONG *count) { + int is_parallel = pomp_in_parallel(); + ok(is_parallel == parallel, "expected %d, got %d\n", parallel, is_parallel); + InterlockedIncrement(count); }
-static void CDECL num_threads_cb(BOOL nested, int nested_threads, LONG *count) +static void CDECL num_threads_cb(BOOL nested, int parallel, int nested_threads, LONG *count) { - int num_threads, thread_num; + int is_parallel, num_threads, thread_num; LONG thread_count;
InterlockedIncrement(count); @@ -205,29 +210,41 @@ static void CDECL num_threads_cb(BOOL nested, int nested_threads, LONG *count) ok(thread_num >= 0 && thread_num < num_threads, "expected thread_num in range [0, %d], got %d\n", num_threads - 1, thread_num);
+ is_parallel = pomp_in_parallel(); + ok(is_parallel == parallel, "expected %d, got %d\n", parallel, is_parallel); + thread_count = 0; - p_vcomp_fork(TRUE, 1, num_threads_cb2, &thread_count); + p_vcomp_fork(TRUE, 2, num_threads_cb2, TRUE, &thread_count); if (nested) ok(thread_count == nested_threads, "expected %d threads, got %d\n", nested_threads, thread_count); else ok(thread_count == 1, "expected 1 thread, got %d\n", thread_count);
+ is_parallel = pomp_in_parallel(); + ok(is_parallel == parallel, "expected %d, got %d\n", parallel, is_parallel); + thread_count = 0; - p_vcomp_fork(FALSE, 1, num_threads_cb2, &thread_count); + p_vcomp_fork(FALSE, 2, num_threads_cb2, parallel, &thread_count); ok(thread_count == 1, "expected 1 thread, got %d\n", thread_count);
+ is_parallel = pomp_in_parallel(); + ok(is_parallel == parallel, "expected %d, got %d\n", parallel, is_parallel); + p_vcomp_set_num_threads(4); thread_count = 0; - p_vcomp_fork(TRUE, 1, num_threads_cb2, &thread_count); + p_vcomp_fork(TRUE, 2, num_threads_cb2, TRUE, &thread_count); if (nested) ok(thread_count == 4, "expected 4 threads, got %d\n", thread_count); else ok(thread_count == 1, "expected 1 thread, got %d\n", thread_count); + + is_parallel = pomp_in_parallel(); + ok(is_parallel == parallel, "expected %d, got %d\n", parallel, is_parallel); }
static void test_omp_get_num_threads(BOOL nested) { - int is_nested, max_threads, num_threads, thread_num; + int is_nested, is_parallel, max_threads, num_threads, thread_num; LONG thread_count;
pomp_set_nested(nested); @@ -239,61 +256,73 @@ static void test_omp_get_num_threads(BOOL nested) thread_num = pomp_get_thread_num(); ok(thread_num == 0, "expected thread_num == 0, got %d\n", thread_num);
+ is_parallel = pomp_in_parallel(); + ok(is_parallel == FALSE, "expected FALSE, got %d\n", is_parallel); + num_threads = pomp_get_num_threads(); ok(num_threads == 1, "expected num_threads == 1, got %d\n", num_threads); thread_count = 0; - p_vcomp_fork(TRUE, 3, num_threads_cb, nested, max_threads, &thread_count); + p_vcomp_fork(TRUE, 4, num_threads_cb, nested, TRUE, max_threads, &thread_count); ok(thread_count == max_threads, "expected %d threads, got %d\n", max_threads, thread_count);
+ is_parallel = pomp_in_parallel(); + ok(is_parallel == FALSE, "expected FALSE, got %d\n", is_parallel); + num_threads = pomp_get_num_threads(); ok(num_threads == 1, "expected num_threads == 1, got %d\n", num_threads); thread_count = 0; - p_vcomp_fork(FALSE, 3, num_threads_cb, TRUE, max_threads, &thread_count); + p_vcomp_fork(FALSE, 4, num_threads_cb, TRUE, FALSE, max_threads, &thread_count); ok(thread_count == 1, "expected 1 thread, got %d\n", thread_count);
+ is_parallel = pomp_in_parallel(); + ok(is_parallel == FALSE, "expected FALSE, got %d\n", is_parallel); + pomp_set_num_threads(1); num_threads = pomp_get_num_threads(); ok(num_threads == 1, "expected num_threads == 1, got %d\n", num_threads); thread_count = 0; - p_vcomp_fork(TRUE, 3, num_threads_cb, nested, 1, &thread_count); + p_vcomp_fork(TRUE, 4, num_threads_cb, nested, TRUE, 1, &thread_count); ok(thread_count == 1, "expected 1 thread, got %d\n", thread_count);
+ is_parallel = pomp_in_parallel(); + ok(is_parallel == FALSE, "expected FALSE, got %d\n", is_parallel); + pomp_set_num_threads(2); num_threads = pomp_get_num_threads(); ok(num_threads == 1, "expected num_threads == 1, got %d\n", num_threads); thread_count = 0; - p_vcomp_fork(TRUE, 3, num_threads_cb, nested, 2, &thread_count); + p_vcomp_fork(TRUE, 4, num_threads_cb, nested, TRUE, 2, &thread_count); ok(thread_count == 2, "expected 2 threads, got %d\n", thread_count);
pomp_set_num_threads(4); num_threads = pomp_get_num_threads(); ok(num_threads == 1, "expected num_threads == 1, got %d\n", num_threads); thread_count = 0; - p_vcomp_fork(TRUE, 3, num_threads_cb, nested, 4, &thread_count); + p_vcomp_fork(TRUE, 4, num_threads_cb, nested, TRUE, 4, &thread_count); ok(thread_count == 4, "expected 4 threads, got %d\n", thread_count);
p_vcomp_set_num_threads(8); num_threads = pomp_get_num_threads(); ok(num_threads == 1, "expected num_threads == 1, got %d\n", num_threads); thread_count = 0; - p_vcomp_fork(TRUE, 3, num_threads_cb, nested, 4, &thread_count); + p_vcomp_fork(TRUE, 4, num_threads_cb, nested, TRUE, 4, &thread_count); ok(thread_count == 8, "expected 8 threads, got %d\n", thread_count); thread_count = 0; - p_vcomp_fork(TRUE, 3, num_threads_cb, nested, 4, &thread_count); + p_vcomp_fork(TRUE, 4, num_threads_cb, nested, TRUE, 4, &thread_count); ok(thread_count == 4, "expected 4 threads, got %d\n", thread_count);
p_vcomp_set_num_threads(0); num_threads = pomp_get_num_threads(); ok(num_threads == 1, "expected num_threads == 1, got %d\n", num_threads); thread_count = 0; - p_vcomp_fork(TRUE, 3, num_threads_cb, nested, 4, &thread_count); + p_vcomp_fork(TRUE, 4, num_threads_cb, nested, TRUE, 4, &thread_count); ok(thread_count == 4, "expected 4 threads, got %d\n", thread_count);
pomp_set_num_threads(0); num_threads = pomp_get_num_threads(); ok(num_threads == 1, "expected num_threads == 1, got %d\n", num_threads); thread_count = 0; - p_vcomp_fork(TRUE, 3, num_threads_cb, nested, 4, &thread_count); + p_vcomp_fork(TRUE, 4, num_threads_cb, nested, TRUE, 4, &thread_count); ok(thread_count == 4, "expected 4 threads, got %d\n", thread_count);
pomp_set_num_threads(max_threads); diff --git a/dlls/vcomp/vcomp.spec b/dlls/vcomp/vcomp.spec index dfbd184..5a5b114 100644 --- a/dlls/vcomp/vcomp.spec +++ b/dlls/vcomp/vcomp.spec @@ -98,7 +98,7 @@ @ cdecl omp_get_thread_num() @ stub omp_get_wtick @ cdecl omp_get_wtime() -@ stub omp_in_parallel +@ cdecl omp_in_parallel() @ stub omp_init_lock @ stub omp_init_nest_lock @ cdecl omp_set_dynamic(long) diff --git a/dlls/vcomp100/vcomp100.spec b/dlls/vcomp100/vcomp100.spec index 6eb6ae5..debc5ff 100644 --- a/dlls/vcomp100/vcomp100.spec +++ b/dlls/vcomp100/vcomp100.spec @@ -98,7 +98,7 @@ @ cdecl omp_get_thread_num() vcomp.omp_get_thread_num @ stub omp_get_wtick @ cdecl omp_get_wtime() vcomp.omp_get_wtime -@ stub omp_in_parallel +@ cdecl omp_in_parallel() vcomp.omp_in_parallel @ stub omp_init_lock @ stub omp_init_nest_lock @ cdecl omp_set_dynamic(long) vcomp.omp_set_dynamic diff --git a/dlls/vcomp90/vcomp90.spec b/dlls/vcomp90/vcomp90.spec index 6eb6ae5..debc5ff 100644 --- a/dlls/vcomp90/vcomp90.spec +++ b/dlls/vcomp90/vcomp90.spec @@ -98,7 +98,7 @@ @ cdecl omp_get_thread_num() vcomp.omp_get_thread_num @ stub omp_get_wtick @ cdecl omp_get_wtime() vcomp.omp_get_wtime -@ stub omp_in_parallel +@ cdecl omp_in_parallel() vcomp.omp_in_parallel @ stub omp_init_lock @ stub omp_init_nest_lock @ cdecl omp_set_dynamic(long) vcomp.omp_set_dynamic