summary refs log tree commit diff stats
path: root/tests/parallel
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2014-06-01 01:45:44 +0200
committerAraq <rumpf_a@web.de>2014-06-01 01:45:44 +0200
commit40baebebfe425f03fbdd41da4c6d2e4c6778d241 (patch)
tree072fa3f048281412c03a12d6d80e49589d0ab930 /tests/parallel
parent9953e0bbca92d81e41a5ca39981b02596027f236 (diff)
downloadNim-40baebebfe425f03fbdd41da4c6d2e4c6778d241.tar.gz
pi test compiles, but crashes randomly
Diffstat (limited to 'tests/parallel')
-rw-r--r--tests/parallel/tpi.nim22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/parallel/tpi.nim b/tests/parallel/tpi.nim
new file mode 100644
index 000000000..de5aa9a51
--- /dev/null
+++ b/tests/parallel/tpi.nim
@@ -0,0 +1,22 @@
+
+import strutils, math, threadpool
+
+proc term(k: float): float = 4 * math.pow(-1, k) / (2*k + 1)
+
+proc piU(n: int): float =
+  var ch = newSeq[Promise[float]](n+1)
+  for k in 0..n:
+    ch[k] = spawn term(float(k))
+  for k in 0..n:
+    result += ^ch[k]
+
+proc piS(n: int): float =
+  var ch = newSeq[float](n+1)
+  parallel:
+    for k in 0..ch.high:
+      ch[k] = spawn term(float(k))
+  for k in 0..ch.high:
+    result += ch[k]
+
+echo formatFloat(piU(5000))
+echo formatFloat(piS(5000))