Or-Tools with Minizinc, multi threading support

101 views
Skip to first unread message

Alessio Pellegrino

unread,
Sep 12, 2025, 8:05:10 AM9/12/25
to or-tools-discuss
Good morning everyone.
I am using Or-Tools with minizinc, and I noticed that it works only in a 1-core or 8-core setup but not with intermediate values (2-7).  I saw that it is something that has been enforced in the code (https://github.com/google/or-tools/blob/7ee639cf6981a9beeba908cf543a50f4ee7413ad/ortools/flatzinc/cp_model_fz_solver.cc#L1701) and I was wondering why that decision was made. Is there any specific requirement that cannot be met with, for example, 4 cores?
Many thanks,
Alessio

Laurent Perron

unread,
Sep 12, 2025, 8:53:23 AM9/12/25
to or-tools...@googlegroups.com

I manually enforce that you always use at least 8 workers. Performance is bad with the default set of workers with only 4 workers.

You can edit the set of active subsolvers as done in the same file.
Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/or-tools-discuss/6a182268-e815-464d-a457-7f613ca119e9n%40googlegroups.com.

Alessio Pellegrino

unread,
Sep 12, 2025, 8:59:48 AM9/12/25
to or-tools-discuss
Okay, thank you!

erik88

unread,
Mar 5, 2026, 5:15:21 AM (2 days ago) Mar 5
to or-tools...@googlegroups.com
There are a few caveats with running MiniZinc + CP-SAT w. multiple
threads.

By default

mzn --solver cp-sat model.mzn

will simply run with a single thread and no-interleaved workers, and
performance will be sub-par. You should run CP-SAT with multiple
workers, in one way or another!

On 25/09/12 05:59AM, Alessio Pellegrino wrote:
> I am using Or-Tools with minizinc, and I noticed that it works only in a
> 1-core or 8-core setup but not with intermediate values (2-7). I saw that
> it is something that has been enforced in the code (
> https://github.com/google/or-tools/blob/7ee639cf6981a9beeba908cf543a50f4ee7413ad/ortools/flatzinc/cp_model_fz_solver.cc#L1701)
> and I was wondering why that decision was made. Is there any specific
> requirement that cannot be met with, for example, 4 cores?
> Many thanks,

As you've already noticed, if you set `-p` to 2-7, CP-SAT will simply
assume you meant 8.

And as Laurent Perron wrote:
> I manually enforce that you always use at least 8 workers. Performance is
> bad with the default set of workers with only 4 workers.

If you for some reason can't run 8 workers (maybe you only have 1-4
threads) then `--free-search` is your best bet:
https://github.com/google/or-tools/blob/4336f9f3aeedd5462ee0008116b1a2a1e7d633ef/ortools/flatzinc/cp_model_fz_solver.cc#L3896

Previously I've written a bit about it here:
https://github.com/MiniZinc/libminizinc/issues/824

How they different flags interplay is in my experience non-obvious.

It depends if you are using the MiniZinc flags:
- free-search `-f/--free-search`
- paralell `-p` flag
and addionally there is the fzn flags you can use which get passed
directly to the OR-Tools fzn interface `num_workers`.

These all get pass in some way or another to the CP-SAT fzn and my best
advice is to read the source code to figure out exactly how the
workers are configurated, these days I think it's here:
https://github.com/google/or-tools/blob/4336f9f3aeedd5462ee0008116b1a2a1e7d633ef/ortools/flatzinc/cp_model_fz_solver.cc#L3871
as well as running with verbose logging (`-v`?) to actually see how many
workers are being set.
Reply all
Reply to author
Forward
0 new messages