mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
All an option to limit number of CPU
This commit is contained in:
@ -2,6 +2,7 @@ package obioptions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
@ -10,6 +11,7 @@ import (
|
||||
|
||||
var _Debug = false
|
||||
var _ParallelWorkers = runtime.NumCPU() - 1
|
||||
var _MaxAllowedCPU = runtime.NumCPU()
|
||||
var _BufferSize = 1
|
||||
var _BatchSize = 5000
|
||||
|
||||
@ -20,7 +22,11 @@ func GenerateOptionParser(optionset ...func(*getoptions.GetOpt)) ArgumentParser
|
||||
options.Bool("help", false, options.Alias("h", "?"))
|
||||
options.BoolVar(&_Debug, "debug", false)
|
||||
|
||||
options.IntVar(&_ParallelWorkers, "workers", runtime.NumCPU()-1,
|
||||
options.IntVar(&_ParallelWorkers, "workers", _ParallelWorkers,
|
||||
options.Alias("w"),
|
||||
options.Description("Number of parallele threads computing the result"))
|
||||
|
||||
options.IntVar(&_MaxAllowedCPU, "max-cpu", _MaxAllowedCPU,
|
||||
options.Alias("w"),
|
||||
options.Description("Number of parallele threads computing the result"))
|
||||
|
||||
@ -32,6 +38,12 @@ func GenerateOptionParser(optionset ...func(*getoptions.GetOpt)) ArgumentParser
|
||||
|
||||
remaining, err := options.Parse(args[1:])
|
||||
|
||||
// Setup the maximum number of CPU usable by the program
|
||||
runtime.GOMAXPROCS(_MaxAllowedCPU)
|
||||
if options.Called("max-cpu") {
|
||||
log.Printf("CPU number limited to %d", _MaxAllowedCPU)
|
||||
}
|
||||
|
||||
if options.Called("help") {
|
||||
fmt.Fprint(os.Stderr, options.Help())
|
||||
os.Exit(1)
|
||||
@ -51,6 +63,12 @@ func CLIParallelWorkers() int {
|
||||
return _ParallelWorkers
|
||||
}
|
||||
|
||||
// CLIParallelWorkers returns the number of parallel workers requested by
|
||||
// the command line option --workers|-w.
|
||||
func CLIMaxCPU() int {
|
||||
return _MaxAllowedCPU
|
||||
}
|
||||
|
||||
// CLIBufferSize returns the expeted channel buffer size for obitools
|
||||
func CLIBufferSize() int {
|
||||
return _BufferSize
|
||||
|
Reference in New Issue
Block a user