2022-02-12 20:38:07 +03:00
|
|
|
module main
|
|
|
|
|
|
|
|
import benchmark
|
|
|
|
import sim
|
|
|
|
import sim.anim
|
|
|
|
import sim.args as simargs
|
|
|
|
|
|
|
|
fn main() {
|
2022-10-16 09:28:57 +03:00
|
|
|
args := simargs.parse_args(extra_workers: 1)! as simargs.ParallelArgs
|
2022-02-12 20:38:07 +03:00
|
|
|
|
|
|
|
mut app := anim.new_app(args)
|
|
|
|
mut workers := []thread{cap: args.workers}
|
|
|
|
|
|
|
|
mut bmark := benchmark.start()
|
|
|
|
|
|
|
|
defer {
|
|
|
|
app.request_chan.close()
|
|
|
|
sim.log('Waiting for workers to finish')
|
|
|
|
workers.wait()
|
|
|
|
app.result_chan.close()
|
|
|
|
sim.log('Workers finished!')
|
|
|
|
bmark.measure(@FN)
|
|
|
|
sim.log('Done!')
|
|
|
|
}
|
|
|
|
|
|
|
|
for id in 0 .. args.workers {
|
|
|
|
workers << go sim.sim_worker(id, app.request_chan, [app.result_chan])
|
|
|
|
}
|
|
|
|
|
2022-10-16 09:28:57 +03:00
|
|
|
handle_request := fn [app] (request &sim.SimRequest) ! {
|
2022-02-12 20:38:07 +03:00
|
|
|
app.request_chan <- request
|
|
|
|
}
|
|
|
|
|
|
|
|
go app.gg.run()
|
|
|
|
|
|
|
|
sim.run(args.params, grid: args.grid, on_request: sim.SimRequestHandler(handle_request))
|
|
|
|
}
|