Changes

Jump to: navigation, search

GPU621/Go Kimchi

216 bytes added, 15:52, 3 August 2021
Implementation
"strings"
"sync"
"time"
)
func multiply(A [][]int, B [][]int) [][]int { sizeA := len(A)
}
}
return n
}
func splitMatrix(nrOfThreads int, matrix [][]int) (matrixes [][][]int) {
for i := 0; i < nrOfThreads; i++ {
matrixes = append(matrixes, matrix[splitter*i:(splitter*(i+1))])
}
return
}
func multiplyStuff(finalMatrix *[][][]int, matrix1 [][]int, matrix2 [][]int, i int) {
(*finalMatrix)[i] = multiply(matrix1, matrix2)
}
func readFile(filePath string) (matrix1 [][]int, matrix2 [][]int) {
scanner := bufio.NewScanner(file)
for scanner.Scan() {
words := strings.Fields(scanner.Text()) if len(words) != 0 {
for _, element := range words {
i, err := strconv.Atoi(element)
} else {
matrix2 = append(matrix2, temp)
}
temp = nil
} else {
matrixNr = 2
}
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
} return
}
func main() {
file := os.Args[1] nrOfThreads, err := strconv.Atoi(os.Args[2]) if err != nil { log.Fatal("USAGE: " + os.Args[0] + " <file> <nrOfThreads>") }
debug.SetGCPercent(-1)
if nrOfThreads <= 0 {
}
var wg sync.WaitGroup
finishedMatrix := make([][][]int, nrOfThreads)
matrix1, matrix2 := readFile(file)
if len(matrix1) != len(matrix2) || (nrOfThreads != 0 && len(matrix1)%nrOfThreads != 0) {
log.Fatal("USAGE: " + os.Args[0] + " <file> <nrOfThreads>")
} var start int64 if nrOfThreads == 0 { start = time.Now().UnixNano() multiply(matrix1, matrix2) } else { matrixes := splitMatrix(nrOfThreads, matrix1) start = time.Now().UnixNano()
for i := 0; i < nrOfThreads; i++ {
wg.Add(1)
go func(index int) { defer wg.Done() multiplyStuff(&finishedMatrix, matrixes[index], matrix2, index)
}(i)
}
wg.Wait()
}
end := time.Now().UnixNano()
84
edits

Navigation menu