We have just released pargo, a library for parallel programming in Go

How should I choose threshold for parallel.Range?

Running:

package main

import (
	"fmt"
	"log"
	"runtime"
	"sync"

	"github.com/ExaScience/pargo/parallel"
)

func main() {
	log.SetFlags(log.Lshortfile)

	fmt.Println("GOMAXPROCS", runtime.GOMAXPROCS(0))

	total := 1000000

	run(total)
	run(total - 1)
}

func run(total int) {
	fmt.Println("total:", total)
	for threshold := -5; threshold < 6; threshold++ {
		mu := &sync.Mutex{}
		count := 0

		parallel.Range(0, total, threshold, func(low, high int) {
			mu.Lock()
			defer mu.Unlock()

			count++
		})

		fmt.Printf("threshold\t%v\tcount\t%v\n", threshold, count)
	}
}

produces:

GOMAXPROCS 2
total: 1000000
threshold	-5	count	262144
threshold	-4	count	262144
threshold	-3	count	475712
threshold	-2	count	524288
threshold	-1	count	1000000
threshold	0	count	1000000
threshold	1	count	2
threshold	2	count	4
threshold	3	count	8
threshold	4	count	8
threshold	5	count	16
total: 999999
threshold	-5	count	262144
threshold	-4	count	262144
threshold	-3	count	475711
threshold	-2	count	524288
threshold	-1	count	999999
threshold	0	count	999999
threshold	1	count	3
threshold	2	count	7
threshold	3	count	8
threshold	4	count	15
threshold	5	count	16

I don’t understand what it is intended to do.