// -p n
// the number of programs, such as build commands or
// test binaries, that can be run in parallel.
-// The default is the number of CPUs available.
+// The default is GOMAXPROCS, normally the number of CPUs available.
// -race
// enable data race detection.
// Supported only on linux/amd64, freebsd/amd64, darwin/amd64, windows/amd64,
BuildA bool // -a flag
BuildBuildmode string // -buildmode flag
BuildContext = defaultContext()
- BuildMod string // -mod flag
- BuildModExplicit bool // whether -mod was set explicitly
- BuildModReason string // reason -mod was set, if set by default
- BuildI bool // -i flag
- BuildLinkshared bool // -linkshared flag
- BuildMSan bool // -msan flag
- BuildN bool // -n flag
- BuildO string // -o flag
- BuildP = runtime.NumCPU() // -p flag
- BuildPkgdir string // -pkgdir flag
- BuildRace bool // -race flag
- BuildToolexec []string // -toolexec flag
+ BuildMod string // -mod flag
+ BuildModExplicit bool // whether -mod was set explicitly
+ BuildModReason string // reason -mod was set, if set by default
+ BuildI bool // -i flag
+ BuildLinkshared bool // -linkshared flag
+ BuildMSan bool // -msan flag
+ BuildN bool // -n flag
+ BuildO string // -o flag
+ BuildP = runtime.GOMAXPROCS(0) // -p flag
+ BuildPkgdir string // -pkgdir flag
+ BuildRace bool // -race flag
+ BuildToolexec []string // -toolexec flag
BuildToolchainName string
BuildToolchainCompiler func() string
BuildToolchainLinker func() string
-p n
the number of programs, such as build commands or
test binaries, that can be run in parallel.
- The default is the number of CPUs available.
+ The default is GOMAXPROCS, normally the number of CPUs available.
-race
enable data race detection.
Supported only on linux/amd64, freebsd/amd64, darwin/amd64, windows/amd64,
// - it has no successor packages to compile (usually package main)
// - all paths through the build graph pass through it
// - critical path scheduling says it is high priority
- // and in such a case, set c to runtime.NumCPU.
+ // and in such a case, set c to runtime.GOMAXPROCS(0).
+ // By default this is the same as runtime.NumCPU.
// We do this now when p==1.
+ // To limit parallelism, set GOMAXPROCS below numCPU; this may be useful
+ // on a low-memory builder, or if a deterministic build order is required.
+ c := runtime.GOMAXPROCS(0)
if cfg.BuildP == 1 {
- // No process parallelism. Max out c.
- return runtime.NumCPU()
+ // No process parallelism, do not cap compiler parallelism.
+ return c
}
- // Some process parallelism. Set c to min(4, numcpu).
- c := 4
- if ncpu := runtime.NumCPU(); ncpu < c {
- c = ncpu
+ // Some process parallelism. Set c to min(4, maxprocs).
+ if c > 4 {
+ c = 4
}
return c
}