Allows for only one cpu and it should work

This commit is contained in:
Eric Coissac
2025-08-06 16:09:25 -04:00
parent 04f3af3e60
commit 730d448fc3
2 changed files with 20 additions and 16 deletions

View File

@@ -54,8 +54,8 @@ func GenerateOptionParser(program string,
options.GetEnv("OBIMAXCPU"), options.GetEnv("OBIMAXCPU"),
options.Description("Number of parallele threads computing the result")) options.Description("Number of parallele threads computing the result"))
options.BoolVar(&_Pprof, "force-one-cpu", false, // options.BoolVar(&_Pprof, "force-one-cpu", false,
options.Description("Force to use only one cpu core for parallel processing")) // options.Description("Force to use only one cpu core for parallel processing"))
options.IntVar(&_PprofMudex, "pprof-mutex", _PprofMudex, options.IntVar(&_PprofMudex, "pprof-mutex", _PprofMudex,
options.GetEnv("OBIPPROFMUTEX"), options.GetEnv("OBIPPROFMUTEX"),
@@ -152,23 +152,27 @@ func GenerateOptionParser(program string,
os.Exit(1) os.Exit(1)
} }
// Setup the maximum number of CPU usable by the program // // Setup the maximum number of CPU usable by the program
if obidefault.MaxCPU() == 1 { // if obidefault.MaxCPU() == 1 {
log.Warn("Limitating the Maximum number of CPU to 1 is not recommanded") // log.Warn("Limitating the Maximum number of CPU to 1 is not recommanded")
log.Warn("The number of CPU requested has been set to 2") // log.Warn("The number of CPU requested has been set to 2")
obidefault.SetMaxCPU(2) // obidefault.SetMaxCPU(2)
} // }
if options.Called("force-one-cpu") { // if options.Called("force-one-cpu") {
log.Warn("Limitating the Maximum number of CPU to 1 is not recommanded") // log.Warn("Limitating the Maximum number of CPU to 1 is not recommanded")
log.Warn("The number of CPU has been forced to 1") // log.Warn("The number of CPU has been forced to 1")
log.Warn("This can lead to unexpected behavior") // log.Warn("This can lead to unexpected behavior")
obidefault.SetMaxCPU(1) // obidefault.SetMaxCPU(1)
} // }
runtime.GOMAXPROCS(obidefault.MaxCPU()) runtime.GOMAXPROCS(obidefault.MaxCPU())
if options.Called("max-cpu") || options.Called("force-one-cpu") { // if options.Called("max-cpu") || options.Called("force-one-cpu") {
// log.Printf("CPU number limited to %d", obidefault.MaxCPU())
// }
if options.Called("max-cpu") {
log.Printf("CPU number limited to %d", obidefault.MaxCPU()) log.Printf("CPU number limited to %d", obidefault.MaxCPU())
} }

View File

@@ -8,7 +8,7 @@ import (
// corresponds to the last commit, and not the one when the file will be // corresponds to the last commit, and not the one when the file will be
// commited // commited
var _Commit = "f239e8d" var _Commit = "04f3af3"
var _Version = "Release 4.4.0" var _Version = "Release 4.4.0"
// Version returns the version of the obitools package. // Version returns the version of the obitools package.