Re: [C backend] Environment of closure on stack

2019-12-06 Thread mratsim
In the end, I used explicit captures with the following syntax:


block:
proc main() =
  init(Weave)
  
  parallelFor i in 0 ..< 100:
log("%d (thread %d)\n", i, myID())
  
  exit(Weave)

# main()
  
  block: # Capturing outside scope
proc main2() =
  init(Weave)
  
  var a = 100
  var b = 10
  parallelFor i in 0 ..< 10:
captures: {a, b}
log("a+b+i = %d (thread %d)\n", a+i, myID())
  
  exit(Weave)



# main2()
  
  
  block: # Nested loops
proc main3() =
  init(Weave)
  
  parallelFor i in 0 ..< 4:
parallelFor j in 0 ..< 8:
  captures: {i}
  log("Matrix[%d, %d] (thread %d)\n", i, j, myID())
  
  exit(Weave)

main3()


Run

>From 
>[Weave](https://github.com/mratsim/weave/blob/c1fc73477ee7572ae635fb6246aad74b844ba8e2/weave/parallel_for.nim#L192-L239)
> multithreading runtime


Re: [C backend] Environment of closure on stack

2019-12-06 Thread foldl
If `gc:none`, linking will fail with undefined `newObj`.

Is it a good idea to put `env` on stack for `gc:none`?


Re: [C backend] Environment of closure on stack

2019-12-03 Thread mratsim
I also require more ways to manipulate closures or being able to implement my 
own from macros.

This would allow me to emulate the OpenMP API or the `parallel` API in my 
multithreading runtime.

I still have to explore the liftLocal pragma or the `owner` macro though 
([https://forum.nim-lang.org/t/4031#25106](https://forum.nim-lang.org/t/4031#25106)
 / 
[https://github.com/nim-lang/Nim/pull/8253](https://github.com/nim-lang/Nim/pull/8253))


[C backend] Environment of closure on stack

2019-12-03 Thread foldl
Hi all,

Env-s are allocated on heap by `newObj`. Is it possible to put them on stack? 
There are some cons, such as closure can't live out of a function's scope. But, 
in the case of truly embedded systems with only several KiB RAM with 
`-gc:regions`, env-s on stack is good enough, ^_^