提交 e39e14d1 编写于 作者: H Helin Wang

handle error from s.opt.UpdateParameter

上级 bc33f9b1
...@@ -109,6 +109,11 @@ func (s *Service) SendGrads(grads []Gradient, dummy *int) error { ...@@ -109,6 +109,11 @@ func (s *Service) SendGrads(grads []Gradient, dummy *int) error {
return ErrUnintialized return ErrUnintialized
} }
count := len(grads)
if count == 0 {
return nil
}
s.mu.Lock() s.mu.Lock()
defer s.mu.Unlock() defer s.mu.Unlock()
...@@ -118,16 +123,25 @@ func (s *Service) SendGrads(grads []Gradient, dummy *int) error { ...@@ -118,16 +123,25 @@ func (s *Service) SendGrads(grads []Gradient, dummy *int) error {
} }
} }
var wg sync.WaitGroup errCh := make(chan error, count)
for _, g := range grads { for _, g := range grads {
wg.Add(1)
go func(p Parameter, g Gradient) { go func(p Parameter, g Gradient) {
s.opt.UpdateParameter(p, g) err := s.opt.UpdateParameter(p, g)
wg.Done() errCh <- err
}(s.paramMap[g.Name], g) }(s.paramMap[g.Name], g)
} }
wg.Wait() recv := 0
for err := range errCh {
if err != nil {
return err
}
recv++
if recv == count {
break
}
}
return nil return nil
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册