Created
February 27, 2015 01:13
-
-
Save lucasuyezu/559ff2f44e4c8b1f0271 to your computer and use it in GitHub Desktop.
Load Balancing between the number of available procs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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