Skip to content

Add --parallel-compile to compile files in parallel - #1235

Open
ru551n wants to merge 5 commits into
VUnit:masterfrom
ru551n:parallel-compile
Open

ru551n wants to merge 5 commits into
VUnit:masterfrom
ru551n:parallel-compile

Conversation

@ru551n

@ru551n ru551n commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Adds --parallel-compile, which compiles files in parallel, up to -p files at a time. A file is compiled as soon as the files it depends on are compiled. Without the flag, files are compiled one at a time as before, whatever -p is, so python run.py --clean -p 0 still compiles serially.

What was added

  • Scheduler: SimulatorInterface.compile_source_files compiles each file once its dependencies are compiled, using a thread pool. As before, the dependents of a failed file are skipped, and --keep-compiling keeps going. Without it, no new files start after a failure.

  • Library rule: GHDL and Riviera-PRO update a library's index without locking it.

    • Two compiles into the same library lose units. Riviera-PRO even reports success for every compile.
    • A compile reading a library while GHDL rewrites its index fails with "cannot find resource library", because GHDL deletes the index before renaming the new one into place.

    Unless a simulator sets supports_concurrent_compiles_into_library, a file is therefore not compiled while its own library is compiled into or read, or while a library it reads is compiled into. The libraries a file reads are those of its dependencies. NVC sets the flag, because it holds a reader/writer lock on its libraries (see NVC performance with Vunit #1036).

  • GHDL: creates every library with ghdl -i when setting up the library mapping. A file with a library clause can otherwise be compiled before anything has been compiled into that library, which GHDL rejects. With gcc coverage, GHDL compiles one file at a time, because the .gcno files land in the working directory.

  • Output: with -p > 1, each file's output is written once its compile finishes, so outputs don't mix.

Measured

A clean compile (--compile --clean --parallel-compile) of hdl-modules, 330 files, wall time including VUnit's start-up, median of 3 runs:

-p NVC GHDL Riviera-PRO*
master 5.88 s 7.51 s 11.85 s
1 5.95 s 7.51 s 11.90 s
4 2.51 s 5.62 s 7.39 s
16 1.65 s 5.63 s 7.24 s

* With --keep-compiling, because hdl-modules does not compile completely with Riviera-PRO on master either ('latency attribute in sine_calculator.vhd). Every run compiled the same 327 files.

GHDL and Riviera-PRO level off early because almost every file reads vunit_lib, so the library rule serialises most of the compile. The follow-up #1236, built on this PR, addresses that with --batch-compile, which compiles the files of a library that are ready at the same time in one call, the automatic form of the soft file groups discussed in #1088. With both flags, the clean compile of hdl-modules takes 1.42 s with NVC, 1.64 s with GHDL and 2.66 s with Riviera-PRO.

Tested

  • New unit tests for compiling different libraries concurrently, one file per library at a time, the read rule, concurrent readers of a library, waiting for dependencies, skipping dependents and writing each file's output in one piece. They fail on master.
  • UI tests: without --parallel-compile, files are compiled with one thread for -p 4 and -p 0; with it, with -p threads.
  • The unit and lint tests pass.
  • GHDL stress test: 10 clean hdl-modules compiles each at -p 4, 16 and 32. All 29 runs that reached the compile compiled all 330 files. The 30th failed earlier, on a duplicate configuration name in hdl-modules' own randomised test setup.

A news fragment is included.

🤖 Generated with Claude Code

ru551n and others added 4 commits October 15, 2026 11:25
A file is compiled as soon as the files it depends on are compiled, up to
-p files at a time. Files of a library are compiled one at a time, since
GHDL and Riviera-PRO update the index of a library without locking it and
lose units when compiled into concurrently. NVC locks its libraries and
compiles files of a library at the same time. The output of a file is
written once it is compiled so that outputs do not mix. GHDL compiles one
file at a time with gcc coverage, which writes .gcno files to the working
directory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GHDL rewrites the index of a library by deleting it and renaming a new
one into place, so a compile reading the library in between fails with
"cannot find resource library". Unless a simulator locks its libraries, a
file is not compiled while its library is read, or while a library it
reads, that of any of its dependencies, is compiled into.

A library clause fails in GHDL on a library nothing has been compiled
into, which a file compiled in parallel may come before. GHDL creates
every library with ghdl -i when setting up the library mapping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without it, files are compiled one at a time whatever -p is, so that a
-p given for running tests does not change how files are compiled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ru551n ru551n changed the title Compile files in parallel with -p Add --parallel-compile to compile files in parallel Oct 15, 2026
@ru551n
ru551n marked this pull request as ready for review October 15, 2026 12:34
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant