-
Notifications
You must be signed in to change notification settings - Fork 70
/
randcheck.go
38 lines (34 loc) · 892 Bytes
/
randcheck.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (c) 2021, Cogent Core. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package tensormpi
import (
"errors"
"fmt"
"math/rand"
"cogentcore.org/core/base/mpi"
)
// RandCheck checks that the current random numbers generated across each
// MPI processor are identical. Most emergent simulations depend on this
// being true, so it is good to check periodically to ensure!
func RandCheck(comm *mpi.Comm) error {
ws := comm.Size()
rnd := rand.Int()
src := []int{rnd}
agg := make([]int, ws)
err := comm.AllGatherInt(agg, src)
if err != nil {
return err
}
errs := ""
for i := range agg {
if agg[i] != rnd {
errs += fmt.Sprintf("%d ", i)
}
}
if errs != "" {
err = errors.New("tensormpi.RandCheck: random numbers differ in procs: " + errs)
mpi.Printf("%s\n", err)
}
return err
}