Skip to content

Use several threads to lift Groebner bases over QQ - #418

Open
mohabsafey wants to merge 19 commits into
algebraic-solving:masterfrom
mohabsafey:gb-lifting-mt
Open

mohabsafey wants to merge 19 commits into
algebraic-solving:masterfrom
mohabsafey:gb-lifting-mt

Conversation

@mohabsafey

Copy link
Copy Markdown
Contributor

This PR uses the threads given by -t to lift Groebner bases over the rationals (-g 2). The output does not depend on the number of threads.

It builds on #411: until #411 is merged, the diff also shows its commits. The 11 commits of this PR start with "Read the trace cache with atomic loads".

Changes

  • Primes by batches. With -t t, the trace is applied to batches of t primes, one prime per thread. The images are then lifted prime by prime, in the same order as with one thread, so that the lifting decisions do not change. Two data races made this unsafe and are fixed first: the matrices cached in the trace are now read with acquire loads, and the elimination via DRL no longer writes into meta data shared by the primes.
  • Parallel lifting. The CRT of the coefficients runs in parallel, by chunks which grow along each polynomial, with blocks balanced among the threads. The CRTs of the witness coefficients are computed only when the reconstruction reaches their polynomial. The images are stored by blocks of rows, one row per prime, so that adding primes never copies them; they are copied, reduced to the common denominator and checked by all threads.
  • Fewer reconstruction attempts. With more than 4 threads, the witnesses are reconstructed at most once per batch, two primes before its end, since an attempt in the middle of a batch saves no time. After an attempt which reconstructs no polynomial, the next one waits for a growth of the number of primes (at most 3%) given by the estimated cost of an attempt. In the spacing of the LLL attempts, an attempt costs t primes.
  • Parallel output. The lifted basis is formatted by all threads, by chunks of at most 256 terms, without flushing after each term.
  • --local-threads p. The memory grows with t (see below). With --local-threads p, where p divides t, the batches have t/p primes, each computed by p threads; the CRT still uses the t threads. Without the option, nothing changes.

Number of primes

With one thread, the primes are those of #411 (identical on the 39 systems below). With t threads, the number of primes may grow:

  • it is rounded up to the end of a batch of t primes, so that systems needing few primes use t of them with t = 32 (eco11 to eco15, noon, kat11, kat12);
  • a polynomial may be reconstructed a batch later, since the attempts are spaced by the batches (henrion7: 99 primes with 1 thread, 120 with 8, 128 with 32; zimmermann: 609, 640, 672). The number of primes is not always monotonic in t (bruno: 389, 440, 384);
  • with --local-threads p, the batches have t/p primes, so that the primes used depend on p.

The primes depend only on the trace and on t (and p), not on timings. The trace learned with several threads is not deterministic, so that the number of primes may vary between two runs with the same t; in two runs of the 39 systems at 8 and 32 threads, it did not.

Benchmarks

On a 2 x 18-core Intel Xeon Gold 6354 (AVX-512 IFMA, primes of 52 bits), FLINT 3.6, -g 2 -t t --random-seed 1, one run per system and thread count. The times are elapsed times of the whole run, including writing the output. Memory is the peak resident size. "#411" is the branch of #411 before its last two commits (fix of the checks and of the 52-bit primes on Windows), which do not change these times. All outputs are identical to the output with one thread.

system time #411 1 / 8 / 32 thr (s) time PR 1 / 8 / 32 thr (s) PR vs #411, 8 / 32 thr PR 32 thr vs 1 thr primes PR 1 / 8 / 32 thr memory PR 1 / 8 / 32 thr (GB)
cyclic9-qq 2660.7 / 492.3 / 284.4 2695.2 / 355.3 / 161.7 1.39 / 1.76 16.7 136 / 136 / 192 1.7 / 6.1 / 23.2
eco15-qq 2645.0 / 560.4 / 248.0 2649.7 / 460.2 / 203.6 1.22 / 1.22 13.0 19 / 24 / 32 5.2 / 11.5 / 39.2
kat14-qq 1283.3 / 345.4 / 240.2 1289.0 / 214.2 / 118.2 1.61 / 2.03 10.9 38 / 40 / 64 5.7 / 10.1 / 31.5
chandra-15-qq 937.0 / 511.7 / 439.8 910.4 / 238.9 / 149.7 2.14 / 2.94 6.1 77 / 80 / 96 12.8 / 18.3 / 55.7
minrank_d_2_p_2_q_8_r_2 279.9 / 239.7 / 196.3 275.7 / 43.6 / 17.9 5.50 / 10.96 15.4 2193 / 2208 / 2208 2.4 / 2.5 / 2.5
eco14-qq 254.3 / 74.8 / 40.5 253.5 / 42.6 / 27.2 1.76 / 1.49 9.3 16 / 16 / 32 1.2 / 2.6 / 9.2
chandra-14-qq 186.3 / 114.3 / 106.4 182.0 / 52.6 / 31.7 2.17 / 3.36 5.7 66 / 72 / 96 3.4 / 5.0 / 12.1
kat13-qq 147.1 / 46.2 / 38.8 144.0 / 27.9 / 13.4 1.66 / 2.89 10.7 29 / 32 / 32 1.2 / 2.5 / 7.9
random2_9_9 111.4 / 99.6 / 89.9 110.5 / 19.2 / 9.87 5.19 / 9.11 11.2 3681 / 3776 / 3680 0.83 / 0.85 / 0.92
minrank_d_3_p_3_q_6_r_3 71.0 / 61.9 / 52.4 68.8 / 12.1 / 5.32 5.14 / 9.84 12.9 965 / 976 / 992 0.85 / 0.87 / 0.93
KLYZ22 70.2 / 23.5 / 21.2 69.9 / 10.2 / 3.74 2.30 / 5.67 18.7 285 / 288 / 288 0.13 / 0.25 / 0.79
cp_d_3_n_6_p_2 50.9 / 46.5 / 41.2 50.1 / 9.12 / 4.48 5.09 / 9.19 11.2 1305 / 1344 / 1312 0.57 / 0.59 / 0.64
minrank_d_2_p_3_q_4_r_2 48.9 / 38.1 / 34.3 48.0 / 8.05 / 3.48 4.74 / 9.84 13.8 1345 / 1352 / 1376 0.44 / 0.47 / 0.52
zimmermann 45.9 / 21.4 / 20.6 46.1 / 7.95 / 3.63 2.69 / 5.68 12.7 609 / 640 / 672 0.06 / 0.20 / 0.74
random3_6_6 45.5 / 34.7 / 30.5 44.8 / 7.38 / 3.07 4.70 / 9.94 14.6 1297 / 1312 / 1312 0.39 / 0.41 / 0.46
chandra-13-qq 39.8 / 27.1 / 24.0 39.0 / 12.5 / 7.61 2.16 / 3.15 5.1 58 / 64 / 64 0.97 / 1.4 / 3.5
bruno 38.3 / 21.4 / 22.0 38.6 / 6.44 / 2.33 3.33 / 9.44 16.5 389 / 440 / 384 0.10 / 0.21 / 0.65
minrank_d_2_p_3_q_7_r_3 35.3 / 28.6 / 24.6 34.8 / 6.06 / 3.43 4.72 / 7.16 10.2 889 / 816 / 992 0.44 / 0.46 / 0.50
henrion7 33.2 / 19.2 / 15.9 33.1 / 7.45 / 3.64 2.58 / 4.37 9.1 99 / 120 / 128 0.39 / 0.71 / 1.8
eco13-qq 22.9 / 8.76 / 6.34 22.1 / 6.13 / 4.37 1.43 / 1.45 5.0 11 / 16 / 32 0.30 / 0.72 / 2.6
kat12-qq 18.7 / 8.74 / 6.75 18.6 / 4.50 / 2.82 1.94 / 2.39 6.6 21 / 24 / 32 0.30 / 0.65 / 2.1
minrank_d_2_p_2_q_7_r_2 13.6 / 12.8 / 11.9 13.3 / 2.70 / 1.48 4.74 / 8.03 9.0 781 / 792 / 800 0.18 / 0.19 / 0.25
noon9-qq 11.0 / 6.96 / 6.14 10.2 / 4.60 / 4.53 1.51 / 1.36 2.2 4 / 8 / 32 0.34 / 0.79 / 3.0
random2_8_8 10.9 / 10.6 / 9.98 10.7 / 2.13 / 1.19 4.98 / 8.39 9.0 1529 / 1536 / 1536 0.12 / 0.13 / 0.17
chandra-12-qq 9.39 / 6.82 / 6.30 9.22 / 3.24 / 2.57 2.10 / 2.45 3.6 52 / 56 / 64 0.26 / 0.40 / 1.1
cp_d_4_n_4_p_3 8.00 / 5.30 / 5.60 7.90 / 1.40 / 0.69 3.79 / 8.12 11.4 637 / 640 / 640 0.08 / 0.09 / 0.15
vor1 4.37 / 2.48 / 2.05 4.35 / 0.89 / 0.53 2.79 / 3.87 8.2 60 / 64 / 64 0.06 / 0.12 / 0.35
eco12-qq 4.18 / 1.86 / 1.48 4.11 / 1.16 / 1.16 1.60 / 1.28 3.5 8 / 8 / 32 0.08 / 0.21 / 0.77
cyclic8-qq 3.21 / 1.78 / 1.44 3.21 / 1.04 / 0.64 1.71 / 2.25 5.0 19 / 24 / 32 0.06 / 0.20 / 0.70
kat11-qq 2.80 / 1.78 / 1.39 2.74 / 0.84 / 0.73 2.12 / 1.90 3.8 17 / 16 / 32 0.07 / 0.17 / 0.56
minrank_d_3_p_2_q_5_r_2 2.53 / 2.13 / 2.05 2.45 / 0.59 / 0.35 3.61 / 5.86 7.0 317 / 320 / 320 0.05 / 0.06 / 0.11
chandra-11-qq 2.11 / 1.63 / 1.62 2.06 / 0.87 / 0.77 1.87 / 2.10 2.7 41 / 40 / 64 0.07 / 0.12 / 0.31
cp_d_3_n_5_p_2 2.03 / 1.85 / 1.88 2.04 / 0.52 / 0.30 3.56 / 6.27 6.8 375 / 384 / 384 0.04 / 0.05 / 0.10
noon8-qq 1.64 / 1.15 / 1.10 1.58 / 0.81 / 0.90 1.42 / 1.22 1.8 4 / 8 / 32 0.06 / 0.18 / 0.66
random2_7_7 1.27 / 1.16 / 1.26 1.29 / 0.31 / 0.21 3.74 / 6.00 6.1 581 / 592 / 608 0.02 / 0.03 / 0.07
minrank_d_2_p_3_q_6_r_3 0.88 / 0.81 / 0.85 0.87 / 0.23 / 0.20 3.52 / 4.25 4.3 242 / 248 / 256 0.03 / 0.04 / 0.08
eco11-qq 0.73 / 0.44 / 0.42 0.70 / 0.31 / 0.33 1.42 / 1.27 2.1 7 / 8 / 32 0.03 / 0.07 / 0.24
minrank_d_2_p_2_q_6_r_2 0.70 / 0.74 / 0.76 0.70 / 0.20 / 0.17 3.70 / 4.47 4.1 263 / 264 / 288 0.02 / 0.03 / 0.07
chandra-10-qq 0.64 / 0.57 / 0.69 0.65 / 0.31 / 0.32 1.84 / 2.16 2.0 48 / 40 / 64 0.03 / 0.05 / 0.12

On these 39 systems, with 1 thread, the PR takes the time of #411 (from 0.98 to 1.08 times faster, 1.01 as a geometric mean). It is 2.61 times faster than #411 with 8 threads (from 1.22 on eco15 to 5.50 on minrank_d_2_p_2_q_8_r_2) and 3.73 times faster with 32 threads (from 1.22 to 10.96), as geometric means. With 32 threads, it is 7.0 times faster than with one thread, and 11.1 times on the 19 systems taking at least 30 s with one thread (from 5.7 on chandra-14 to 18.7 on KLYZ22). The total time goes from 9102 s with one thread to 1575 s with 8 threads and 798 s with 32 threads (#411: 2885 s and 2041 s).

The scaling is limited on chandra (5 to 6 times with 32 threads): the trace learned with several threads makes about 1.5 times more operations per prime than the trace learned with one thread. It is also limited on the systems which need few primes (eco, noon, kat11, kat12), where the last batch is mostly wasted.

Larger systems, gb-lifting-mt only (before the fix of the checks in #411), with a time limit of one hour, at 8 and 32 threads; with one thread, most of them exceed the limit. Both outputs are identical where both runs end. KLYZ23 and 3 other sing-visual-servoing systems exceed the limit with 32 threads too.

system time 8 / 32 thr (s) primes 8 / 32 thr memory 8 / 32 thr (GB)
sing-visual-servoing-jorge-rectangle_NOTparallel.G1 > 3600 / 2566 - / 8832 - / 66.7
sing-visual-servoing-jorge-genericPlanar3_NOTparallel.G1 > 3600 / 2233 - / 8064 - / 61.8
sing-visual-servoing-jorge-square_NOTparallel.new > 3600 / 2111 - / 6272 - / 52.4
sing-visual-servoing-jorge-square_NOTparallel.G0 > 3600 / 2081 - / 6272 - / 52.4
KLYZ12 > 3600 / 1244 - / 1728 - / 14.6
fekete-valdes-n6p0idealVarsReordered 2037 / 659 72 / 96 6.4 / 21.3
fekete-valdes-n6p0idealVarsReorderedVart 1947 / 659 72 / 96 6.3 / 21.4
fekete-valdes-n6p0ideal 1929 / 655 72 / 96 6.3 / 21.2
fekete-valdes-n6p0idealMaxRank3 1566 / 443 64 / 64 5.7 / 21.0
sing-visual-servoing-jorge-rectangle1.sZ 1212 / 384 1392 / 1440 3.9 / 7.5
sing-visual-servoing-jorge-genericPlanar3_parallel.G1 1153 / 352 1584 / 1728 9.4 / 10.8
KLYZ13 1265 / 348 1208 / 1184 4.9 / 11.1
sing-visual-servoing-jorge-square1.pZ 828 / 286 144 / 192 3.8 / 13.8
sing-visual-servoing-jorge-square2.sZ 806 / 258 760 / 768 4.1 / 7.8
sing-visual-servoing-jorge-rectangle_parallel.coplanarity 427 / 121 472 / 480 2.2 / 5.5
sing-visual-servoing-jorge-lozenge1.sZ 248 / 77 312 / 320 1.8 / 4.7
sing-visual-servoing-jorge-rectangle_parallel.G1 203 / 67 288 / 320 1.6 / 4.2
sing-visual-servoing-jorge-square1.sZ 41 / 15 56 / 64 1.1 / 3.8

Memory

The memory grows with the number of threads: each thread runs its own F4 application, the bases computed are held until they are lifted, and the images wait for the next reconstruction attempt, made once per batch. With 32 threads, the peak is 3.9 times that with one thread as a geometric mean on the 39 systems, and 4.4 to 14 times on the systems with large F4 applications (chandra-15: 12.8 to 55.7 GB, kat14: 5.7 to 31.5 GB, eco15: 5.2 to 39.2 GB, cyclic9: 1.7 to 23.2 GB).

--local-threads p trades time for memory. With 32 threads:

system p = 1 p = 4 p = 32 #411
eco14 27.8 s, 9.7 GB 24.4 s, 3.3 GB 35.8 s, 1.5 GB 41.2 s, 1.5 GB
cyclic9 160 s, 24.3 GB 159 s, 6.9 GB 297 s, 2.1 GB 284 s, 2.1 GB
chandra-15 148 s, 58.5 GB 150 s, 22.2 GB 331 s, 15.4 GB 429 s, 15.2 GB

A bug found on the way

The first runs of this branch gave a wrong basis for chandra-15 with 32 threads: one coefficient of 3369 bits instead of 1028 bits, correct modulo the first 64 primes only. The polynomials lifted again after a failed check were counted as checked by a new prime without being checked. This is fixed in #411 ("Check the polynomials lifted again after a failed check"); with the fix, chandra-15 gives the right basis with 32 threads (149.7 s, 96 primes). The same counting is still in master, where a wrong lift is less likely since the coefficients are not accepted as integers.

Tests

make check passes (98 tests, including a new test of --local-threads on cyclic5), on Linux with and without AVX-512 IFMA, and with the arguments of the GMP functions taking an unsigned long truncated to 32 bits, as on Windows.

Some of the changes in this PR were made with the assistance of generative AI (Claude Code).

🤖 Generated with Claude Code

mohabsafey and others added 19 commits November 27, 2026 16:34
When lifting a Groebner basis over QQ (-g 2), the denominator of each
polynomial is guessed from the previous one, and three witness
coefficients are rationally reconstructed before the whole polynomial is
lifted. When the denominator of a polynomial has a large factor which
does not divide the previous ones (e.g. the first polynomial, or one
where the denominators jump), this reconstruction needs about
bits(n) + 2 bits(d) bits of modulus, d being the new factor, while the
numerators n only need bits(n).

The witnesses of a polynomial share their denominator. Up to 8 of them
(the three witnesses and nonzero coefficients spread over the
polynomial) are now reconstructed simultaneously as a short vector of a
lattice found by LLL, which needs about bits(n) + bits(d) / k bits. LLL
is tried when the rational reconstruction of the witnesses fails, first
with the guessed denominator (the first column of the lattice is scaled
by its bitsize), then without it with 4 witnesses, since the guess
inflates the numerators when it shares little with the denominator. The
candidate is stored as the reconstructed witnesses, hence it is checked
with the next prime and used as the denominator of the full lifting, as
before.

LLL is not tried before the modulus has the bitsize of the guessed
denominator, then again each time the number of primes grows by
max(5%, sqrt(2A/n)), A being the cost of an attempt in units of the cost
of a prime, and its estimated cost is kept below 10% of the estimated
cost of the primes. These estimates use the operations recorded in the
trace with the weights of the cost model of hensel.c, and not timings,
so that the number of primes used stays reproducible. Without this
bound, LLL made random2_8_8 three times slower.

Fewer primes on bruno (1089 -> 629), KLYZ22 (725 -> 481), cyclic8
(46 -> 30), vor1 (124 -> 95) and minrank_d_2_p_3_q_7_r_3 (1633 -> 1417),
for speedups of 2.04, 1.67, 1.39, 1.25 and 1.23 (-g 2 -t 1); no change
on random2, kat and eco. The output is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Once the witness coefficients of a polynomial are checked, all its
coefficients are reconstructed with the lcm of the denominators found so
far as a guess. A coefficient whose denominator has a factor which
divides none of these needs about bits(n) + 2 bits(d) bits of modulus, d
being this factor, and the whole polynomial waits for it. This is what
bounds the number of primes on katsura and eco.

A coefficient whose reconstruction fails is now kept with its CRT image,
and up to 8 of them are reconstructed simultaneously by LLL with the
guessed denominator, as the witnesses are, together with already
reconstructed coefficients when less than 8 fail. On success, the guess
is multiplied by the factor found and they are reconstructed again with
it. The cost of these calls is bounded as for the witnesses, with a
schedule of their own. A wrong factor makes the lifted polynomial fail
the check with the next primes, as a wrong reconstruction does, and the
content of the lifted polynomial is removed in case LLL found a multiple
of the missing factor. The lattice reduction is shared with the
reconstruction of the witnesses (lll_common_den).

The reconstruction of the witnesses without guessed denominator, on a
lattice where LLL is much slower, only pays when the guess carries
factors foreign to the denominator. It is now tried only once, for some
lifted polynomial, at least 1/8 of the bits of the denominator of the
previous polynomial do not divide its own. On many systems (random,
minrank, cp_d) all denominators divide about the same integer and LLL
then only cost time: minrank_d_3_p_3_q_6_r_3 and random2_9_9 are no
longer slower than before the reconstruction by LLL.

henrion7 needs 161 primes instead of 202 (1.33 times faster with -g 2
-t 1), kat12 35 instead of 43, kat11 27 instead of 28, kat9 12 instead
of 13 and chandra-11 67 instead of 69. The output is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Once the witnesses of a polynomial are checked, each coefficient u was
lifted by CRT, then rationally reconstructed with the guessed
denominator g, the lcm of the denominators found so far. For most
coefficients the denominator divides g, so that u g is an integer and
the rational reconstruction only finds it again. On systems needing
thousands of primes (random, minrank, cp_d), this took about as much
time as the CRT, 15 to 25% of the total.

The CRT is now applied to the residues of u g modulo the primes, which
gives u g as the symmetric remainder modulo their product M. It is
accepted as an integer when it has RR_MARGIN bits less than M, else u
is lifted by CRT and rationally reconstructed as before. Most
coefficients thus cost one CRT, and neither the product u g of large
integers nor a rational reconstruction. As with a rational
reconstruction, a wrong integer (probability about 2^(-RR_MARGIN)) is
rejected when checking the lifted polynomial with the next primes. The
CRT is now taken over the primes whose product is M only: it was also
taken over the prime used for checking, with an old residue, which was
harmless since the result was then reduced modulo M.

The time of the rational reconstructions is divided by 3 to 9 on
minrank, random, cp_d and henrion7 (minrank_d_3_p_3_q_6_r_3: 14.4 to
1.5 s, 1.39 times faster in total, cp_d_3_n_6_p_2 1.25, random2_9_9
1.13 with -g 2 -t 1). Integers are also accepted with fewer bits than
the bounds of the rational reconstruction required: kat12 needs 34
primes instead of 35, eco12 12 instead of 13. The output is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the coefficients of a Groebner basis polynomial are reconstructed
by LLL with a guessed denominator g of s bits, the numerators of the
short vector have about s plus the bitsize of the missing factor d of
the denominator. The s - 64 lowest bits of the lattice entries
therefore do not change the short vector: LLL now runs on the lattice
whose entries are shifted right by these bits, d is read from the
reduced basis, and the numerators are recomputed exactly from d before
the unchanged acceptance test.

This makes each call 2 to 4 times faster for large guesses, which is
where LLL is wasted on random systems: their last stalled polynomials
are reconstructed by rational reconstruction at about the bitsize of
their integers, so that LLL cannot save primes there. The cost model
deciding the attempts is kept as an upper bound, so that the number of
primes is unchanged. On random2_10_10, LLL time drops from 74 to 21 s
for the same 15749 primes; outputs are identical on all systems tested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The multi-modular computation of Groebner bases over the rationals
(-g 2) used primes of 31 bits only. F4 computes modulo primes of up
to 52 bits with 64 bit integers, and with AVX-512 IFMA its cost per
bit of the modulus is then lower than with primes of 31 bits.

The trace is still learned modulo a prime of 31 bits, since learning
modulo a larger prime is slower; it is then applied modulo primes of
52 bits, whose images are stored on 64 bits (the images modulo 31
bit primes keep their 32 bit storage). The modular arithmetic of the
lifting, the CRT updates and the checks handle primes of 64 bits,
and copy_basis_mod_p supports the 64 bit coefficients.

Primes of 52 bits are used by default when msolve is built with
AVX-512 IFMA, else primes of 31 bits; the new option --gb-prime-bits
(31 or 52) selects them explicitly. With 31 bit primes, the primes
used and the outputs are unchanged.

On a Xeon Gold 6354 (Ice Lake, AVX-512 IFMA), 26 systems, 5 seeds
(2 for the largest ones), identical outputs: about 40% fewer primes,
1.16 times faster on geometric mean (from 0.96 to 1.33, 1.17 on
random2_10_10). Without IFMA, on an AVX2 machine, the gain is only
1.02 with losses up to 0.84, hence the default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The lattices used to reconstruct coefficients by LLL are small, and
fmpz_lll spends most of its time on them beyond the floating-point
reduction: on lattices of dimension 9 with a modulus of 360 to 900
bits, it takes 1.2 to 1.6 ms with FLINT 3.6 and 10 to 13 ms with
FLINT 3.1, against 0.1 to 0.4 ms for fmpz_lll_d_heuristic alone, which
finds the same short vectors. A certified reduction is not needed,
since the candidates are checked by their sizes and then with new
primes, so fmpz_lll is now only called when the heuristic reduction
fails. With FLINT 3.1, LLL took about 1 s out of 4.5 s on kat11-qq.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the check of a lifted polynomial fails, the lifting restarts from
this polynomial, and the following ones, which were lifted but not checked
yet, are lifted again. Their counter of checks was incremented instead of
being reset, so that their new lift was taken as checked without being
compared to the images modulo a prime not used to lift it. Since the
coefficients are accepted as integers when they are small enough, such a
lift may be wrong: this happened on chandra-15 when lifting with batches
of 32 primes. A lifted polynomial is now marked as unchecked, whether it
was lifted before or not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On Windows, unsigned long has 32 bits, so that the GMP functions mpz_*_ui
truncate the primes of 52 bits used for the Groebner bases over the
rationals when AVX-512 IFMA is available: the reductions of the input
coefficients modulo the primes, the products of the CRT modulus by the
primes, the CRT itself and the checks of the lifted coefficients were
wrong, so that the lifted polynomials never passed their checks. On the
Windows runners of the CI with AMD Zen 4 and Zen 5 processors, four tests
failed and diff_elim-drl-qq did not end. The primes and the coefficients
modulo the primes are now passed to GMP as limbs, which have 64 bits on
all 64 bit platforms (new header gmp_u64.h), and they are printed with
PRIu64.

The failures are reproduced on Linux by truncating to 32 bits the
arguments of the GMP functions taking an unsigned long: with this change,
make check passes in that setting, with a random seed and with the seed
of the CI. Otherwise, the outputs and the timings are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When a trace is applied, the matrices and the supports of the basis
elements are cached in the trace and published with compare-and-swap,
so that several primes can share them. Three places read these
pointers with plain loads, which is a data race when the trace is
applied concurrently for several primes. Read them with acquire loads
instead, so that the data written before publication is visible to
the readers. ThreadSanitizer reported no more races in the trace
application after this change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…acers

Over the rationals, the elimination via the DRL Groebner basis set the
round of the multi-modular computation, the information level and the
number of threads in the meta data of the DRL and elimination steps,
which are kept from one prime to the next. Once their tracers are
learnt, these fields are now set on copies of these meta data, which
are then only read, as in run_f4, so that the tracers can be applied
for several primes at the same time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With -t > 1, the trace is applied in batches of primes, one prime per
thread, and the images are then consumed prime by prime in the same
order as with a single thread, so the lifting decisions do not change.
The CRT of the coefficients runs in parallel chunks with one workspace
per thread. Chunks start at one coefficient per thread at each
polynomial and double, since the guessed denominator mostly changes at
the first coefficients. After such a change, the results already
computed are updated from the previous guess instead of being
recomputed. The witness CRTs, the residues of the guessed denominators
and the decimal conversion of the output also run in parallel, and the
inverse used by the witness CRTs is computed once per prime.

On 6 cores, random2_9_9 goes from 77.5 s to 23.0 s and
minrank_d_3_p_3_q_6_r_3 from 47.9 s to 12.9 s, with identical outputs.
The number of primes may still vary slightly between runs with several
threads, because the multi-threaded learning of the trace is not
deterministic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Splitting these CRTs among the threads made them slower: each one is
cheap, but their results then had to move from the caches of the other
threads to the one that reconstructs the witnesses. On random2_9_9 with
6 threads, they took 3.2 s in parallel and 1.3 s on one thread.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When lifting a Groebner basis over QQ, the CRTs of the three witness
coefficients of every polynomial not lifted yet were updated with each
new prime, while they are only used by the rational reconstruction of
the witnesses, which stops at the first polynomial for which it fails.
Only the polynomials already reached are now kept up to date prime by
prime; the CRTs of the next ones are computed from their images modulo
all the primes when the reconstruction reaches them, for as many
polynomials as threads at once, in parallel.

The results are the same symmetric remainders, so the primes used and
the output are unchanged. On an Intel Xeon Gold 6354 with 32 threads
and FLINT 3.6, the time of the CRTs goes from 33.5 to 23.0 s on
random2_10_10 (total 137.8 to 132.4 s) and from 5.4 to 4.4 s on
minrank_d_2_p_2_q_8_r_2 (total 28.9 to 27.4 s).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With several threads, the trace is applied to batches of as many primes
as threads, and then the main thread lifts them one by one: the
reconstructions of the witnesses and the calls to LLL run on a single
thread while the other threads wait. Most of them fail, and an attempt
in the middle of a batch saves no time since the whole batch is
computed anyway. Above 4 threads, the witnesses are now reconstructed
at most once per batch, two primes before its end so that a
reconstruction found is checked within the batch. In the spacing of
the attempts of LLL, an attempt now costs as many primes as threads,
since the primes are computed that many at once while LLL runs on one
thread.

The output is unchanged, and so are the primes used with at most 4
threads. On an Intel Xeon Gold 6354 with 32 threads and FLINT 3.6,
bruno goes from 3.78 to 2.24 s, KLYZ22 from 5.43 to 3.86 s, zimmermann
from 5.38 to 3.83 s, random2_9_9 from 16.0 to 12.7 s and random2_10_10
from 134.8 to 113.7 s (12 systems, geometric mean 1.18x); eco12 and
minrank_d_2_p_3_q_7_r_3, which need few primes or lose an LLL success,
are 6 to 10% slower.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Writing a lifted basis converted the coefficients in parallel but
formatted the terms on one thread, flushing the file after each term,
so that writing took up to a quarter of the running time with many
threads (11 s out of 47 s for chandra-14 with 32 threads). The terms
are now formatted in memory, without flushing, by all threads, by
chunks of at most 256 terms of a polynomial and about 64 KB of text,
which are written in order: this suits bases with many small
polynomials as well as bases with few polynomials with huge
coefficients, and bounds the memory used. The output is unchanged. On
a 2 x 18-core Xeon Gold 6354 with 32 threads, writing the basis takes
1.8 s instead of 11.1 s for chandra-14, 0.8 s instead of 4.6 s for
kat13, and 14.0 s instead of 15.1 s for random2_10_10.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With many threads, the lifting steps run between two batches of primes
kept the other threads idle for up to half of the computation. The
modular images of each polynomial were stored in one array, which was
enlarged (and copied) every few primes and zeroed, and the coefficients
of each lifted polynomial were reduced to their common denominator and
checked modulo the new primes by one thread. The images are now stored
by blocks of rows, one row per prime, allocated together for the primes
added at once, so that adding primes never copies the rows already
stored; the images of a new prime are copied by all threads, and so are
the reduction to the common denominator and the checks of the
polynomials of at least 512 terms. Since the blocks have various sizes,
the memory they occupied once free-ed is returned to the system once per
batch (with glibc). The output and the primes used are unchanged. On a
2 x 18-core Xeon Gold 6354 with 32 threads, chandra-14 takes 31.1 s
instead of 40.5 s, minrank_d_2_p_2_q_8_r_2 18.2 s instead of 23.1 s and
random2_10_10 99.3 s instead of 108.1 s, with less memory (12.7 GB
instead of 15.9 GB for chandra-14).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The coefficients of a polynomial are reconstructed by chunks, which
start with one coefficient per thread and double, the coefficients of a
chunk being split among the threads by blocks of four. The first chunks
of each polynomial thus kept only a quarter or a half of the threads
busy, and on bases with few, large polynomials most chunks are small.
The blocks are now made smaller for small chunks, so that each thread
gets about four of them; the output is unchanged. On a 2 x 18-core Xeon
Gold 6354 with 32 threads, the threads are busy 91 to 93% of the time
of this CRT instead of 55 to 71% on random2_9_9, random2_10_10 and
minrank_d_2_p_2_q_8_r_2, and random2_9_9 takes 9.9 s instead of 11.2 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With batches of primes, the witnesses are reconstructed once per batch,
but the polynomials are reconstructed in a few attempts only, by groups
of polynomials with coefficients of about the same size: in between,
every attempt fails on the same polynomial, and these failures cost up
to a tenth of the computation on random systems. After an attempt which
reconstructs no polynomial, the next one is now made after a growth of
the number of primes given, as for LLL, by the estimated cost of an
attempt (fitted on the size of the modulus) relative to the cost of a
prime, but limited to 3 percent, which bounds the primes added when the
last polynomials are reconstructed later. It depends only on the trace
and on the number of primes and of threads, and nothing changes with 4
threads or fewer. On a 2 x 18-core Xeon Gold 6354, random2_10_10 takes
89.1 s instead of 93.8 s with 32 threads and 216.0 s instead of 226.6 s
with 8 threads, with up to 3 percent more primes; random2_9_9 takes
19.1 s instead of 21.8 s with 8 threads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With -g 2 and t threads, the trace is applied to batches of t primes, one
thread per prime, so that the memory grows with t: each thread runs its
own F4 application, the bases computed are held until they are lifted,
and the images of the primes wait for the next reconstruction attempt,
made once per batch. With the new option --local-threads p, where p
divides t, the batches have t/p primes, each computed by p threads, and
the reconstruction attempts are spaced by these batches; the CRT still
uses the t threads. The primes used then depend on p, but they are
reproducible for given t and p. If p does not divide t, a warning is
printed and one thread per prime is used; without the option, nothing
changes. A test checks both cases on cyclic5.

The primes of a batch are then applied by threads started with
pthread_create rather than in a parallel region: the parallel regions of
F4 would be nested in it, and libgomp starts new threads for each nested
region, which doubles the time of an application when a batch has a
single prime.

On an Intel Xeon Gold 6354 with 32 threads and FLINT 3.6, with p = 4,
eco14 goes from 27.8 s and 9.7 GB to 24.4 s and 3.3 GB, cyclic9 from
160 s and 24.3 GB to 159 s and 6.9 GB, and chandra-15 from 148 s and
58.5 GB to 150 s and 22.2 GB. With p = 32, eco14 takes 35.8 s and
1.5 GB and chandra-15 331 s and 15.4 GB, against 41.2 s and 429 s when
the primes are computed and lifted one at a time with 32 threads.

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