Skip to content

Instantly share code, notes, and snippets.

@lucasuyezu
Created February 27, 2015 01:13
Show Gist options
  • Save lucasuyezu/559ff2f44e4c8b1f0271 to your computer and use it in GitHub Desktop.
Save lucasuyezu/559ff2f44e4c8b1f0271 to your computer and use it in GitHub Desktop.
Load Balancing between the number of available procs
package main
import (
"fmt"
"runtime"
)
func main() {
procs := runtime.GOMAXPROCS(0)
lines := []int{2, 3, 5, 7, 11, 13}
numArrays := procs
lo := 0
hi := len(lines)
step := 1
if procs >= len(lines) {
numArrays = len(lines)
hi = 1
} else {
hi /= procs
step = hi
}
fmt.Printf("Temos %d procs:\n", procs)
fmt.Printf("Temos %d itens:\n", len(lines))
fmt.Printf("Temos %d arrays:\n", numArrays)
for i := 1; i <= numArrays; i++ {
if i == numArrays {
hi = len(lines)
}
fmt.Println(lines[lo:hi])
lo = hi
hi = hi + step
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment