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 @@ -51,6 +51,7 @@ fglm_build_matrixn_nonradical-shape-31
fglm_build_matrixn_radical-shape-31
line_endings_support
neogb_io
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 @@ -8,6 +8,7 @@ bin_PROGRAMS = msolve
msolve_SOURCES = src/msolve/main.c

check_PROGRAMS = neogb_io \
neogb_rng \
fglm_build_matrixn_radical-shape-31 \
fglm_build_matrixn_nonradical-shape-31 \
fglm_build_matrixn_nonradical-radicalshape-31 \
Expand Down Expand Up @@ -82,6 +83,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_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 @@ -1309,9 +1309,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 @@ -1426,7 +1426,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 @@ -543,14 +543,14 @@ int main(int argc, char **argv){
&precision, &refine, &isolate, &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 @@ -735,19 +735,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 @@ -1855,9 +1855,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 @@ -1945,6 +1948,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 @@ -2248,9 +2252,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 @@ -4840,9 +4844,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 @@ -5024,9 +5028,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 @@ -40,4 +42,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
15 changes: 12 additions & 3 deletions src/neogb/la_ff_16.c
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ static void probabilistic_sparse_reduced_echelon_form_ff_16(

/* 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 @@ -772,14 +773,16 @@ static void probabilistic_sparse_reduced_echelon_form_ff_16(
/* 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));
while (bctr < nrbl) {
cfp = bctr + i*rpb;
sc = 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 Expand Up @@ -1657,6 +1660,7 @@ static cf16_t **probabilistic_dense_linear_algebra_ff_16(
(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 @@ -1671,14 +1675,16 @@ static cf16_t **probabilistic_dense_linear_algebra_ff_16(
hm_t os;
cf16_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;
os = ncr % UNROLL;

/* 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 Expand Up @@ -1793,6 +1799,7 @@ static cf16_t **probabilistic_sparse_dense_echelon_form_ff_16(
(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 @@ -1806,13 +1813,15 @@ static cf16_t **probabilistic_sparse_dense_echelon_form_ff_16(
cf16_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
15 changes: 12 additions & 3 deletions src/neogb/la_ff_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -2364,6 +2364,7 @@ static void probabilistic_sparse_reduced_echelon_form_ff_32(

/* 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 @@ -2378,14 +2379,16 @@ static void probabilistic_sparse_reduced_echelon_form_ff_32(
/* 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));
while (bctr < nrbl) {
cfp = bctr + i*rpb;
sc = 0;

/* fill random value array */
for (j = 0; j < nrbl; ++j) {
do {
mull[j] = (int64_t)rand() & mask;
mull[j] = (int64_t)msolve_rng_rand(&rng) & mask;
} while (mull[j] == 0);
}
/* generate one dense row as random linear combination
Expand Down Expand Up @@ -3583,6 +3586,7 @@ static cf32_t **probabilistic_dense_linear_algebra_ff_32(
(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 @@ -3597,14 +3601,16 @@ static cf32_t **probabilistic_dense_linear_algebra_ff_32(
hm_t os;
cf32_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;
os = ncr % UNROLL;

/* fill random value array */
for (j = 0; j < nrbl; ++j) {
do {
mull[j] = (int64_t)rand() & mask;
mull[j] = (int64_t)msolve_rng_rand(&rng) & mask;
} while (mull[j] == 0);
}
/* generate one dense row as random linear combination
Expand Down Expand Up @@ -3719,6 +3725,7 @@ static cf32_t **probabilistic_sparse_dense_echelon_form_ff_32(
(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 @@ -3732,13 +3739,15 @@ static cf32_t **probabilistic_sparse_dense_echelon_form_ff_32(
cf32_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