forked from mallano/gofem
/
errorhandler.go
57 lines (51 loc) · 1.21 KB
/
errorhandler.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2015 Dorival Pedroso and Raul Durand. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package fem
import (
"log"
"github.com/cpmech/gosl/chk"
"github.com/cpmech/gosl/io"
"github.com/cpmech/gosl/mpi"
)
func LogErr(err error, msg string) (stop bool) {
if err != nil {
fullmsg := "ERROR: " + msg + " : " + err.Error()
log.Printf(fullmsg)
Global.WspcStop[Global.Rank] = 1
return true
}
return
}
func LogErrCond(condition bool, msg string, prm ...interface{}) (stop bool) {
if condition {
fullmsg := "ERROR: " + io.Sf(msg, prm...)
log.Printf(fullmsg)
Global.WspcStop[Global.Rank] = 1
return true
}
return
}
func Stop() bool {
if !Global.Distr {
if Global.WspcStop[Global.Rank] > 0 {
chk.CallerInfo(3)
chk.CallerInfo(2)
io.PfRed("simulation stopped due to errors. see log files\n")
return true
}
return false
}
mpi.IntAllReduceMax(Global.WspcStop, Global.WspcInum)
for i := 0; i < Global.Nproc; i++ {
if Global.WspcStop[i] > 0 {
if Global.Root {
chk.CallerInfo(3)
chk.CallerInfo(2)
io.PfRed("simulation stopped due to errors. see log files\n")
}
return true
}
}
return false
}