Hello, what is Threshold constant in code for? I wanted to try your code, but with Threshold 1 it take all of 16GB RAM I have and crash on sigkill. When I use Threshold 8 it seems ok, but when I use 64, it again take a lot of RAM... I thought it's count of Threads that program will use, while running on CPU. But it does give unexpected or strange results.
Dátum: štvrtok 14. apríla 2011, čas: 14:55:09 UTC+2, odosielateľ: Dmitry Vyukov > Hi, > > I want to create a parallel matrix multiplication benchmark for Go. I used > to fork-join style parallelism, so I implemented it as follows: > > type Matrix [][]float64 > > func matrix_make(n int) Matrix { > M := make([][]float64, n); > for i := 0; i != n; i += 1 { > M[i] = make([]float64, n) > } > return M > } > > const (Threshold = 8) > > func matmult_pimpl (sync chan int, A Matrix, B Matrix, C Matrix, i0 int, > i1 int, j0 int, j1 int, k0 int, k1 int) { > di := i1 - i0 > dj := j1 - j0 > dk := k1 - k0 > if (di >= dj && di >= dk && di >= Threshold) { > mi := i0 + di / 2 > sync0 := make(chan int, 1) > go matmult_pimpl(sync0, A, B, C, i0, mi, j0, j1, k0, k1) > matmult_pimpl(nil, A, B, C, mi, i1, j0, j1, k0, k1) > <- sync0 > } else if (dj >= dk && dj >= Threshold) { > mj := j0 + dj / 2 > sync0 := make(chan int, 1) > go matmult_pimpl(sync0, A, B, C, i0, i1, j0, mj, k0, k1) > matmult_pimpl(nil, A, B, C, i0, i1, mj, j1, k0, k1) > <- sync0 > } else if (dk >= Threshold) { > mk := k0 + dk / 2 > matmult_pimpl(nil, A, B, C, i0, i1, j0, j1, k0, mk) > matmult_pimpl(nil, A, B, C, i0, i1, j0, j1, mk, k1) > } else { > for i := i0; i < i1; i += 1 { > for j := j0; j < j1; j += 1 { > for k := k0; k < k1; k += 1 { > C[i][j] += A[i][k] * B[k][j]; > } > } > } > } > if sync != nil { > sync <- 0 > } > } > > func matmult_parallel(A Matrix, B Matrix) Matrix { > n := len(A) > C := matrix_make(n) > matmult_pimpl(nil, A, B, C, 0, n, 0, n, 0, n) > return C > } > > Is it a good implementation for Go? Is it enough "Go-ish"? What would be a > "canonical" way? > TIA > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/32e55537-d2d0-4e9a-8425-c85ad6a790a1n%40googlegroups.com.