/
engine.go
67 lines (54 loc) · 1.23 KB
/
engine.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
58
59
60
61
62
63
64
65
66
67
/*
engine does the simulation bookkeeping, I/O and GUI.
space-dependence:
value: space-independent
param: region-dependent parameter (always input)
field: fully space-dependent field
TODO: godoc everything
*/
package engine
import (
"fmt"
"os"
"runtime"
"sync"
"time"
"github.com/kuchkin/mumax3-gneb/cuda/cu"
"github.com/kuchkin/mumax3-gneb/timer"
)
const VERSION = "mumax 3.10"
var UNAME = fmt.Sprintf("%s [%s_%s %s(%s) CUDA-%d.%d]",
VERSION, runtime.GOOS, runtime.GOARCH, runtime.Version(), runtime.Compiler,
cu.CUDA_VERSION/1000, (cu.CUDA_VERSION%1000)/10)
var StartTime = time.Now()
var (
busyLock sync.Mutex
busy bool // are we so busy we can't respond from run loop? (e.g. calc kernel)
)
// We set SetBusy(true) when the simulation is too busy too accept GUI input on Inject channel.
// E.g. during kernel init.
func SetBusy(b bool) {
busyLock.Lock()
defer busyLock.Unlock()
busy = b
}
func GetBusy() bool {
busyLock.Lock()
defer busyLock.Unlock()
return busy
}
// Cleanly exits the simulation, assuring all output is flushed.
func Close() {
drainOutput()
LogUsedRefs()
Table.flush()
if logfile != nil {
logfile.Close()
}
if bibfile != nil {
bibfile.Close()
}
if *Flag_sync {
timer.Print(os.Stdout)
}
}