v / examples / pendulum-simulation
Raw file | 37 loc (28 sloc) | 790 bytes | Latest commit hash e81e0ac70
1module main
2
3import benchmark
4import sim
5import sim.anim
6import sim.args as simargs
7
8fn main() {
9 args := simargs.parse_args(extra_workers: 1)! as simargs.ParallelArgs
10
11 mut app := anim.new_app(args)
12 mut workers := []thread{cap: args.workers}
13
14 mut bmark := benchmark.start()
15
16 defer {
17 app.request_chan.close()
18 sim.log('Waiting for workers to finish')
19 workers.wait()
20 app.result_chan.close()
21 sim.log('Workers finished!')
22 bmark.measure(@FN)
23 sim.log('Done!')
24 }
25
26 for id in 0 .. args.workers {
27 workers << spawn sim.sim_worker(id, app.request_chan, [app.result_chan])
28 }
29
30 handle_request := fn [app] (request &sim.SimRequest) ! {
31 app.request_chan <- request
32 }
33
34 spawn app.gg.run()
35
36 sim.run(args.params, grid: args.grid, on_request: sim.SimRequestHandler(handle_request))
37}