mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
introduce obidefault
This commit is contained in:
26
pkg/obidefault/batch.go
Normal file
26
pkg/obidefault/batch.go
Normal file
@ -0,0 +1,26 @@
|
||||
package obidefault
|
||||
|
||||
var _BatchSize = 2000
|
||||
|
||||
// SetBatchSize sets the size of the sequence batches.
|
||||
//
|
||||
// n - an integer representing the size of the sequence batches.
|
||||
func SetBatchSize(n int) {
|
||||
_BatchSize = n
|
||||
}
|
||||
|
||||
// CLIBatchSize returns the expected size of the sequence batches.
|
||||
//
|
||||
// In Obitools, the sequences are processed in parallel by batches.
|
||||
// The number of sequence in each batch is determined by the command line option
|
||||
// --batch-size and the environment variable OBIBATCHSIZE.
|
||||
//
|
||||
// No parameters.
|
||||
// Returns an integer value.
|
||||
func BatchSize() int {
|
||||
return _BatchSize
|
||||
}
|
||||
|
||||
func BatchSizePtr() *int {
|
||||
return &_BatchSize
|
||||
}
|
15
pkg/obidefault/compressed.go
Normal file
15
pkg/obidefault/compressed.go
Normal file
@ -0,0 +1,15 @@
|
||||
package obidefault
|
||||
|
||||
var __compressed__ = false
|
||||
|
||||
func CompressOutput() bool {
|
||||
return __compressed__
|
||||
}
|
||||
|
||||
func SetCompressOutput(b bool) {
|
||||
__compressed__ = b
|
||||
}
|
||||
|
||||
func CompressedPtr() *bool {
|
||||
return &__compressed__
|
||||
}
|
32
pkg/obidefault/taxonomy.go
Normal file
32
pkg/obidefault/taxonomy.go
Normal file
@ -0,0 +1,32 @@
|
||||
package obidefault
|
||||
|
||||
var __taxonomy__ = ""
|
||||
var __alternative_name__ = false
|
||||
|
||||
func SelectedTaxonomy() string {
|
||||
return __taxonomy__
|
||||
}
|
||||
|
||||
func HasSelectedTaxonomy() bool {
|
||||
return __taxonomy__ != ""
|
||||
}
|
||||
|
||||
func AreAlternativeNamesSelected() bool {
|
||||
return __alternative_name__
|
||||
}
|
||||
|
||||
func SelectedTaxonomyPtr() *string {
|
||||
return &__taxonomy__
|
||||
}
|
||||
|
||||
func AlternativeNamesSelectedPtr() *bool {
|
||||
return &__alternative_name__
|
||||
}
|
||||
|
||||
func SetSelectedTaxonomy(taxonomy string) {
|
||||
__taxonomy__ = taxonomy
|
||||
}
|
||||
|
||||
func SetAlternativeNamesSelected(alt bool) {
|
||||
__alternative_name__ = alt
|
||||
}
|
170
pkg/obidefault/workers.go
Normal file
170
pkg/obidefault/workers.go
Normal file
@ -0,0 +1,170 @@
|
||||
package obidefault
|
||||
|
||||
import "runtime"
|
||||
|
||||
var _MaxAllowedCPU = runtime.NumCPU()
|
||||
var _WorkerPerCore = 1.0
|
||||
|
||||
var _ReadWorkerPerCore = 0.25
|
||||
var _WriteWorkerPerCore = 0.25
|
||||
|
||||
var _StrictReadWorker = 0
|
||||
var _StrictWriteWorker = 0
|
||||
|
||||
var _ParallelFilesRead = 0
|
||||
|
||||
// CLIParallelWorkers returns the number of parallel workers used for
|
||||
// computing the result.
|
||||
//
|
||||
// The number of parallel workers is determined by the command line option
|
||||
// --max-cpu|-m and the environment variable OBIMAXCPU. This number is
|
||||
// multiplied by the variable _WorkerPerCore.
|
||||
//
|
||||
// No parameters.
|
||||
// Returns an integer representing the number of parallel workers.
|
||||
func ParallelWorkers() int {
|
||||
return int(float64(MaxCPU()) * float64(WorkerPerCore()))
|
||||
}
|
||||
|
||||
// CLIMaxCPU returns the maximum number of CPU cores allowed.
|
||||
//
|
||||
// The maximum number of CPU cores is determined by the command line option
|
||||
// --max-cpu|-m and the environment variable OBIMAXCPU.
|
||||
//
|
||||
// No parameters.
|
||||
// Returns an integer representing the maximum number of CPU cores allowed.
|
||||
func MaxCPU() int {
|
||||
return _MaxAllowedCPU
|
||||
}
|
||||
|
||||
func MaxCPUPtr() *int {
|
||||
return &_MaxAllowedCPU
|
||||
}
|
||||
|
||||
// WorkerPerCore returns the number of workers per CPU core.
|
||||
//
|
||||
// No parameters.
|
||||
// Returns a float64 representing the number of workers per CPU core.
|
||||
func WorkerPerCore() float64 {
|
||||
return _WorkerPerCore
|
||||
}
|
||||
|
||||
// SetWorkerPerCore sets the number of workers per CPU core.
|
||||
//
|
||||
// It takes a float64 parameter representing the number of workers
|
||||
// per CPU core and does not return any value.
|
||||
func SetWorkerPerCore(n float64) {
|
||||
_WorkerPerCore = n
|
||||
}
|
||||
|
||||
// SetMaxCPU sets the maximum number of CPU cores allowed.
|
||||
//
|
||||
// n - an integer representing the new maximum number of CPU cores.
|
||||
func SetMaxCPU(n int) {
|
||||
_MaxAllowedCPU = n
|
||||
}
|
||||
|
||||
// SetReadWorker sets the number of workers for reading files.
|
||||
//
|
||||
// The number of worker dedicated to reading files is determined
|
||||
// as the number of allowed CPU cores multiplied by number of read workers per core.
|
||||
// Setting the number of read workers using this function allows to decouple the number
|
||||
// of read workers from the number of CPU cores.
|
||||
//
|
||||
// n - an integer representing the number of workers to be set.
|
||||
func SetStrictReadWorker(n int) {
|
||||
_StrictReadWorker = n
|
||||
}
|
||||
|
||||
func SetStrictWriteWorker(n int) {
|
||||
_StrictWriteWorker = n
|
||||
}
|
||||
|
||||
// SetReadWorkerPerCore sets the number of worker per CPU
|
||||
// core for reading files.
|
||||
//
|
||||
// n float64
|
||||
func SetReadWorkerPerCore(n float64) {
|
||||
_ReadWorkerPerCore = n
|
||||
}
|
||||
|
||||
func SetWriteWorkerPerCore(n float64) {
|
||||
_WriteWorkerPerCore = n
|
||||
}
|
||||
|
||||
// ReadWorker returns the number of workers for reading files.
|
||||
//
|
||||
// No parameters.
|
||||
// Returns an integer representing the number of workers.
|
||||
func StrictReadWorker() int {
|
||||
return _StrictReadWorker
|
||||
}
|
||||
|
||||
func StrictWriteWorker() int {
|
||||
return _StrictWriteWorker
|
||||
}
|
||||
|
||||
// CLIReadParallelWorkers returns the number of parallel workers used for
|
||||
// reading files.
|
||||
//
|
||||
// The number of parallel workers is determined by the command line option
|
||||
// --max-cpu|-m and the environment variable OBIMAXCPU. This number is
|
||||
// multiplied by the variable _ReadWorkerPerCore.
|
||||
//
|
||||
// No parameters.
|
||||
// Returns an integer representing the number of parallel workers.
|
||||
func ReadParallelWorkers() int {
|
||||
if StrictReadWorker() == 0 {
|
||||
n := int(float64(MaxCPU()) * ReadWorkerPerCore())
|
||||
if n == 0 {
|
||||
n = 1
|
||||
}
|
||||
return n
|
||||
} else {
|
||||
return StrictReadWorker()
|
||||
}
|
||||
}
|
||||
|
||||
func WriteParallelWorkers() int {
|
||||
if StrictWriteWorker() == 0 {
|
||||
n := int(float64(MaxCPU()) * WriteWorkerPerCore())
|
||||
if n == 0 {
|
||||
n = 1
|
||||
}
|
||||
return n
|
||||
} else {
|
||||
return StrictReadWorker()
|
||||
}
|
||||
}
|
||||
|
||||
// ReadWorkerPerCore returns the number of worker per CPU core for
|
||||
// computing the result.
|
||||
//
|
||||
// No parameters.
|
||||
// Returns a float64 representing the number of worker per CPU core.
|
||||
func ReadWorkerPerCore() float64 {
|
||||
return _ReadWorkerPerCore
|
||||
}
|
||||
|
||||
func WriteWorkerPerCore() float64 {
|
||||
return _ReadWorkerPerCore
|
||||
}
|
||||
|
||||
// ParallelFilesRead returns the number of files to be read in parallel.
|
||||
//
|
||||
// No parameters.
|
||||
// Returns an integer representing the number of files to be read.
|
||||
func ParallelFilesRead() int {
|
||||
if _ParallelFilesRead == 0 {
|
||||
return ReadParallelWorkers()
|
||||
} else {
|
||||
return _ParallelFilesRead
|
||||
}
|
||||
}
|
||||
|
||||
// SetParallelFilesRead sets the number of files to be read in parallel.
|
||||
//
|
||||
// n - an integer representing the number of files to be set.
|
||||
func SetParallelFilesRead(n int) {
|
||||
_ParallelFilesRead = n
|
||||
}
|
Reference in New Issue
Block a user