pi test compiles, but crashes randomly
This commit is contained in:
parent
9953e0bbca
commit
40baebebfe
4 changed files with 43 additions and 6 deletions
22
tests/parallel/tpi.nim
Normal file
22
tests/parallel/tpi.nim
Normal file
|
|
@ -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))
|
||||
Loading…
Add table
Add a link
Reference in a new issue