Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "runtime"
- )
- // Tune me!
- const batchSize = 5000
- func main() {
- // Tune me!
- runtime.GOMAXPROCS(runtime.NumCPU())
- primes := make(chan uint32)
- jobs := make(chan uint32)
- fmt.Println("1")
- fmt.Println("2")
- // Tune me!
- numJobs := runtime.NumCPU()
- for i := 0; i < numJobs; i++ {
- go func() {
- for x := range jobs {
- next:
- for end := x + batchSize; x < end; x += 2 {
- if x%2 == 0 {
- continue
- }
- for j := uint32(3); j < x; j += 2 {
- if x%j == 0 {
- continue next
- }
- }
- primes <- x
- }
- }
- }()
- }
- highest := uint32(2)
- go func() {
- for i := uint32(3); ; i += batchSize {
- jobs <- i
- }
- }()
- for prime := range primes {
- if prime > highest {
- highest = prime
- fmt.Printf("%d\n", prime)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement