Don't use that code - instead pick up something modern and well-supported like https://www.gonum.org/
On Sat, Mar 27, 2021 at 3:23 PM Gabriel Pcklub <[email protected]> wrote: > thanks for explanation, well, how can I change that code, so it will take > count of Threads (or gorutines) instead size of matrix for one gorutine? > > Dátum: štvrtok 25. marca 2021, čas: 19:21:02 UTC+1, odosielateľ: > [email protected] > >> Blast from the past so it's hard to be sure, but I think that was how >> many rows or columns to pick for parallel sub matrices to multiply. >> >> On Thu, Mar 25, 2021, 1:17 PM Gabriel Pcklub <[email protected]> >> wrote: >> >>> 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 a topic in the >>> Google Groups "golang-nuts" group. >>> To unsubscribe from this topic, visit >>> https://groups.google.com/d/topic/golang-nuts/RVX-BhHcugM/unsubscribe. >>> To unsubscribe from this group and all its topics, send an email to >>> [email protected]. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/golang-nuts/32e55537-d2d0-4e9a-8425-c85ad6a790a1n%40googlegroups.com >>> <https://groups.google.com/d/msgid/golang-nuts/32e55537-d2d0-4e9a-8425-c85ad6a790a1n%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- > You received this message because you are subscribed to a topic in the > Google Groups "golang-nuts" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/golang-nuts/RVX-BhHcugM/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/8fa9bb79-938a-4f89-a0c9-792776151a6en%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/8fa9bb79-938a-4f89-a0c9-792776151a6en%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAEc0J6ZHgORaakD22YtvQkhB9rLN8CrtxZaPw5Bdf6V8d24QwA%40mail.gmail.com.
