-
Notifications
You must be signed in to change notification settings - Fork 0
/
sparselu-crash-mwe.go
127 lines (107 loc) · 2.75 KB
/
sparselu-crash-mwe.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package main
import (
"flag"
"fmt"
"runtime"
"sync"
)
var matrixSize, submatrixSize int
/***********************************************************************
* genmat:
**********************************************************************/
func genmat(M []*[][]float32) {
var null_entry bool
for ii := 0; ii < matrixSize; ii++ {
for jj := 0; jj < matrixSize; jj++ {
null_entry = false
if (ii < jj) && (ii%3 != 0) {
null_entry = true
}
if (ii > jj) && (jj%3 != 0) {
null_entry = true
}
if ii%2 == 1 {
null_entry = true
}
if jj%2 == 1 {
null_entry = true
}
if ii == jj {
null_entry = false
}
if ii == jj-1 {
null_entry = false
}
if ii-1 == jj {
null_entry = false
}
if null_entry == false {
subMatrix := make([][]float32, submatrixSize)
for i := range subMatrix {
subMatrix[i] = make([]float32, submatrixSize)
}
M[ii*matrixSize+jj] = &subMatrix
} else {
M[ii*matrixSize+jj] = nil
}
}
}
}
/***********************************************************************
* bmod:
**********************************************************************/
func bmod(row [][]float32, col [][]float32, inner [][]float32) {
for i := 0; i < submatrixSize; i++ {
for j := 0; j < submatrixSize; j++ {
for k := 0; k < submatrixSize; k++ {
inner[i][j] = inner[i][j] - row[i][k]*col[k][j]
}
}
}
}
func sparselu_init(pBENCH *[]*[][]float32, pass string) {
*pBENCH = make([]*[][]float32, matrixSize*matrixSize)
genmat(*pBENCH)
}
func sparselu_par_call(BENCH []*[][]float32) {
var wg sync.WaitGroup
for kk := 0; kk < matrixSize; kk++ {
for ii := kk + 1; ii < matrixSize; ii++ {
if BENCH[ii*matrixSize+kk] != nil {
for jj := kk + 1; jj < matrixSize; jj++ {
if BENCH[kk*matrixSize+jj] != nil {
//#pragma omp task untied firstprivate(kk, jj, ii) shared(BENCH)
wg.Add(1)
jj := jj
go func(wg *sync.WaitGroup) {
defer (*wg).Done()
if BENCH[ii*matrixSize+jj] == nil {
subMatrix := make([][]float32, submatrixSize)
// go-style initializing 2d matrix in a loop
for i := range subMatrix {
subMatrix[i] = make([]float32, submatrixSize)
}
BENCH[ii*matrixSize+jj] = &subMatrix
}
bmod(*BENCH[ii*matrixSize+kk], *BENCH[kk*matrixSize+jj], *BENCH[ii*matrixSize+jj])
}(&wg)
}
}
wg.Wait()
}
}
}
}
func main() {
runtime.GOMAXPROCS(47)
flag.IntVar(&matrixSize, "n", 50, "Matrix size")
flag.IntVar(&submatrixSize, "m", 100, "Submatrix size")
flag.Parse()
var matrixPar []*[][]float32
sparselu_init(&matrixPar, "Parallel")
{
// we're not measuring initialization time, just like BOTS
sparselu_par_call(matrixPar)
}
fmt.Println("Program ended")
}