Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fglm_build_matrixn_radical-shape-31
line_endings_support
neogb_io
neogb_f4_52_bit
neogb_rng
msolve-*.tar.gz
msolve-*/
src/msolve/msolve-version.h
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ msolve_SOURCES = src/msolve/main.c

check_PROGRAMS = neogb_io \
neogb_f4_52_bit \
neogb_rng \
fglm_build_matrixn_radical-shape-31 \
fglm_build_matrixn_nonradical-shape-31 \
fglm_build_matrixn_nonradical-radicalshape-31 \
Expand Down Expand Up @@ -87,6 +88,7 @@ checkdiff = test/diff/diff_bug-2nd-prime-bad.sh \
# dist_check_DATA = test/input_files
neogb_io_SOURCES = test/neogb/io/validate_input_data.c
neogb_f4_52_bit_SOURCES = test/neogb/f4/f4_52_bit.c
neogb_rng_SOURCES = test/neogb/rng/mt19937.c
fglm_build_matrixn_radical_shape_31_SOURCES = test/fglm/build_matrixn_radical-shape-31.c
fglm_build_matrixn_nonradical_shape_31_SOURCES = test/fglm/build_matrixn_nonradical-shape-31.c
fglm_build_matrixn_nonradical_radicalshape_31_SOURCES = test/fglm/build_matrixn_nonradical-radicalshape-31.c
Expand Down
17 changes: 9 additions & 8 deletions src/fglm/fglm_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include<time.h>
/* for timing functions */
#include "../neogb/tools.h"
#include "../neogb/rng.h"
#include "../msolve/streams.h"

#ifdef _OPENMP
Expand Down Expand Up @@ -618,8 +619,8 @@ static void generate_matrix_sequence(sp_matfglm_t *matxn, fglm_data_t *data,
Rmat[i] = 0;
}
for(szmat_t i = 0; i < matxn->ncols; i++){
Rmat[i] = (CF_t)rand() % prime;
Rmat[i] += (CF_t)rand() % prime;
Rmat[i] = (CF_t)msolve_rand() % prime;
Rmat[i] += (CF_t)msolve_rand() % prime;
}

/* allocates result matrix (matxn * Rmat) */
Expand Down Expand Up @@ -1150,7 +1151,7 @@ int compute_parametrizations_non_shape_position_case(param_t *param,
if(linvars[nvars - 2 - nc] == 0
&& squvars[nvars - 2 - nc] != 0){

uint64_t lambda= 1 + ((uint64_t) rand() % (prime-1));
uint64_t lambda= 1 + ((uint64_t) msolve_rand() % (prime-1));
/* needed for verification */

invert_table_polynomial (param, data, data_bms, block_size,
Expand Down Expand Up @@ -1257,7 +1258,7 @@ static int compute_parametrizations_colon(param_t *param,
if(linvars[nvars - 2 - nc] == 0
&& squvars[nvars - 2 - nc] != 0){

uint64_t lambda= 1 + ((uint64_t) rand() % (prime-1));
uint64_t lambda= 1 + ((uint64_t) msolve_rand() % (prime-1));
/* needed for verification */

invert_table_polynomial (param, data, data_bms, block_size,
Expand Down Expand Up @@ -1323,9 +1324,9 @@ static inline long initialize_fglm_data(sp_matfglm_t *matrix,
if(matrix->dense_mat[i]==0)
nb++;
}
data->vecinit[0] = 1 + ((CF_t) rand() % (prime-1)); /* random, nonzero */
data->vecinit[0] = 1 + ((CF_t) msolve_rand() % (prime-1)); /* random, nonzero */
for(szmat_t i = 1; i < matrix->ncols; i++){
data->vecinit[i] = (CF_t)rand() % prime;
data->vecinit[i] = (CF_t)msolve_rand() % prime;
}
data->res[0] = data->vecinit[0];
for(szmat_t i = 1; i < block_size; i++){
Expand All @@ -1345,8 +1346,8 @@ static inline long initialize_fglm_colon_data(sp_matfglmcol_t *matrix,
nb++;
}
for(szmat_t i = 0; i < matrix->ncols; i++){
data->vecinit[i] = (CF_t)rand() % prime;
data->vecinit[i] += (CF_t)rand() % prime;
data->vecinit[i] = (CF_t)msolve_rand() % prime;
data->vecinit[i] += (CF_t)msolve_rand() % prime;
/* data->vecinit[i] = (CF_t)(i+1) % prime; */
}
data->res[0] = data->vecinit[0];
Expand Down
6 changes: 3 additions & 3 deletions src/msolve/lifting-gb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1522,9 +1522,9 @@ gb_modpoly_t *core_groebner_qq(
uint32_t primeinit = 0;
uint32_t lprime = 1303905299;

prime = next_prime(rand() % (1303905301 - (1<<30) + 1) + (1<<30));
prime = next_prime(msolve_rand() % (1303905301 - (1<<30) + 1) + (1<<30));
while(fc == 0 && is_lucky_prime_ui(prime, bs)){
prime = next_prime(rand() % (1303905301 - (1<<30) + 1) + (1<<30));
prime = next_prime(msolve_rand() % (1303905301 - (1<<30) + 1) + (1<<30));
}

primeinit = prime;
Expand Down Expand Up @@ -1640,7 +1640,7 @@ gb_modpoly_t *core_groebner_qq(


learn = 0;
prime = next_prime(rand() % (1303905301 - (1<<30) + 1) + (1<<30));
prime = next_prime(msolve_rand() % (1303905301 - (1<<30) + 1) + (1<<30));
if(info_level){
fprintf(VERBSTREAM, "New prime = %d\n", prime);
}
Expand Down
4 changes: 2 additions & 2 deletions src/msolve/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,14 +561,14 @@ int main(int argc, char **argv){
&precision, &generate_pbm,
&seed, &info_level, files);

/* srand initialization */
/* pseudo-random number generator initialization */
uint32_t true_seed;
if (seed < 0) {
true_seed = time(0);
} else {
true_seed = (uint32_t) seed;
}
srand(true_seed);
msolve_srand(true_seed);
if (info_level) {
fprintf (VERBSTREAM,"Initial seed for pseudo-random number generator ");
fprintf (VERBSTREAM,"is %u\n",true_seed);
Expand Down
24 changes: 14 additions & 10 deletions src/msolve/msolve.c
Original file line number Diff line number Diff line change
Expand Up @@ -756,19 +756,19 @@ static int add_random_linear_form_to_input_system(data_gens_ff_t *gens,
if (gens->field_char > 0) {
int j = 0;
for (i = len_old; i < len_new; i++, j++) {
int32_t rdval = ((int8_t)(rand()) % gens->field_char);
int32_t rdval = ((int8_t)(msolve_rand()) % gens->field_char);
while (rdval == 0) {
rdval = ((int8_t)(rand()) % gens->field_char);
rdval = ((int8_t)(msolve_rand()) % gens->field_char);
}
gens->random_linear_form[j] = rdval;
gens->cfs[i] = rdval;
}
} else {
int j = 0;
for (i = len_old; i < len_new; i++, j++) {
int32_t rdval = rand();
int32_t rdval = msolve_rand();
while (rdval == 0) {
rdval = rand();
rdval = msolve_rand();
}
gens->random_linear_form[j] = rdval;
mpz_set_si(*(gens->mpz_cfs[2*i]), rdval);
Expand Down Expand Up @@ -2230,9 +2230,12 @@ static void secondary_modular_steps(sp_matfglm_t **bmatrix,
for(nvars_t i = 0; i < st->nprimes; i++){
bad_primes[i] = 0;
}
const uint32_t rng_base = msolve_rand_u32();
const msolve_rng_t rng_saved = *msolve_rng_current();
#pragma omp parallel for num_threads(nthrds) \
private(i) schedule(static)
for (i = 0; i < st->nprimes; ++i){
msolve_srand(msolve_rng_derive_seed(rng_base, i));
if (trace_det->mat_lifted < 2 || trace_det->lin_lifted < 2) {
bs[i] = core_gba(bs_qq, st, &error, lp->p[i]);
*stf4 = realtime()-rt;
Expand Down Expand Up @@ -2320,6 +2323,7 @@ static void secondary_modular_steps(sp_matfglm_t **bmatrix,
free_basis_and_only_local_hash_table_data(&(bs[i]));
}
}
*msolve_rng_current() = rng_saved;
st->nthrds = nthrds;
}

Expand Down Expand Up @@ -2819,9 +2823,9 @@ int msolve_trace_qq(mpz_param_t *mpz_paramp,
uint32_t lprime = 1303905299;
/* choose next_prime of some random number between 1<<30 and 1303905301 */
/* (roughly, there are ~ 10**7 such primes) */
prime = next_prime(rand() % (1303905301 - (1 << 30) + 1) + (1 << 30));
prime = next_prime(msolve_rand() % (1303905301 - (1 << 30) + 1) + (1 << 30));
while (gens->field_char == 0 && (is_lucky_prime_ui(prime, bs_qq) || is_member(prime, (*binit_primes)))) {
prime = next_prime(rand() % (1303905301 - (1 << 30) + 1) + (1 << 30));
prime = next_prime(msolve_rand() % (1303905301 - (1 << 30) + 1) + (1 << 30));
}
primeinit = prime;
lp->p[0] = primeinit;
Expand Down Expand Up @@ -5696,9 +5700,9 @@ int core_msolve(
trace_t *trace = initialize_trace(bs_qq, st);

uint32_t prime = next_prime(1<<30);
prime = next_prime(rand() % (1303905301 - (1<<30) + 1) + (1<<30));
prime = next_prime(msolve_rand() % (1303905301 - (1<<30) + 1) + (1<<30));
while(is_lucky_prime_ui(prime, bs_qq)){
prime = next_prime(rand() % (1303905301 - (1<<30) + 1) + (1<<30));
prime = next_prime(msolve_rand() % (1303905301 - (1<<30) + 1) + (1<<30));
}

uint32_t primeinit = prime;
Expand Down Expand Up @@ -5880,9 +5884,9 @@ int core_msolve(
st->tr = trace;

uint32_t prime = next_prime(1<<30);
prime = next_prime(rand() % (1303905301 - (1<<30) + 1) + (1<<30));
prime = next_prime(msolve_rand() % (1303905301 - (1<<30) + 1) + (1<<30));
while(is_lucky_prime_ui(prime, bs_qq)){
prime = next_prime(rand() % (1303905301 - (1<<30) + 1) + (1<<30));
prime = next_prime(msolve_rand() % (1303905301 - (1<<30) + 1) + (1<<30));
}

uint32_t primeinit = prime;
Expand Down
6 changes: 5 additions & 1 deletion src/neogb/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ libneogb_la_SOURCES = libneogb.h gb.c
libneogb_ladir = $(includedir)/msolve/neogb
libneogb_la_HEADERS =libneogb.h basis.h data.h engine.h f4.h sba.h hash.h \
io.h modular.h nf.h f4sat.h sort_r.h meta_data.h \
tools.h update.h
tools.h update.h rng.h mt.h
libneogb_la_LDFLAGS = -version-info $(LT_VERSION)
libneogb_la_CFLAGS = $(SIMD_FLAGS) $(CPUEXT_FLAGS) $(OPENMP_CFLAGS) -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare

Expand All @@ -21,6 +21,8 @@ EXTRA_DIST = basis.h \
meta_data.h \
tools.h \
update.h \
rng.h \
mt.h \
basis.c \
convert.c \
data.c \
Expand All @@ -43,4 +45,6 @@ EXTRA_DIST = basis.h \
meta_data.c \
symbol.c \
tools.c \
rng.c \
mt.c \
update.c
2 changes: 2 additions & 0 deletions src/neogb/gb.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "libneogb.h"
#include "data.c"
#include "meta_data.c"/* computational meta data */
#include "mt.c" /* MT19937 from GSL 1.9 */
#include "rng.c" /* platform independent pseudo-random numbers */
#include "tools.c" /* tools like inversion mod p,
* tracer construction, timings etc. */
#include "sort_r.h" /* special quicksort implementation */
Expand Down
2 changes: 1 addition & 1 deletion src/neogb/la_ff_16.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ static hm_t *reduce_dense_row_by_known_pivots_sparse_ff_16(
#define LA_CF_T cf16_t
#define LA_CF cf_16
#define LA_FF(name) name##_ff_16
#define LA_RANDOM_MULTIPLIER(fc) ((int64_t)rand() % (fc))
#define LA_RANDOM_MULTIPLIER(rng, fc) ((int64_t)msolve_rng_rand(rng) % (fc))

#define LA_SMALL(name) name##_ff_16
#include "la_ff_small_prime.c"
Expand Down
5 changes: 3 additions & 2 deletions src/neogb/la_ff_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static int is_kernel_trivial(
/* fill random value array */
for (i = 0; i < ncr; ++i) {
do {
mull[j] = (int64_t)rand() % fc;
mull[j] = (int64_t)msolve_rand() % fc;
} while (mull[j] == 0);
}
for (i = 0; i < sat->ld; ++i) {
Expand Down Expand Up @@ -1997,7 +1997,8 @@ static cf32_t *reduce_dense_row_by_dense_new_pivots_31_bit(
#define LA_FF(name) name##_ff_32
/* restrict random multipliers to < 2^15, see
* probabilistic_sparse_reduced_echelon_form_ff_32() */
#define LA_RANDOM_MULTIPLIER(fc) ((int64_t)rand() & ((1 << 15) - 1))
#define LA_RANDOM_MULTIPLIER(rng, fc) \
((int64_t)msolve_rng_rand(rng) & ((1 << 15) - 1))

#define LA_SMALL(name) name##_17_bit
#include "la_ff_small_prime.c"
Expand Down
11 changes: 9 additions & 2 deletions src/neogb/la_ff_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -1183,8 +1183,15 @@ static cf64_t *reduce_dense_row_by_all_pivots_ff_64(
#define LA_CF_T cf64_t
#define LA_CF cf_64
#define LA_FF(name) name##_ff_64
#define LA_RANDOM_MULTIPLIER(fc) \
((int64_t)((((uint64_t)rand() << 31) ^ (uint64_t)rand()) % (fc)))
/* the two draws are sequenced so that the multiplier does not depend on
* the evaluation order chosen by the compiler */
static inline int64_t random_multiplier_ff_64(msolve_rng_t *rng, uint64_t fc)
{
const uint64_t hi = (uint64_t)msolve_rng_rand(rng);
const uint64_t lo = (uint64_t)msolve_rng_rand(rng);
return (int64_t)(((hi << 31) ^ lo) % fc);
}
#define LA_RANDOM_MULTIPLIER(rng, fc) random_multiplier_ff_64((rng), (fc))

/* maximal number of rows reduced together by the known pivots, see
* LA_FF(reduce_dense_rows_by_known_pivots) in la_ff_common.c */
Expand Down
2 changes: 1 addition & 1 deletion src/neogb/la_ff_8.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ static hm_t *reduce_dense_row_by_known_pivots_sparse_ff_8(
#define LA_CF_T cf8_t
#define LA_CF cf_8
#define LA_FF(name) name##_ff_8
#define LA_RANDOM_MULTIPLIER(fc) ((int64_t)rand() % (fc))
#define LA_RANDOM_MULTIPLIER(rng, fc) ((int64_t)msolve_rng_rand(rng) % (fc))

#define LA_SMALL(name) name##_ff_8
#include "la_ff_small_prime.c"
Expand Down
23 changes: 16 additions & 7 deletions src/neogb/la_ff_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
* mat_t, e.g. cf_8
* LA_FF(name) appends the field suffix to name, e.g.
* LA_FF(foo) expands to foo_ff_8
* LA_RANDOM_MULTIPLIER(fc) random multiplier for the probabilistic
* linear algebra
* LA_RANDOM_MULTIPLIER(rng, fc) random multiplier for the probabilistic
* linear algebra, drawn from the generator rng
*
* Moreover, the following functions have to be defined:
*
Expand Down Expand Up @@ -635,6 +635,7 @@ static void LA_FF(probabilistic_sparse_reduced_echelon_form)(

/* mo need to have any sharing dependencies on parallel computation,
* no data to be synchronized at this step of the linear algebra */
const uint32_t rng_base = msolve_rand_u32();
#pragma omp parallel for num_threads(st->nthrds) \
private(i, j, k, l, m) \
schedule(dynamic)
Expand All @@ -649,6 +650,8 @@ static void LA_FF(probabilistic_sparse_reduced_echelon_form)(
/* starting column, offset, coefficient array position in tmpcf */
hm_t sc, cfp;
len_t bctr = 0;
msolve_rng_t rng;
msolve_rng_seed(&rng, msolve_rng_derive_seed(rng_base, i));
/* the combinations start at the smallest lead term of the
* rows of the block. As in the exact linear algebra, they are
* only reduced together if the rows fill at least 1/32 of
Expand All @@ -673,7 +676,7 @@ static void LA_FF(probabilistic_sparse_reduced_echelon_form)(
/* fill random value array */
for (j = 0; j < nrbl; ++j) {
do {
mull[j] = LA_RANDOM_MULTIPLIER(fc);
mull[j] = LA_RANDOM_MULTIPLIER(&rng, fc);
} while (mull[j] == 0);
}
/* generate one dense row as random linear combination
Expand Down Expand Up @@ -758,7 +761,7 @@ static void LA_FF(probabilistic_sparse_reduced_echelon_form)(
for (j = 0; j < nl; ++j) {
int64_t c;
do {
c = LA_RANDOM_MULTIPLIER(fc);
c = LA_RANDOM_MULTIPLIER(&rng, fc);
} while (c == 0);
mm[j] = ff64_mont((uint64_t)c, &f);
}
Expand All @@ -772,7 +775,7 @@ static void LA_FF(probabilistic_sparse_reduced_echelon_form)(
int64_t mc[LA_NR];
for (j = 0; j < nl; ++j) {
do {
mc[j] = LA_RANDOM_MULTIPLIER(fc);
mc[j] = LA_RANDOM_MULTIPLIER(&rng, fc);
} while (mc[j] == 0);
}
for (l = 0; l < len; ++l) {
Expand Down Expand Up @@ -2065,6 +2068,7 @@ static LA_CF_T **LA_FF(probabilistic_dense_linear_algebra)(
(uint64_t)rpb * st->nthrds * sizeof(int64_t));

/* reduction process to get all possible pivots, no interreduction here */
const uint32_t rng_base = msolve_rand_u32();
#pragma omp parallel for num_threads(st->nthrds) \
private(i, j, k, l) shared(nps, tbr) \
schedule(dynamic)
Expand All @@ -2079,6 +2083,8 @@ static LA_CF_T **LA_FF(probabilistic_dense_linear_algebra)(
hm_t os;
LA_CF_T *tmp;
len_t bctr = 0;
msolve_rng_t rng;
msolve_rng_seed(&rng, msolve_rng_derive_seed(rng_base, i));
while (bctr < nrbl) {
npc = 0;
#ifndef LA_WIDE
Expand All @@ -2088,7 +2094,7 @@ static LA_CF_T **LA_FF(probabilistic_dense_linear_algebra)(
/* fill random value array */
for (j = 0; j < nrbl; ++j) {
do {
mull[j] = LA_RANDOM_MULTIPLIER(fc);
mull[j] = LA_RANDOM_MULTIPLIER(&rng, fc);
} while (mull[j] == 0);
}
/* generate one dense row as random linear combination
Expand Down Expand Up @@ -2214,6 +2220,7 @@ static LA_CF_T **LA_FF(probabilistic_sparse_dense_echelon_form)(
(uint64_t)rpb * st->nthrds * sizeof(int64_t));

/* reduction process to get all possible pivots, no interreduction here */
const uint32_t rng_base = msolve_rand_u32();
#pragma omp parallel for num_threads(st->nthrds) \
private(i, j, k, l, m) shared(nps) \
schedule(dynamic)
Expand All @@ -2227,13 +2234,15 @@ static LA_CF_T **LA_FF(probabilistic_sparse_dense_echelon_form)(
LA_CF_T *tmp;
hm_t npc;
len_t bctr = 0;
msolve_rng_t rng;
msolve_rng_seed(&rng, msolve_rng_derive_seed(rng_base, i));
while (bctr < nrbl) {
npc = 0;

/* fill random value array */
for (j = 0; j < nrbl; ++j) {
do {
mull[j] = (int64_t)rand() % fc;
mull[j] = (int64_t)msolve_rng_rand(&rng) % fc;
} while (mull[j] == 0);
}
/* generate one dense row as random linear combination
Expand Down
Loading
Loading