ethomas2/counting-nodes

saw your post on reddit

Opened this issue · 1 comments

func main3() {
	var n uint64

	if *ngoroutines == 0 {
		n = uint64(runtime.GOMAXPROCS(0))
	} else {
		n = uint64(*ngoroutines)
	}

	fmt.Println("GOMAXPROCS", n)

	result := make(chan uint64)
	var i uint64

	for i = 0; i < n; i++ {
		go func(i uint64) {
			var sum uint64
			var start = (LIMIT / n) * i
			var end = start + (LIMIT / n)

			for j := start; j < end; j++ {
				sum += j
			}
			result <- sum
		}(i)
	}

	var total uint64
	for i = 0; i < n; i++ {
		total += <-result
	}

	fmt.Println(total)
}

Thank you