added parallel for test case
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 4 Jan 2022 00:09:21 +0000 (18:09 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 4 Jan 2022 00:09:21 +0000 (18:09 -0600)
scripts/run_tests.onyx
tests/parallel_for [new file with mode: 0644]
tests/parallel_for.onyx [new file with mode: 0644]

index 41e36f621d5307bdde0c1e337c218fb806f2525d..54ca53aaa4408ab93de70d4cd7ddc247f13eb7df 100644 (file)
@@ -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 (file)
index 0000000..4932792
--- /dev/null
@@ -0,0 +1 @@
+50015001
diff --git a/tests/parallel_for.onyx b/tests/parallel_for.onyx
new file mode 100644 (file)
index 0000000..a827bcf
--- /dev/null
@@ -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);
+}
+