I have copied the example (computing Pi) from the _experimental features_ 
document, but I have replaced a simple _float_ variable by an _object which 
contains a seq[float] variable_ , since this comes closer to my real 
application.

I don't understand the error message

_Error: type mismatch: got 'FlowVar[seq[float]]' for 'spawn term(k), 
nimCreateFlowVar' but expected 'seq[float]'_

Here is the code
    
    
    # nim c  --threads:on  -r ParPiObj.nim
    
    type
      Coeff = object
        c : seq[float]
    
    # Compute PI in an inefficient way
    import strutils, math, threadpool
    # {.experimental: "parallel".}
    
    proc term(k: int): seq[float] =
      result= @[(if (k and 1) == 0 : 1.0 else: -1.0) * 4.0/(float(k+k) + 1.0)]
    
    proc pi(n: int): float =
      var ch = newSeq[Coeff](n+1)
      {.push experimental: "parallel".}
      parallel:
        for k in 0..ch.high:
          ch[k].c = spawn term(k)
    #[ gives Error: type mismatch: got 'FlowVar[seq[float]]'
       for 'spawn term(k), nimCreateFlowVar' but expected 'seq[float]'
    ]#
      for k in 0..ch.high:
        result += ch[k].c
      
      {.pop.}
    
    echo formatFloat(pi(5000))
    
    
    Run

Many thanks for some hints or pointers to additional documentation, Helmut 

Reply via email to