From: Brendan Hansen Date: Tue, 4 Jan 2022 00:09:21 +0000 (-0600) Subject: added parallel for test case X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=5bac039c31e4858ad7e64a7b2560c3f9cf395575;p=onyx.git added parallel for test case --- diff --git a/scripts/run_tests.onyx b/scripts/run_tests.onyx index 41e36f62..54ca53aa 100644 --- a/scripts/run_tests.onyx +++ b/scripts/run_tests.onyx @@ -9,24 +9,6 @@ use package core use package core.intrinsics.onyx { init } #local runtime :: package runtime -#if false { - @Relocate - divide_array :: (arr: [] $T, divisions: [] [] T) { - if divisions.count == 0 do return; - - chunk_size := arr.count / divisions.count; - - i := 0; - for ^ divisions { - low := i*chunk_size; - high := (i+1)*chunk_size; - if i == divisions.count - 1 do high = divisions.count; - *it = arr[low .. high]; - i += 1; - } - } -} - Color :: enum { White; Red; diff --git a/tests/parallel_for b/tests/parallel_for new file mode 100644 index 00000000..49327921 --- /dev/null +++ b/tests/parallel_for @@ -0,0 +1 @@ +50015001 diff --git a/tests/parallel_for.onyx b/tests/parallel_for.onyx new file mode 100644 index 00000000..a827bcfd --- /dev/null +++ b/tests/parallel_for.onyx @@ -0,0 +1,22 @@ +#load "core/std" + +use package core + +main :: (args) => { + sum := 0; + + thread_data: struct { + sum : ^i32; + mutex: sync.Mutex; + }; + thread_data.sum = ^sum; + sync.mutex_init(^thread_data.mutex); + + iter.parallel_for(0 .. 10000, 4, ^thread_data) { + sync.scoped_mutex(^thread_data.mutex); + *thread_data.sum += it; + } + + println(sum); +} +