One of the new features in Z3 4.8.1 is parallel solving:
A parallel mode is available for select theories, including QF_BV. By setting parallel.enable=true Z3 will spawn a number of worker threads proportional to the number of available CPU cores to apply cube and conquer solving on the goal.
It mentions that just parallel.enable=true
needs to be set but I can't find that parallel
structure in the code.
Can someone provide some example code to see how to implement this new feature?
Thank you
Short answer: As @LeventErkok points out, the syntax of
parallel.enable=true
is for use in the command line to the z3 executable itself. And as he says and @Claies's link had indicated, if you are using a binding, you will want to use the relevantset_param()
method. For C++ that isset_param("parallel.enable", true);
When I added this to the C++ binding example, it gave basically the same output...though it spat out some extra information to stderr, a bunch of lines like:
Which matches @LeventErkrok's observed difference using the z3 tool on another problem.
(I was curious what Z3 was all about, so I also went looking in the C++ sources for parallel.enable. So that's where my answer started out from, before people who knew more answered. My findings left here for anyone interested...)
Long answer: If you're looking through the sources for z3 itself, you won't find a C++ object called
parallel
where you'd writeparallel.enable = true;
. It's a property stored in a configuration object managed by string names. That configuration object is calledparallel_params
, it's not in GitHub because it is generated as part of the build process, intosrc/solver/parallel_params.hpp
The specification for these properties and their defaults is per-module in a
.pyg
file. This is just Python which is loaded by the build preparation process and eval()'d with a few things defined. The parallel solver options are insrc/solver/parallel_params.pyg
, e.g.:If you want to change these defaults while building z3, it looks like you have to edit the
.pyg
file, as there seems no parameterization for something likepython scripts/mk_make.py parallel.enable=true
.As an example of how changing this file affects the generated header defining the parallel properties, I directly modified
parallel_params.pyg
to say "True" instead of "False" for its default. The consequence was the following 2-line diff to the generatedsrc/solver/parallel_params.hpp
file:From the command line
If you are using the z3 executable, then you simply pass the setting in the command line. That is, if your script is in file
a.smt2
, use:and z3 will use the parallel solver as it processes the benchmark. For instance:
Regular call:
Parallel mode:
Note the extra comments regarding the execution of the parallel mode in the second run.
Programmatically
If you're asking about how to use it from the programmatic API? For Python, it would look like:
I'm sure other API's have similar calls. (Caveat: I haven't actually used/tested this feature myself; and since it's rather new, it might be the case that not all programmatic APIs support it. Hopefully, you get a nice warning/error if that's the case!)