1 #ifndef ALREADY_Solvestack
2 #define ALREADY_Solvestack
14 for(
int k=0;
k<nbelem;
k++)
25 for(
int k=0;
k<nbelem;
k++)
32 template<
typename compo,
typename workspace,
typename mon,
typename T>
35 template<
typename compo,
typename workspace,
typename mon,
typename T>
36 void wrap_vider_pile(
stack_elem * stack,
int stacksize,
39 int * nbstack,mutex &mymutex,
workspace *w)
47 vider_pile<compo,workspace,mon,T>(stack,stacksize,p,exceed_p
55 template<
typename compo,
typename workspace,
typename mon,
typename T>
65 map<rep_t,coeff_t> mapexceed;
66 int i,maxnfsize,
j,compt,
k;
67 unsigned long *tmpptr;
70 if (stacksize==0)
return;
71 for(i=0;i<stacksize;i++)
79 tmpptr=(
unsigned long *)p->nfind;
81 for(i=0;
i<p->sizenf/
sizeof(
unsigned long);i++)
84 ((
unsigned long*)w->
tabnf)[
i]=tmpptr[
i];
86 for(j=0;j<8*sizeof(unsigned long);j+=NUMBITS,mask>>=
NUMBITS)
94 for(i=0;i<sizeexceed_p;i++)
95 mapexceed[exceed_p[i].rep]=exceed_p[i].GetCoeff();
97 for(i=p->sizenf-(p->sizenf %
sizeof(
unsigned long));i<p->sizenf;i++)
106 for(k=0;k<stacksize;k++)
110 T tmpcoeff=stack[
k].
coeff;
112 tmpptr=(
unsigned long*)tmpp->nfind;
115 for(i=0;
i<tmpp->sizenf/
sizeof(
unsigned long);i++)
118 ((
unsigned long*)w->
tabnf)[
i]|=tmpptr[
i];
120 for(j=0;j<8*sizeof(unsigned long);j+=NUMBITS,mask>>=
NUMBITS)
125 (w->
tabcoeff+(8*
sizeof(
unsigned long)*i+j),
126 &tmpcoeff,tmpp->
nf+compt);
132 ((
unsigned long*)w->
tabnf)[
i]&=~(1<<(j+
k));
136 for(i=tmpp->sizenf-(tmpp->sizenf%
sizeof(
unsigned long));i<tmpp->sizenf;i++)
141 for(j=0;j<8;j++,mask<<=1)
143 if(tmpp->nfind[i]&mask)
181 p->
nf=(T*)MAC_REV_REALLOC<T>(p->
nf,p->
size*
sizeof(T),
184 p->nfind=(
unsigned char*)realloc(p->nfind,j+1);
194 unsigned char mask=1;
195 for(k=0;k<8;k++,mask<<=1)
210 cout<<
"dans vider pile exceed a la fin"<<endl;
211 auto itermap=mapexceed.begin();
212 for(
int i=0;itermap!=mapexceed.end();i++,itermap++)
213 cout<<
mon(itermap->second,itermap->first)<<
" ---- ";
217 MAC_REV_FREE<mon>(exceed_p,sizeexceed_p*
sizeof(
mon));
218 exceed_p=(
mon*)MAC_REV_MALLOC<mon>(mapexceed.size()*
sizeof(
mon));
219 auto itermap=mapexceed.begin();
220 for(
int i=0;itermap!=mapexceed.end();i++,itermap++)
221 exceed_p[i]=
mon(itermap->second,itermap->first);
222 sizeexceed_p=mapexceed.size();
225 template<
typename coeff,
typename workspace,
typename component>
232 const int taille=compo.
poly.size();
233 auto &tmpPk=compo.
poly;
236 int *nbstack=(
int*)
malloc((taille+1)*
sizeof(int));
238 list<std::thread > listthread;
239 mutex *tabmut=
new mutex[taille];
240 vector<workspace> vw(taille);
249 cout<<
"ds solveU"<<endl;
250 for(
int i=0;
i<taille;
i++)
258 for(
int i=u.ncol-1;
i>=0;
i--)
260 coeff mult_coeff=(coeff)1;
266 vider_pile<component,workspace,mon,COEFF>
275 for (j=((
i==(u.ncol-1))?(u.nnz-1):(u.colptr[
i+1]-1))
276 ;(j>=(u.colptr)[
i]);j--)
279 mult_coeff=((
COEFF*)u.nzval)[
j];
282 if(
Iszero(mult_coeff))
continue;
283 mult_coeff=((coeff)1)/mult_coeff;
287 compo.
exceed[
i][j]*=mult_coeff;
289 for (j=((
i==(u.ncol-1))?(u.nnz-1):(u.colptr[
i+1]-1))
290 ;(j>=(u.colptr)[
i]);j--)
295 tabmut[u.rowind[
j]].lock();
298 if(((
COEFF*)u.nzval)[j]!=(coeff)0)
300 stack[u.rowind[
j]*LEVELSTACK+nbstack[u.rowind[
j]]].
coeff
302 stack[u.rowind[
j]*LEVELSTACK+nbstack[u.rowind[
j]]].
p
304 stack[u.rowind[
j]*LEVELSTACK+nbstack[u.rowind[
j]]].
exceed=compo.
exceed[
i];
305 stack[u.rowind[
j]*LEVELSTACK+nbstack[u.rowind[
j]]].
sizeexceed=
307 nbstack[u.rowind[
j]]++;
308 if(nbstack[u.rowind[j]]==LEVELSTACK)
311 vider_pile<component,workspace,mon,COEFF>
313 ,&tmpPk[u.rowind[
j]],compo.
exceed[u.rowind[
j]],
318 nbstack[u.rowind[
j]]=0;
322 listthread.push_back(std::thread(
323 wrap_vider_pile<component,workspace,mon,COEFF>,
324 stack+u.rowind[j]*LEVELSTACK,LEVELSTACK
325 ,&tmpPk[u.rowind[j]],std::ref(compo.
exceed[u.rowind[j]]),
328 std::ref(tabmut[u.rowind[j]]),&vw[u.rowind[j]]));
331 for(
auto iterfuture=listthread.begin();
332 iterfuture!=listthread.end();iterfuture++)
334 listthread.erase(listthread.begin(),listthread.end());
341 tabmut[u.rowind[
j]].unlock();
348 tabmut[u.rowind[
j]].unlock();
357 for(
auto iterfuture=listthread.begin();
358 iterfuture!=listthread.end();iterfuture++)
360 listthread.erase(listthread.begin(),listthread.end());
367 typename list<pol >::iterator iterPk=Pk.begin();
368 for(
typename vector<pol >::iterator iter=tmpPk.begin()
369 ;iter!=tmpPk.end();iter++)
375 cout<<
"apres SolveU"<<endl;
376 for(
int i=0;
i<tmpPk.size();
i++)
378 cout<<
"compo.sizeexceed[i]<<endl; "<<compo.
sizeexceed[
i]<<endl;
381 copy(compo.
poly[
i].nf,compo.
poly[
i].nf+compo.
poly[
i].size,ostream_iterator<coeff>(cout,
" "));
383 cout<<
"compo "<<compo.
poly[
i].ind<<endl;
389 template<
typename workspace,
typename component,
typename coeff>
401 const int taille=l.nrow;
402 auto &tmpPk=compo.
poly;
406 int *nbstack=(
int*)
malloc((taille)*
sizeof(int));
408 list<std::thread > listthread;
409 mutex *tabmut=
new mutex[taille];
410 vector<workspace> vw(taille);
421 for(
int i=0;
i<taille;
i++)
425 cout<<
"avant SolveL"<<endl;
426 for(
int i=0;
i<tmpPk.size();
i++)
428 cout<<
"compo "<<compo.
poly[
i].ind<<endl;
430 copy(compo.
poly[
i].nf,compo.
poly[
i].nf+compo.
poly[
i].size,ostream_iterator<mon>(cout,
" "));
442 for(
int i=0;
i<l.ncol;
i++)
446 cout<<
"vider pile"<<endl;
449 cout<<
"compo "<<compo.
poly[
i].ind<<endl;
450 copy(compo.
poly[
i].nf,compo.
poly[
i].nf+compo.
poly[
i].size,ostream_iterator<coeff>(cout,
" --- "));
456 vider_pile<component,workspace,mon,COEFF>
464 for (;(j<l.nnz)&&(j<(l.colptr)[
i+1]);j++)
469 tabmut[l.rowind[
j]].lock();
481 stack[l.rowind[
j]*LEVELSTACK+nbstack[l.rowind[
j]]].
coeff
483 stack[l.rowind[
j]*LEVELSTACK+nbstack[l.rowind[
j]]].
p
485 stack[l.rowind[
j]*LEVELSTACK+nbstack[l.rowind[
j]]].
exceed
487 stack[l.rowind[
j]*LEVELSTACK+nbstack[l.rowind[
j]]].
sizeexceed
489 nbstack[l.rowind[
j]]++;
494 if(nbstack[l.rowind[j]]==LEVELSTACK)
497 vider_pile<component,workspace,mon,COEFF>
499 ,&tmpPk[l.rowind[
j]],compo.
exceed[l.rowind[
j]],
502 nbstack[l.rowind[
j]]=0;
506 listthread.push_back(std::thread(
507 wrap_vider_pile<component,workspace,mon,COEFF>,
508 stack+l.rowind[j]*LEVELSTACK,LEVELSTACK
509 ,&tmpPk[l.rowind[j]],std::ref(compo.
exceed[l.rowind[j]]),
511 nbstack+l.rowind[j],std::ref(tabmut[l.rowind[j]]),
515 for(
auto iterfuture=listthread.begin();
516 iterfuture!=listthread.end();iterfuture++)
518 listthread.erase(listthread.begin(),listthread.end());
527 tabmut[l.rowind[
j]].unlock();
534 tabmut[l.rowind[
j]].unlock();
548 for(
auto iterfuture=listthread.begin();
549 iterfuture!=listthread.end();iterfuture++)
551 listthread.erase(listthread.begin(),listthread.end());
559 cout<<
"apres SolveL"<<endl;
560 for(
int i=0;
i<tmpPk.size();
i++)
564 copy(compo.
poly[
i].nf,compo.
poly[
i].nf+compo.
poly[
i].size,ostream_iterator<coeff>(cout,
" "));
567 cout<<
"compo "<<compo.
poly[
i].ind<<endl;
574 template<
typename typmat ,
typename typPk,
typename mon,
typename typMk,
typename workspace,
580 ,typMk &tmpMk, workspace &w, typserv & serv)
583 int *Pr,*Pc,maxsize=0;
586 struct timeval t1,t2;
590 gettimeofday(&t1,NULL);
591 LUdecomp(S,&L,&U,&Pr,&Pc);
592 gettimeofday(&t2,NULL);
593 cout<<
"\e[32m Temps LU "<<t2.tv_sec-t1.tv_sec+1e-6*(t2.tv_usec-t1.tv_usec);
594 cout<<
"\e(B\e[m"<<endl;
602 copy(Pr,Pr+L.nrow,ostream_iterator<int>(cout,
" "));cout<<endl;
604 tmppr=(
int*)
malloc(
sizeof(
int)*L.nrow);
605 tmppc=(
int*)
malloc(
sizeof(
int)*L.nrow);
608 for(
int i=0;
i<compo.
poly.size();
i++)
610 tmpMk[
i]=compo.
poly[
i].ind;
611 tmpMk[
i].SetCoeff(1);
617 copy(Pr,Pr+L.nrow,tmppr);
618 Dopermu(compo.
poly,tmppr);
619 copy(Pr,Pr+L.nrow,tmppr);
620 Dopermu(compo.
exceed,tmppr);
621 copy(Pr,Pr+L.nrow,tmppr) ;
626 copy(Pc,Pc+S.ncol,tmppc);
628 Dopermu(tmpMk,tmppc);
635 auto tmpPk=compo.
poly;
637 cout<<
"avant SolveL"<<endl;
638 for(
int i=0;
i<tmpPk.size();
i++)
640 cout<<
"compo "<<compo.
poly[
i].ind<<endl;
643 copy(compo.
poly[
i].nf,compo.
poly[
i].nf+compo.
poly[
i].size,ostream_iterator<typename typPk::value_type::coeff_t>(cout,
" "));
645 cout<<invconv<Poly>(compo.
poly[
i],serv)<<endl;
646 cout<<
"----------------------------------------------"<<endl;
655 cout<<
"apres SolveLLL"<<endl;
656 for(
int i=0;
i<tmpPk.size();
i++)
658 cout<<
"l'ind "<<compo.
poly[
i].ind<<endl;
659 for(
int j=0;
j<S.ncol;
j++)
661 cout<<tmpMk[
j]*S(
i,
j)<<
"+ ";
664 cout<<invconv<Poly>(compo.
poly[
i],serv)<<endl;
669 gettimeofday(&t2,NULL);
670 cout<<
"\e[32m Temps RESTE "<<t2.tv_sec-t1.tv_sec+1e-6*(t2.tv_usec-t1.tv_usec);
671 cout<<
"\e(B\e[m"<<endl;
675 template<
typename typmat,
typename typMk,
typename component,
typename typserv>
681 typedef typename typMk::value_type::coeff_t coeff;
683 typename typMk::const_iterator itermon=verytmpMk.begin();
685 for(
auto iter_in_poly=compo.
poly.begin();
686 itermon!=verytmpMk.end();iter_in_poly++,itermon++,j++)
692 iter_in_poly->ind=*itermon;
693 iter_in_poly->ind.SetCoeff(1);
699 for(
int i=tmpmat.colptr[j];
i<tmpmat.colptr[j+1];
i++)
700 if(!(((coeff*)tmpmat.nzval)[
i]==0))
705 coeff tmpcoeff=((coeff*)tmpmat.nzval)[
i];
708 compo.
exceed[tmpmat.rowind[
i]]=(mon*)
709 MAC_REV_REALLOC<mon>(compo.
exceed[tmpmat.rowind[
i]],
711 (compo.
sizeexceed[tmpmat.rowind[
i]]+1)*
sizeof(mon));
716 iter_in_poly->ind=
mon(0);
722 #endif //ALREADY_Solvestack
void Solve(typmat &S, typmat &L, component< typPk, mon > &compo, int **pr, int **pc, typMk &tmpMk, workspace &w, typserv &serv)
Definition: Solvestacke2ter.hpp:578
Definition: workspace.hpp:11
Definition: pol2terspecial.hpp:36
void affdebug(const typmat &m)
Definition: io.hpp:30
C GetCoeff() const
Definition: Monom.hpp:67
mon * exceed
Definition: pol2terspecial.hpp:31
typPk_t poly
Definition: pol2terspecial.hpp:42
COEFF coeff
Definition: pol2terspecial.hpp:29
void SolveL(const harewell< coeff > &l, component &compo, workspace &w)
Definition: Solvestacke2ter.hpp:390
void(* tabfun1[32])(COEFF *, pol< mon, COEFF > *, int *)
Definition: auxfun.hpp:417
void inverse(int *&, int)
void reorder_ind(const typmat &tmpmat, const typMk &verytmpMk, component &compo, typserv &serv)
Definition: Solvestacke2ter.hpp:676
coeff * tabcoeff
Definition: workspace.hpp:12
T coeff_t
Definition: pol.hpp:9
void INIT_ELEM< stack_elem >(void *ptr, int size)
Definition: Solvestacke2ter.hpp:11
MSKconetypee MSKrealt MSKint32t MSKint32t j
Definition: mosek.h:2421
unsigned char * tabnf
Definition: workspace.hpp:13
void destroy_space(workspace< coeff > *w)
Definition: workspace.hpp:34
MSKint32t k
Definition: mosek.h:2713
R rep
Definition: Monom.hpp:30
int nbbits[256]
Definition: pol2ter.hpp:4
void SolveU(const harewell< coeff > &u, component &compo, workspace &w)
Definition: Solvestacke2ter.hpp:226
void(* tabfun2[32])(COEFF *, COEFF *, pol< mon, COEFF > *, int *)
Definition: auxfun.hpp:418
pol2ter< mon, COEFF > * p
Definition: pol2terspecial.hpp:30
Definition: pol2terspecial.hpp:27
vector< int > sizeexceed
Definition: pol2terspecial.hpp:44
R rep_t
Definition: Monom.hpp:27
void vider_pile(stack_elem *stack, int stacksize, pol< mon, T > *p, mon *&exceed_p, int &sizeexceed_p, workspace *w)
Definition: Solvestacke2ter.hpp:56
#define NUMBITS
Definition: Solvestacke2ter.hpp:5
Mon mon
Definition: solver_bb_floating.cpp:136
void increase_space(workspace< coeff > *w)
Definition: workspace.hpp:19
MSKint32t MSKint32t MSKint32t i
Definition: mosek.h:2278
int Iszero(const Scl< MPQ > &c)
Definition: Iszero.hpp:14
int sizenf
Definition: workspace.hpp:15
#define NBTHREAD
Definition: Solvestacke2ter.hpp:9
int size
Definition: pol.hpp:10
#define COEFF
Definition: symbo2.hpp:8
typPk::value_type pol
Definition: pol2terspecial.hpp:39
vector< mon * > exceed
Definition: pol2terspecial.hpp:43
#define MASKBIT
Definition: Solvestacke2ter.hpp:6
#define pol
Definition: pol2ter.hpp:3
int size
Definition: workspace.hpp:14
void SetCoeff(const C &c)
Definition: Monom.hpp:68
int sizeexceed
Definition: pol2terspecial.hpp:32
void CLEAR_ELEM< stack_elem >(void *ptr, int size)
Definition: Solvestacke2ter.hpp:22
Multivariate monomials.
Definition: Monom.hpp:21
T * nf
Definition: pol.hpp:12
#define LEVELSTACK
Definition: Solvestacke2ter.hpp:7