PySCF parallelism: controls and measured limits#
Start with one explicit thread budget, then inspect phase timings. More threads can increase CPU consumption without reducing elapsed time. Automatic allocation bounds concurrency; it does not benchmark the machine or promise optimal settings.
Automatic and manual control#
Add this fragment to an existing scientific input and run it normally:
parallelism:
threads: 32
pyscf2mppt input.yaml --output-dir runs/reference
The effective budget N is capped by detected logical CPUs, inherited affinity and visible cgroup-v2 CPU quotas. The driver changes thread counts, not CPU or NUMA placement. It does not currently provide portable cgroup-v1 quota detection. Run one numerical worker per process: loaded-library setters are process-global.
Phase |
Automatic OMP / BLAS |
Reason |
|---|---|---|
|
N / 1 |
Parallel one-electron integral work, cached after construction |
|
N / N |
Integral generation and BLAS solves execute sequentially |
|
1 / N |
Conservative product budget |
|
N / 1 |
OpenMP-priority baseline without nested threaded BLAS |
For a controlled comparison, explicitly select both components:
parallelism:
threads: 32
phases:
df_build:
omp_num_threads: 1
blas_num_threads: 32
hcore:
omp_num_threads: 8
blas_num_threads: 1
This is an example of manual allocation, not a recommended universal optimum.
Other phases retain automatic limits. A phase OpenMP override takes precedence
over the enclosing SCF/CASSCF omp_num_threads, which takes precedence over auto.
A stage value of zero becomes one; -1 means auto within the effective budget.
Explicit limits that cannot fit that budget fail rather than silently oversubscribe.
On conservative routes, OMP × BLAS must fit N. With only one limit specified,
the other receives at most floor(N / specified_limit). On the admitted
sequential DF route, max(OMP, BLAS) must fit N, and an unspecified pool can
receive N. Thus 32/32 is valid only for the audited sequential route, not a
blanket allowance to run 1,024 threads under a budget of 32.
Omitting parallelism, or using null, preserves the legacy policy: omitted
stage thread counts resolve from multiprocessing.cpu_count(), and BLAS limits
remain unchanged. Ambient OMP_NUM_THREADS does not define that legacy default.
MPI, CIPSIXX, DIAGPT and HEFFSO have separate controls. See the
complete phase and restoration contract.
Why DF admission is deliberately narrow#
The optimized path requires molecular PySCF 2.15.0, its native in-core Cholesky dispatch and independently controlled pthread/compiled-serial OpenBLAS pools. Admission happens when the native builder chooses its actual route; a large memory setting alone does not prove that route will be used.
Outcore builds, other providers/versions, MKL and eigenvalue fallback retain
conservative limits. If fallback cannot honor an explicit 32/32 pair under a
32-thread budget, execution fails before that unsupported kernel. Auto can
select the conservative pair instead. A shared OpenMP OpenBLAS setter uses
equal floor(sqrt(N)) automatic limits; unequal manual limits are rejected.
That fallback has policy coverage, not full native performance acceptance.
Compiled serial BLAS stays at one. Loaded MKL domain overrides are checked for budget violations, but these safeguards do not certify all MKL numerical or performance paths. Broader MKL acceptance and additional DF routes remain separate work. No backend is silently replaced to obtain a faster result.
Read the right timing and backend evidence#
Inspect logs/pyscf.log and logs/events.jsonl for resolved limits, loaded
library paths/versions, selection reasons, phase times and hcore build counts.
A setter readback of 32 is a limit, not evidence that 32 CPUs did useful work.
Two loaded OpenMP libraries do not by themselves prove simultaneous nested teams.
Driver phase events report self CPU, waited-child CPU, their sum and CPU/wall. Block2 executes in a child, so a near-zero native PySCF parent-only CPU timer can coexist with an active DMRG calculation. The driver includes terminated children that the worker waited for, including children behind a waiting shell. CPU/wall of 23 means average consumption equivalent to 23 CPUs, including runtime overhead and spinning; it is not a measure of useful arithmetic.
CASSCF includes active-solver calls, and enclosing SCF includes preparation and nested provider work. Do not sum inclusive rows. Compare the same timer boundary: a command stopping after CASSCF cannot be compared directly with a command that also exports integrals. Historical runs before the child-accounting fix retain their original counters; those logs are not retroactively corrected.
Reuse avoids work that thread tuning cannot fix#
The process-local hcore cache retains the physical AO one-electron operator across repeated SCF/CASSCF requests. Geometry, basis, potentials and embedding changes invalidate it; MO rotations and density updates alone do not. Returned arrays are independent copies. The cache does not serialize into checkpoints or claim to accelerate the first build.
For performance comparisons from an existing CASSCF state, use
managed CASSCF continuation, which imports optimized
orbitals and matching block2 MPS into a separate run, without repeating SCF/AVAS.
Ordinary --resume reuses a completed stage; it does not request an additional
macroiteration. Continuation inherits the source thread policy when omitted;
a replacement parallelism mapping replaces it, and explicit null removes it.
Preserve the common source and use separate output directories for each policy.
Benchmark evidence#
The following measurements answer different questions. They are not one scaling curve: hardware, runtime builds, stopping points and active spaces differ. No new calculation is required to read or reproduce the tabulated arithmetic.
Ce500: startup environment and stage settings are different#
On Xeon E5-1650 (6 physical cores, 12 SMT threads), PySCF 2.15 with shared pthread OpenBLAS 0.3.34, two repeated extremes gave mean managed SCF wall times of 1679.443 s at startup/stage 1/1 and 354.967 s at 6/6: 4.731× speedup. The individual 6/6 observations were 353.428 and 356.505 s. No CPU binding was applied. These were pre-cache runs and startup OpenMP also affected BLAS.
At fixed stage OMP=6, changing startup OMP from 1 to 6 reduced the interval from DF start to initial energy from 52.258 to 19.354 s, while SCF iterations were nearly unchanged (159.462 versus 158.699 s). Source inspection confirmed repeated hcore construction for the explicit hcore guess and SCF kernel. The two long pre-DF intervals were not isolated hcore microbenchmarks. This experiment did not explain the separate historical 25m42s Ce1470 delay.
Ce44: hcore cache and automatic budgets#
On AMD EPYC 9R45, 32 physical cores/SMT1, the same numerical libraries and OMP32/BLAS1 were held fixed for three fresh baseline/candidate pairs through selected export. The phase policy was inactive in both A/B branches.
Metric |
Before cache, median |
With cache, median |
|---|---|---|
Complete frontend |
617.30 s |
318.89 s |
Native CASSCF timer |
399.315 s |
133.812 s |
Native SCF timer |
28.893 s |
28.895 s |
Peak RSS |
9.7964 GiB |
9.7956 GiB |
All runs converged in three macroiterations. Complete frontend speedup was 1.94×; CASSCF speedup was 2.98×. Total ranges were 617.11–618.63 and 318.59–319.22 s. The cache removes repeated work rather than increasing memory.
The earlier conservative auto implementation, before sequential DF admission, then measured 333.47 / 400.21 / 587.32 s at 32 / 16 / 8 threads respectively, one run per budget. Average CPU equivalents were 15.24 / 9.59 / 6.04. Auto32 was 4.57% slower than the fixed-policy candidate median. These results must not be labelled measurements of the newer N/N DF auto implementation.
A serial-plus-parallel fit predicted about 50 minutes at one core; pairwise fits ranged from 40 to 53 minutes. No one-core run was performed. This is model sensitivity, not a measured result or confidence interval.
Ce44: busy CPUs can be allocator contention#
A separate same-runtime profile stopping after CASSCF measured hcore at 16.539 s with 32 threads and 6.469 s with an eight-thread hcore override. Allocator/free samples fell from 86.11% to 17.55%. The old bundled serial PySCF BLAS showed buffer-lock contention. This evidence supports that specific bottleneck; merely observing two GNU OpenMP runtimes did not establish causation. The experiment does not justify a global eight-thread cap for every runtime.
Ce44: runtime packaging also matters#
A later shared Conda LP64 pthread OpenBLAS 0.3.34 runtime reduced the matched fixed32 through-CASSCF wall from 250.99 to 167.45 s (1.50×). Old/new auto32 were 267.27/174.08 s, and hcore8 were 241.50/166.60 s. All three new points converged; maximum state-energy deviation was 2.756×10⁻⁹ Eh against 10⁻⁷ Eh.
These were single observations on different rentals and changed libcint, NumPy/SciPy and packaging as well as BLAS. They measure the complete runtime change, not an isolated BLAS speedup. Profiles switched from the old Barcelona kernel to Cooperlake, with much lower allocator sample shares. The 0.85 s fixed32/hcore8 difference does not establish significant wall-time improvement; hcore CPU cost fell from 104.30 to 30.82 CPU seconds. This runtime was an experiment artifact, not a replacement automatically installed by thread controls.
Ce44: 192 cores did not improve on 96#
A later Conda/HPC runtime used Ce44 with 491 AO, CASSCF(1e,12o) and 12 states. Two repeats per condition stopped after CASSCF. Historical runs used explicitly authorized placement: 96 cores on one socket versus 192 across both. That placement is part of the measurement, not an automatic product setting.
Policy |
96 cores, mean wall / CPU seconds |
192 cores, mean wall / CPU seconds |
|---|---|---|
Then-current auto |
231.805 / 6223.14 |
242.285 / 12414.33 |
Candidate hcore cap8, other phases OMP=N/BLAS1 |
228.455 / 5821.19 |
237.315 / 11266.12 |
All eight points converged; maximum state-energy deviation was 2.76×10⁻⁹ Eh against a 10⁻⁷ Eh criterion. Doubling cores increased elapsed time by roughly 4% and nearly doubled CPU cost. CASSCF and weakly parallel initial preparation limited the benefit. The 96-core candidate gain was smaller than the baseline repeat spread. No global auto defaults were changed from this two-repeat study.
Ce1470: faster DF is a small part of one continued macroiteration#
On one r8a.8xlarge worker, two sequential runs used the same four-macro source, CAS(11e,17o), 12 states, PySCF 2.15.0 and pthread OpenBLAS 0.3.34. Each requested one additional macroiteration, with matching optimized orbitals and block2 MPS. Both containers used the same immutable image and differed only by the DF phase override in YAML. This compares explicit DF1/32 against admitted native DF32/32; it is one observation per condition, not a repeat distribution.
Inclusive phase wall |
Explicit DF1/32 |
Admitted DF32/32 |
|---|---|---|
DF build |
135.923 s |
26.062 s |
CASSCF |
3076.225 s |
2968.887 s |
DF accelerated 5.22×, but CASSCF improved only 3.49% (1.036×). Saving about 110 seconds in a roughly 3,000-second calculation cannot give a fivefold whole-calculation improvement. The remaining work needs its own phase evidence.
The unconverged endpoints differ. The averaged energy changed by −1.52×10⁻⁸ Eh, but the maximum sorted state-energy difference was 1.06545×10⁻⁶ Eh, exceeding 10⁻⁷ Eh. Both endpoints were unconverged. Both restart energies matched their common source within the separate 5×10⁻⁵ Eh restart tolerance (observed differences about 5.54×10⁻⁸ Eh). Successful restart and finite outputs therefore do not establish endpoint equivalence or convergence. The timing is measured evidence. Changes in parallel evaluation can change rounding, the iterative trajectory and the solution reached by PySCF, including SCF. Agreement after one unconverged macroiteration is not a package correctness criterion. The original comparison result is retained as an observation, not promoted into a package regression test or a release gate.
The 10⁻⁷ Eh endpoint criterion is hard-coded in the experiment comparison; it is not a general pyscf2mppt CI tolerance. The source DMRG energy tolerance is 5×10⁻⁵ Eh. These tolerances serve different purposes, but a much tighter cross-run endpoint requirement needs justification for an unconverged iterative solve. Convergence flags are recorded independently and are not part of the comparison script’s Boolean parity expression. No same-policy repeats were performed, so this pair cannot separate normal repeat variability from a thread-policy effect.
Practical interpretation#
Compare unchanged science and a common starting state, record actual backend versions and thread readbacks, and choose matching wall-time boundaries. Use total elapsed time for throughput and CPU seconds for resource efficiency. A faster isolated kernel may barely change the complete run. A smaller thread team can outperform a larger one when synchronization, allocator contention, small BLAS work or memory traffic dominates. These observations motivate manual controls; they do not turn auto into a calibrated performance predictor.