Rebase against 813368481679a5848bc715d1e181782de157485f.

This commit is contained in:
Sebastian Lackner
2015-08-06 17:34:47 +02:00
parent 0054a6b6f5
commit 4a9653f221
9 changed files with 34 additions and 509 deletions

View File

@@ -1,207 +0,0 @@
From ae5dc1f9033a941c293ad221c19e5d49c140a13f Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Sun, 19 Jul 2015 01:01:28 +0200
Subject: vcomp: Implement _vcomp_for_dynamic_init and _vcomp_for_dynamic_next.
---
dlls/vcomp/main.c | 77 +++++++++++++++++++++++++++++++++++++++++++++
dlls/vcomp/vcomp.spec | 4 +--
dlls/vcomp100/vcomp100.spec | 4 +--
dlls/vcomp90/vcomp90.spec | 4 +--
4 files changed, 83 insertions(+), 6 deletions(-)
diff --git a/dlls/vcomp/main.c b/dlls/vcomp/main.c
index 301370c..2433abc 100644
--- a/dlls/vcomp/main.c
+++ b/dlls/vcomp/main.c
@@ -64,6 +64,9 @@ struct vcomp_thread_data
/* section */
unsigned int section;
+
+ /* dynamic */
+ unsigned int dynamic;
};
struct vcomp_team_data
@@ -88,6 +91,14 @@ struct vcomp_task_data
unsigned int section;
int num_sections;
int section_index;
+
+ /* dynamic */
+ unsigned int dynamic;
+ unsigned int dynamic_first;
+ unsigned int dynamic_iterations;
+ int dynamic_step;
+ unsigned int dynamic_chunksize;
+ unsigned int dynamic_min_chunksize;
};
#if defined(__i386__)
@@ -200,6 +211,7 @@ static struct vcomp_thread_data *vcomp_init_thread_data(void)
}
data->task.section = 0;
+ data->task.dynamic = 0;
thread_data = &data->thread;
thread_data->team = NULL;
@@ -208,6 +220,7 @@ static struct vcomp_thread_data *vcomp_init_thread_data(void)
thread_data->parallel = FALSE;
thread_data->fork_threads = 0;
thread_data->section = 1;
+ thread_data->dynamic = 1;
vcomp_set_thread_data(thread_data);
return thread_data;
@@ -634,6 +647,66 @@ void CDECL _vcomp_for_static_end(void)
/* nothing to do here */
}
+void CDECL _vcomp_for_dynamic_init(unsigned int flags, unsigned int first, unsigned int last,
+ int step, unsigned int chunksize)
+{
+ struct vcomp_thread_data *thread_data = vcomp_init_thread_data();
+ struct vcomp_task_data *task_data = thread_data->task;
+
+ TRACE("(%u, %u, %u, %d, %u)\n", flags, first, last, step, chunksize);
+
+ EnterCriticalSection(&vcomp_section);
+ thread_data->dynamic++;
+ if ((int)(thread_data->dynamic - task_data->dynamic) > 0)
+ {
+ struct vcomp_team_data *team_data = thread_data->team;
+ int num_threads = team_data ? team_data->num_threads : 1;
+ unsigned int iterations;
+
+ if (flags & 0x40)
+ iterations = 1 + (last - first) / step;
+ else
+ {
+ iterations = 1 + (first - last) / step;
+ step *= -1;
+ }
+
+ task_data->dynamic = thread_data->dynamic;
+ task_data->dynamic_first = first;
+ task_data->dynamic_iterations = iterations;
+ task_data->dynamic_step = step;
+ task_data->dynamic_chunksize = max(1, iterations / num_threads);
+ task_data->dynamic_min_chunksize = max(1, chunksize);
+ }
+ LeaveCriticalSection(&vcomp_section);
+}
+
+int CDECL _vcomp_for_dynamic_next(unsigned int *begin, unsigned int *end)
+{
+ struct vcomp_thread_data *thread_data = vcomp_init_thread_data();
+ struct vcomp_task_data *task_data = thread_data->task;
+ unsigned int iterations = 0;
+
+ TRACE("(%p, %p)\n", begin, end);
+
+ EnterCriticalSection(&vcomp_section);
+ if (thread_data->dynamic == task_data->dynamic &&
+ task_data->dynamic_iterations != 0)
+ {
+ iterations = min(task_data->dynamic_iterations, task_data->dynamic_chunksize);
+ *begin = task_data->dynamic_first;
+ *end = task_data->dynamic_first + (iterations - 1) * task_data->dynamic_step;
+
+ task_data->dynamic_iterations -= iterations;
+ task_data->dynamic_first += iterations * task_data->dynamic_step;
+ task_data->dynamic_chunksize = max((task_data->dynamic_chunksize * 3 + 2)/4,
+ task_data->dynamic_min_chunksize);
+ }
+ LeaveCriticalSection(&vcomp_section);
+
+ return (iterations != 0);
+}
+
int CDECL omp_in_parallel(void)
{
TRACE("()\n");
@@ -711,6 +784,7 @@ void WINAPIV _vcomp_fork(BOOL ifval, int nargs, void *wrapper, ...)
team_data.barrier_count = 0;
task_data.section = 0;
+ task_data.dynamic = 0;
thread_data.team = &team_data;
thread_data.task = &task_data;
@@ -718,6 +792,7 @@ void WINAPIV _vcomp_fork(BOOL ifval, int nargs, void *wrapper, ...)
thread_data.parallel = ifval || prev_thread_data->parallel;
thread_data.fork_threads = 0;
thread_data.section = 1;
+ thread_data.dynamic = 1;
list_init(&thread_data.entry);
InitializeConditionVariable(&thread_data.cond);
@@ -736,6 +811,7 @@ void WINAPIV _vcomp_fork(BOOL ifval, int nargs, void *wrapper, ...)
data->parallel = thread_data.parallel;
data->fork_threads = 0;
data->section = 1;
+ data->dynamic = 1;
list_remove(&data->entry);
list_add_tail(&thread_data.entry, &data->entry);
WakeAllConditionVariable(&data->cond);
@@ -757,6 +833,7 @@ void WINAPIV _vcomp_fork(BOOL ifval, int nargs, void *wrapper, ...)
data->parallel = thread_data.parallel;
data->fork_threads = 0;
data->section = 1;
+ data->dynamic = 1;
InitializeConditionVariable(&data->cond);
thread = CreateThread(NULL, 0, _vcomp_fork_worker, data, 0, NULL);
diff --git a/dlls/vcomp/vcomp.spec b/dlls/vcomp/vcomp.spec
index 3a709df..6e2fcec 100644
--- a/dlls/vcomp/vcomp.spec
+++ b/dlls/vcomp/vcomp.spec
@@ -55,9 +55,9 @@
@ stub _vcomp_copyprivate_receive
@ stub _vcomp_enter_critsect
@ stub _vcomp_flush
-@ stub _vcomp_for_dynamic_init
+@ cdecl _vcomp_for_dynamic_init(long long long long long)
@ stub _vcomp_for_dynamic_init_i8
-@ stub _vcomp_for_dynamic_next
+@ cdecl _vcomp_for_dynamic_next(ptr ptr)
@ stub _vcomp_for_dynamic_next_i8
@ cdecl _vcomp_for_static_end()
@ cdecl _vcomp_for_static_init(long long long long ptr ptr ptr ptr ptr)
diff --git a/dlls/vcomp100/vcomp100.spec b/dlls/vcomp100/vcomp100.spec
index 56c7ae3..ab93ec2 100644
--- a/dlls/vcomp100/vcomp100.spec
+++ b/dlls/vcomp100/vcomp100.spec
@@ -55,9 +55,9 @@
@ stub _vcomp_copyprivate_receive
@ stub _vcomp_enter_critsect
@ stub _vcomp_flush
-@ stub _vcomp_for_dynamic_init
+@ cdecl _vcomp_for_dynamic_init(long long long long long) vcomp._vcomp_for_dynamic_init
@ stub _vcomp_for_dynamic_init_i8
-@ stub _vcomp_for_dynamic_next
+@ cdecl _vcomp_for_dynamic_next(ptr ptr) vcomp._vcomp_for_dynamic_next
@ stub _vcomp_for_dynamic_next_i8
@ cdecl _vcomp_for_static_end() vcomp._vcomp_for_static_end
@ cdecl _vcomp_for_static_init(long long long long ptr ptr ptr ptr ptr) vcomp._vcomp_for_static_init
diff --git a/dlls/vcomp90/vcomp90.spec b/dlls/vcomp90/vcomp90.spec
index 56c7ae3..ab93ec2 100644
--- a/dlls/vcomp90/vcomp90.spec
+++ b/dlls/vcomp90/vcomp90.spec
@@ -55,9 +55,9 @@
@ stub _vcomp_copyprivate_receive
@ stub _vcomp_enter_critsect
@ stub _vcomp_flush
-@ stub _vcomp_for_dynamic_init
+@ cdecl _vcomp_for_dynamic_init(long long long long long) vcomp._vcomp_for_dynamic_init
@ stub _vcomp_for_dynamic_init_i8
-@ stub _vcomp_for_dynamic_next
+@ cdecl _vcomp_for_dynamic_next(ptr ptr) vcomp._vcomp_for_dynamic_next
@ stub _vcomp_for_dynamic_next_i8
@ cdecl _vcomp_for_static_end() vcomp._vcomp_for_static_end
@ cdecl _vcomp_for_static_init(long long long long ptr ptr ptr ptr ptr) vcomp._vcomp_for_static_init
--
2.4.5

View File

@@ -1,112 +0,0 @@
From 6c4782b340f4cd6c9262cda2a4023f3d472e380e Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Sun, 19 Jul 2015 01:05:02 +0200
Subject: vcomp/tests: Add tests for _vcomp_for_dynamic_init.
---
dlls/vcomp/tests/vcomp.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 68 insertions(+)
diff --git a/dlls/vcomp/tests/vcomp.c b/dlls/vcomp/tests/vcomp.c
index f021a72..faa7bd1 100644
--- a/dlls/vcomp/tests/vcomp.c
+++ b/dlls/vcomp/tests/vcomp.c
@@ -51,6 +51,9 @@ static void (CDECL *p_vcomp_atomic_sub_r4)(float *dest, float val);
static void (CDECL *p_vcomp_atomic_sub_r8)(double *dest, double val);
static void (CDECL *p_vcomp_atomic_xor_i4)(int *dest, int val);
static void (CDECL *p_vcomp_barrier)(void);
+static void (CDECL *p_vcomp_for_dynamic_init)(unsigned int flags, unsigned int first, unsigned int last,
+ int step, unsigned int chunksize);
+static int (CDECL *p_vcomp_for_dynamic_next)(unsigned int *begin, unsigned int *end);
static void (CDECL *p_vcomp_for_static_end)(void);
static void (CDECL *p_vcomp_for_static_init)(int first, int last, int step, int chunksize, unsigned int *loops,
int *begin, int *end, int *next, int *lastchunk);
@@ -214,6 +217,8 @@ static BOOL init_vcomp(void)
VCOMP_GET_PROC(_vcomp_atomic_sub_r8);
VCOMP_GET_PROC(_vcomp_atomic_xor_i4);
VCOMP_GET_PROC(_vcomp_barrier);
+ VCOMP_GET_PROC(_vcomp_for_dynamic_init);
+ VCOMP_GET_PROC(_vcomp_for_dynamic_next);
VCOMP_GET_PROC(_vcomp_for_static_end);
VCOMP_GET_PROC(_vcomp_for_static_init);
VCOMP_GET_PROC(_vcomp_for_static_simple_init);
@@ -991,6 +996,68 @@ static void test_atomic_double(void)
}
}
+static void CDECL for_dynamic_cb(LONG *a, LONG *b, LONG *c)
+{
+ unsigned int begin, end;
+
+ p_vcomp_for_dynamic_init(0x40, 1, 999983, 1, 30);
+ while (p_vcomp_for_dynamic_next(&begin, &end))
+ {
+ InterlockedExchangeAdd(a, end - begin + 1);
+ Sleep(1);
+ }
+
+ p_vcomp_for_dynamic_init(0, 99991, 1, 1, 50);
+ while (p_vcomp_for_dynamic_next(&begin, &end))
+ {
+ InterlockedExchangeAdd(b, begin - end + 1);
+ Sleep(1);
+ }
+
+ p_vcomp_for_dynamic_init(0x40, 1, 9973, 7, 30);
+ while (p_vcomp_for_dynamic_next(&begin, &end))
+ {
+ while (begin <= end)
+ {
+ InterlockedIncrement(c);
+ begin += 7;
+ }
+ Sleep(1);
+ }
+}
+
+static void test_vcomp_for_dynamic_init(void)
+{
+ int max_threads = pomp_get_max_threads();
+ LONG a, b, c;
+ int i;
+
+ a = b = c = 0;
+ for_dynamic_cb(&a, &b, &c);
+ ok(a == 999983, "expected a == 999983, got %d\n", a);
+ ok(b == 99991, "expected b == 99991, got %d\n", b);
+ ok(c == 1425, "expected c == 1425, got %d\n", c);
+
+ for (i = 1; i <= 4; i++)
+ {
+ pomp_set_num_threads(i);
+
+ a = b = c = 0;
+ p_vcomp_fork(TRUE, 3, for_dynamic_cb, &a, &b, &c);
+ ok(a == 999983, "expected a == 999983, got %d\n", a);
+ ok(b == 99991, "expected b == 99991, got %d\n", b);
+ ok(c == 1425, "expected c == 1425, got %d\n", c);
+
+ a = b = c = 0;
+ p_vcomp_fork(FALSE, 3, for_dynamic_cb, &a, &b, &c);
+ ok(a == 999983, "expected a == 999983, got %d\n", a);
+ ok(b == 99991, "expected b == 99991, got %d\n", b);
+ ok(c == 1425, "expected c == 1425, got %d\n", c);
+ }
+
+ pomp_set_num_threads(max_threads);
+}
+
START_TEST(vcomp)
{
if (!init_vcomp())
@@ -1002,6 +1069,7 @@ START_TEST(vcomp)
test_vcomp_sections_init();
test_vcomp_for_static_simple_init();
test_vcomp_for_static_init();
+ test_vcomp_for_dynamic_init();
test_atomic_integer32();
test_atomic_float();
test_atomic_double();
--
2.4.5

View File

@@ -1 +0,0 @@
Fixes: [31640] Implement various vcomp functions