Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleans partly change of order functions and data-structures which are no more used #176

Merged
merged 2 commits into from
Sep 18, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/fglm/data_fglm.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static inline void free_sp_mat_fglm(sp_matfglm_t *mat){
static inline fglm_data_t *allocate_fglm_data(szmat_t nrows, szmat_t ncols, szmat_t nvars){
fglm_data_t * data = malloc(sizeof(fglm_data_t));

szmat_t block_size = nvars; //taille de bloc dans data->res
szmat_t block_size = nvars; //block size in data->res

if(posix_memalign((void **)&data->vecinit, 32, ncols*sizeof(CF_t))){
fprintf(stderr, "posix_memalign failed\n");
Expand Down
198 changes: 9 additions & 189 deletions src/fglm/fglm_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ static inline void generate_sequence(sp_matfglm_t *matrix, fglm_data_t * data,
}
#endif

static void generate_matrix_sequence(sp_matfglm_t *matxn, fglm_data_t * data,
static void generate_matrix_sequence(sp_matfglm_t *matxn, fglm_data_t *data,
szmat_t block_size, long dimquot,
nvars_t* squvars,
nvars_t* linvars,
Expand All @@ -708,7 +708,14 @@ static void generate_matrix_sequence(sp_matfglm_t *matxn, fglm_data_t * data,
const szmat_t ncols = matxn->ncols;
const szmat_t nrows = matxn->nrows;

const int BL = 16;
int BL = 0;
if(nvars < 16){
BL = 16;
}
else{
BL = 32;
}

/* allocates random matrix */
CF_t *Rmat ALIGNED32;
if(posix_memalign((void **)&Rmat, 32, BL*ncols*sizeof(CF_t))){
Expand Down Expand Up @@ -1500,193 +1507,6 @@ static inline long initialize_fglm_colon_data(sp_matfglmcol_t *matrix,
}


param_t *nmod_fglm_compute(sp_matfglm_t *matrix, const mod_t prime, const nvars_t nvars,
const szmat_t nlins,
nvars_t *linvars,
uint32_t *lineqs,
nvars_t *squvars,
const int info_level,
md_t *st){
#if DEBUGFGLM > 0
fprintf(stderr, "prime = %u\n", prime);
#endif

#if DEBUGFGLM >= 1
FILE *fmat = fopen("/tmp/matrix.fglm", "w");
display_fglm_matrix(fmat, matrix);
fclose(fmat);
#endif
/* 1147878294 */
if(prime>=1518500213){
fprintf(stderr, "Prime %u is too large.\n", prime);
fprintf(stderr, "One needs to use update linear algebra fglm functions\n");
return NULL;
}

szmat_t block_size = nvars-nlins;

fglm_data_t *data = allocate_fglm_data(matrix->nrows, matrix->ncols, nvars);

param_t *param = allocate_fglm_param(prime, nvars);

long sz = matrix->ncols * matrix->nrows;
long nb = initialize_fglm_data(matrix, data, prime, sz, block_size);

if(info_level){
fprintf(stderr, "[%u, %u], Dense / Total = %.2f%%\n",
matrix->ncols, matrix->nrows,
100*((double)matrix->nrows / (double)matrix->ncols));
fprintf(stderr, "Density of non-trivial part %.2f%%\n",
100-100*(float)nb/(float)sz);
}

szmat_t dimquot = (matrix->ncols);

#if DEBUGFGLM > 1
print_vec(stderr, data->vecinit, matrix->ncols);
print_vec(stderr, data->res, 2 * block_size * matrix->ncols);
fprintf(stderr, "\n");
#endif

double st1 = realtime();

#ifdef BLOCKWIED
fprintf(stderr, "Starts computation of matrix sequence\n");
double st0 = omp_get_wtime();
generate_matrix_sequence(matrix, data, block_size, dimquot,
squvars, linvars, nvars, prime, st);
double et0 = omp_get_wtime() - st0;
fprintf(stderr, "Matrix sequence computed\n");
fprintf(stderr, "Elapsed time : %.2f\n", et0);
fprintf(stderr, "Implementation to be completed\n");

// pick some nbrows, nbcols, length
// (matrix sequence has "2*glen" matrices of size "gdim x gdim"
slong gdim = 16;
slong glen = 4096;
nmod_mat_poly_t matp;
nmod_mat_poly_init2(matp, 2*gdim, gdim, prime, 2*glen);
// top gdim x gdim submatrix matrices is formed from the matrix sequence
// for the moment, let's take random coefficients
flint_rand_t state;
flint_randinit(state);
srand(time(0));
flint_randseed(state, rand(), rand());
for (slong k = 0; k < 2*glen; k++)
{
mp_ptr vec = (matp->coeffs + k)->entries;
for (slong i = 0; i < gdim*gdim; i++)
vec[i] = n_randint(state, matp->mod.n);
}
// bottom gdim x gdim submatrix is -identity
for (slong i = 0; i < gdim; i++)
nmod_mat_entry(matp->coeffs + 0, gdim+i, i) = prime-1;

// convert to poly_mat pmat, and forget matp
double st_recon = omp_get_wtime();
nmod_poly_mat_t pmat;
nmod_poly_mat_set_from_mat_poly(pmat, matp);
nmod_mat_poly_clear(matp);

// fraction reconstruction
nmod_poly_mat_t appbas;
nmod_poly_mat_init(appbas, 2*gdim, 2*gdim, prime);
nmod_poly_mat_pmbasis(appbas, NULL, pmat, 2*glen);
// extract generator and forget appbas
nmod_poly_mat_t gen;
nmod_poly_mat_init(gen, gdim, gdim, prime);
for (slong i = 0; i < gdim; i++)
for (slong j = 0; j < gdim; j++)
nmod_poly_swap(gen->rows[i] + j, appbas->rows[i] + j);
nmod_poly_mat_clear(appbas);

double tt_recon = omp_get_wtime() - st_recon;
fprintf(stderr, "Matrix generator computed\n");
fprintf(stderr, "Elapsed time : %.2f\n", tt_recon);
fprintf(stderr, "Implementation to be completed\n");

exit(1);
#else
generate_sequence_verif(matrix, data, block_size, dimquot,
squvars, linvars, nvars, prime, st);
#endif
if(info_level > 1){
double nops = 2 * (matrix->nrows/ 1000.0) * (matrix->ncols / 1000.0) * (matrix->ncols / 1000.0);
double rt1 = realtime()-st1;
fprintf(stderr, "Time spent to generate sequence (elapsed): %.2f sec (%.2f Gops/sec)\n", rt1, nops / rt1);
}

st1 = realtime();

/* Berlekamp-Massey data */
fglm_bms_data_t *data_bms = allocate_fglm_bms_data(dimquot, prime);

long dim = 0;
compute_minpoly(param, data, data_bms, dimquot, linvars, lineqs, nvars, &dim,
info_level);

if(info_level){
fprintf(stderr, "Time spent to compute eliminating polynomial (elapsed: %.2f sec\n",
realtime()-st1);
}


if (dimquot == dim) {

if(info_level){
fprintf(stderr, "Elimination polynomial is squarefree.\n");
}

st1 = realtime();
if(compute_parametrizations(param, data, data_bms,
dim, dimquot, block_size,
nlins, linvars, lineqs,
nvars) == 0){

fprintf(stderr, "Matrix is not invertible (there should be a bug)\n");
free_fglm_bms_data(data_bms);
free_fglm_data(data);
return NULL;

}

} else {

fprintf(stderr, "Elimination polynomial is not squarefree.\n");

int right_param= compute_parametrizations_non_shape_position_case(param,
data,
data_bms,
dimquot,
block_size,
nlins, linvars,
lineqs, squvars,
nvars, prime,
1); /* verif */
if (right_param == 0) {
fprintf(stderr, "Matrix is not invertible (there should be a bug)\n");
free_fglm_bms_data(data_bms);
free_fglm_data(data);
return NULL;
} else if (right_param == 1) {
fprintf(stderr, "Radical ideal might have no correct parametrization\n");
} else if (right_param < nvars) {
fprintf(stderr, "Only the first %d parametrizations of ",right_param-1);
} else {
fprintf(stderr, "All the parametrizations of ");
fprintf(stderr, "the radical ideal are correct\n");
}
}
if(info_level){
fprintf(stderr, "Time spent to compute parametrizations (elapsed): %.2f sec\n",
realtime()-st1);
fprintf(stderr, "Parametrizations done.\n");
}
free_fglm_bms_data(data_bms);
free_fglm_data(data);
return param;
}


param_t *nmod_fglm_compute_trace_data(sp_matfglm_t *matrix, mod_t prime,
szmat_t nvars,
Expand Down
11 changes: 6 additions & 5 deletions src/msolve/msolve-data.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,12 @@ typedef struct{
#define ALIGNED32 __attribute__((aligned(32)))
#endif
typedef struct{
CF_t *vecinit ALIGNED32; //vecteur initial
CF_t *res ALIGNED32; //va contenir les termes de suites qui nous interessent
CF_t *vecmult ALIGNED32; //utilise pour la multiplication
CF_t *vvec ALIGNED32;
CF_l_t *vec_cache ALIGNED32; //useless
CF_t *vecinit ALIGNED32; /* init vector used in Wiedemann's implementation */
CF_t *vecmult ALIGNED32; /* vector used to store the multiplication of the
* dense part of the multiplication matrix with a
* vector in Wiedemann */
CF_t *vvec ALIGNED32; /* stores the result of matrix vector product in Wiedeman */
CF_t *res ALIGNED32; /* array storing the term sequences needed after Wiedeman */
mp_limb_t *pts;
} fglm_data_t;

Expand Down
Loading