From 34409088d79d314b1cc7507871315c7e13e0fe28 Mon Sep 17 00:00:00 2001 From: Oliver Tonnhofer Date: Mon, 6 May 2013 10:21:03 +0200 Subject: [PATCH] make wayFill parallel --- parser.go | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/parser.go b/parser.go index 10df190..737b7c6 100644 --- a/parser.go +++ b/parser.go @@ -109,7 +109,7 @@ func main() { } log.SetFlags(log.LstdFlags | log.Llongfile) - //runtime.GOMAXPROCS(runtime.NumCPU()) + runtime.GOMAXPROCS(runtime.NumCPU()) flag.Parse() osmCache, err := cache.NewOSMCache("/tmp/goposm") if err != nil { @@ -117,7 +117,7 @@ func main() { } defer osmCache.Close() - //parse(osmCache, flag.Arg(0)) + // parse(osmCache, flag.Arg(0)) fmt.Println("foo") //rel := osmCache.Relations.Iter() @@ -126,27 +126,36 @@ func main() { //} way := osmCache.Ways.Iter() - i := 0 refCache, err := cache.NewRefIndex("/tmp/refindex") if err != nil { log.Fatal(err) } - for w := range way { - i += 1 - ok := osmCache.Coords.FillWay(w) - if !ok { - continue - } - if true { - for _, node := range w.Nodes { - refCache.Add(node.Id, w.Id) + + waitFill := sync.WaitGroup{} + for i := 0; i < runtime.NumCPU(); i++ { + waitFill.Add(1) + + go func() { + i := 0 + for w := range way { + ok := osmCache.Coords.FillWay(w) + if !ok { + continue + } + if true { + for _, node := range w.Nodes { + refCache.Add(node.Id, w.Id) + } + } + if i%1000 == 0 { + fmt.Println(i) + } + i++ } - } - if i%1000 == 0 { - fmt.Println(i) - } + waitFill.Done() + }() } - fmt.Println(i) + waitFill.Wait() //parser.PBFStats(os.Args[1]) fmt.Println("done") }