Borderbasix

Solvestacke2ter.hpp
Go to the documentation of this file.
1 #ifndef ALREADY_Solvestack
2 #define ALREADY_Solvestack
3 
4 //#include"auxfun3.hpp"
5 #define NUMBITS 8
6 #define MASKBIT 255
7 #define LEVELSTACK 40
8 //#define NBTHREAD 7
9 #define NBTHREAD 7
10 template<>
11 void INIT_ELEM<stack_elem>(void * ptr, int size)
12 {
13  int nbelem=size/sizeof(stack_elem);
14  for(int k=0;k<nbelem;k++)
15  {
16 
17  INIT_ELEM<COEFF>(&((stack_elem*)ptr)[k].coeff,sizeof(COEFF));
18  }
19 }
20 
21 template<>
22 void CLEAR_ELEM<stack_elem>(void * ptr, int size)
23 {
24  int nbelem=size/sizeof(stack_elem);
25  for(int k=0;k<nbelem;k++)
26  {
27 
28  CLEAR_ELEM<COEFF>(&((stack_elem*)ptr)[k].coeff,sizeof(COEFF));
29  }
30 }
31 #ifdef ASYNC2
32 template<typename compo, typename workspace, typename mon, typename T>
33 void vider_pile( stack_elem * stack, int stacksize,
34  pol<mon,T> *p, mon * &exceed_p, int &sizeexceed_p,workspace *w);
35 template<typename compo, typename workspace, typename mon, typename T>
36 void wrap_vider_pile( stack_elem * stack, int stacksize,
37  pol<mon,T> *p, mon * &exceed_p, int &sizeexceed_p,
38  // int * nbstack,recursive_mutex &mymutex, workspace *w)
39  int * nbstack,mutex &mymutex, workspace *w)
40 {
41  // workspace<COEFF> w;
42  // cout<<"je vide la pile "<<endl;
43  //w.sizenf=0;
44  //w.size=0;
45  //w.tabnf=NULL;
46  //w.tabcoeff=NULL;
47  vider_pile<compo,workspace,mon,T>(stack,stacksize,p,exceed_p
48  ,sizeexceed_p,w);
49  *nbstack=0;
50  mymutex.unlock();
51  //cout<<"j'ai vidé la pile "<<endl;
52 }
53 
54 #endif
55 template<typename compo, typename workspace, typename mon, typename T>
56 void vider_pile( stack_elem * stack, int stacksize,
57  pol<mon,T> *p, mon * &exceed_p, int &sizeexceed_p,workspace *w)
58 {
59  //le but de cette fonction est de realiser p-=la stack
60  //en respectant aussi les exceed
61  //TODO peut etre mettre les exceed sous forme de map (unoirdered cxx11)
62  //directement dans mult
63  typedef typename pol<mon,T>::coeff_t coeff_t;
64  typedef typename mon::rep_t rep_t;
65  map<rep_t,coeff_t> mapexceed;
66  int i,maxnfsize,j,compt,k;
67  unsigned long *tmpptr;
68  unsigned long mask=1;
69  // cout<<"ds vider pile pour "<<p->ind<<endl;
70  if (stacksize==0) return;
71  for(i=0;i<stacksize;i++)
72  for(;w->sizenf<stack[i].p->sizenf;increase_space(w));
73  for(;w->sizenf<p->sizenf;increase_space(w));
74  //
75  for(i=0;i<w->size;i++) w->tabcoeff[i]=0;
76  for(i=0;i<w->sizenf;i++) w->tabnf[i]=0;
77  //
78  compt=0;
79  tmpptr=(unsigned long *)p->nfind;
80  //#pragma omp parallel for shared(compt)
81  for(i=0;i<p->sizenf/sizeof(unsigned long);i++)
82  if(tmpptr[i])
83  {
84  ((unsigned long*)w->tabnf)[i]=tmpptr[i];
85  mask=tmpptr[i];
86  for(j=0;j<8*sizeof(unsigned long);j+=NUMBITS,mask>>=NUMBITS)
87  if(mask&MASKBIT)
88  {
89  tabfun1[mask&MASKBIT](w->tabcoeff+(8*sizeof(unsigned long)*i+j),p->nf+compt);
90  compt+=nbbits[mask&MASKBIT];
91  }
92  }
93  //au tour des exceed
94  for(i=0;i<sizeexceed_p;i++)
95  mapexceed[exceed_p[i].rep]=exceed_p[i].GetCoeff();
96  //
97  for(i=p->sizenf-(p->sizenf % sizeof(unsigned long));i<p->sizenf;i++)
98  // for(i=0;i<p->sizenf;i++)
99  if(p->nfind[i])
100  {
101  w->tabnf[i]=p->nfind[i];
102  tabfun1[w->tabnf[i]](w->tabcoeff+(8*i),p->nf+compt);
103  compt+=nbbits[p->nfind[i]];
104  }
105  // cout<<"stacksize "<<stacksize<<endl;
106  for(k=0;k<stacksize;k++)
107  {
108  compt=0;
109  pol<mon,T> *tmpp=stack[k].p;
110  T tmpcoeff=stack[k].coeff;
111  // cout<<"tmpcoeff "<<tmpcoeff<<endl;
112  tmpptr=(unsigned long*)tmpp->nfind;
113  //ici race condition omp sur comp
114  //#pragma omp parallel for shared(compt)
115  for(i=0;i<tmpp->sizenf/sizeof(unsigned long);i++)
116  if(tmpptr[i])
117  {
118  ((unsigned long*)w->tabnf)[i]|=tmpptr[i];
119  mask=tmpptr[i];
120  for(j=0;j<8*sizeof(unsigned long);j+=NUMBITS,mask>>=NUMBITS)
121  {
122  if(mask&MASKBIT)
123  {
124  tabfun2[mask&MASKBIT]
125  (w->tabcoeff+(8*sizeof(unsigned long)*i+j),
126  &tmpcoeff,tmpp->nf+compt);
127  compt+=nbbits[mask&MASKBIT];
128  }
129 #if 0
130  for(int k=0;k<8;k++)
131  if(Iszero(w->tabcoeff[8*i*sizeof(unsigned long)+j+k]))
132  ((unsigned long*)w->tabnf)[i]&=~(1<<(j+k));//mask;
133 #endif
134  }
135  }
136  for(i=tmpp->sizenf-(tmpp->sizenf%sizeof(unsigned long));i<tmpp->sizenf;i++)
137  if(tmpp->nfind[i])
138  {
139  w->tabnf[i]|=tmpp->nfind[i];
140  mask=1;
141  for(j=0;j<8;j++,mask<<=1)
142  {
143  if(tmpp->nfind[i]&mask)
144  {
145  // cout<<"coeff dans w avant "<<w->tabcoeff[8*i+j]<<endl;
146  // cout<<"tmpcoeff "<<tmpcoeff<<endl;
147  // cout<<"tmpp->nf[compt]; "<<tmpp->nf[compt]<<endl;
148  w->tabcoeff[8*i+j]-=tmpcoeff*tmpp->nf[compt++];
149  //cout<<"coeff dans w apres "<<w->tabcoeff[8*i+j]<<endl;
150  }
151  //if(Iszero(w->tabcoeff[8*i+j]))
152  // w->tabnf[i]&=~mask;
153  }
154  }
155  //
156  //ici on fait la meme operation sur les exceed!
157  //
158  //a voir//
159  //
160  // cout<<"k ici "<<k<<" stack[k].sizeexceed "<<stack[k].sizeexceed<<endl;
161  for(int i=0;i<stack[k].sizeexceed;i++)
162  {
163  // cout<<"stack[k].exceed[i].rep "<<stack[k].exceed[i].rep<<" "<<stack[k].exceed[i].GetCoeff()<<" tmpcoeff "<<tmpcoeff<<endl;
164  mapexceed[stack[k].exceed[i].rep]-=stack[k].exceed[i].GetCoeff()*tmpcoeff;
165  }
166  }
167  compt=0;j=-1;
168  for(i=0;i<w->sizenf;i++)
169  if(w->tabnf[i])
170  {
171  for(int k=0;k<8;k++)
172  if(Iszero(w->tabcoeff[8*i+k]))
173  w->tabnf[i]&=~(1<<k);
174  if(w->tabnf[i])
175  {
176  j=i;
177  compt+=nbbits[w->tabnf[i]];
178  }
179  }
180  // cout<<" ici la size "<<compt<<endl;
181  p->nf=(T*)MAC_REV_REALLOC<T>(p->nf,p->size*sizeof(T),
182  compt*sizeof(T));
183  p->size=compt;
184  p->nfind=(unsigned char*)realloc(p->nfind,j+1);
185  p->sizenf=j+1;
186  compt=0;
187  for(i=0;i<=j;i++)
188  {
189 
190  p->nfind[i]=w->tabnf[i];
191  w->tabnf[i]=0;
192  if(p->nfind[i])
193  {
194  unsigned char mask=1;
195  for(k=0;k<8;k++,mask<<=1)
196  {
197  if(p->nfind[i]&mask)
198  {
199  p->nf[compt++]=w->tabcoeff[8*i+k];
200  w->tabcoeff[8*i+k]=0;
201  }
202  }
203  }
204  }
205  //
206  //Il reste a reconstruire un exceed à partir de la mapexceed
207  //
208 #ifdef DEBUG
209  {
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)<<" ---- ";
214  cout<<endl;
215  }
216 #endif
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();
223 }
224 
225 template<typename coeff, typename workspace, typename component>
226 void SolveU(const harewell<coeff> & u, component &compo, workspace &w)
227 {
228  // typedef list<pol<mon,COEFF> > typPk;
229  // typedef pol<mon,COEFF> elem_typ;
230  typedef typename component::pol pol;
231  int t;
232  const int taille=compo.poly.size();
233  auto &tmpPk=compo.poly;//c le vecteur des polynomes de la component
234  stack_elem *stack=(stack_elem*)MAC_REV_MALLOC<stack_elem>
235  (LEVELSTACK*(taille+1)*sizeof(stack_elem));
236  int *nbstack=(int*)malloc((taille+1)*sizeof(int));
237 #ifdef ASYNC2
238  list<std::thread > listthread;
239  mutex *tabmut=new mutex[taille];
240  vector<workspace> vw(taille);
241  for(auto w :vw)
242  {
243  w.sizenf=0;
244  w.size=0;
245  w.tabnf=NULL;
246  w.tabcoeff=NULL;
247  }
248 #endif
249  cout<<"ds solveU"<<endl;
250  for(int i=0;i<taille;i++)
251  nbstack[i]=0;
252 
253  //copy(tmpPk.begin(),Pk.begin(),Pk.end());
254  // for(typPk::iterator iter=Pk.begin();iter!=Pk.end();iter++)
255  // tmpPk.push_back(*iter);
256  //Pk.erase(Pk.begin(),Pk.end());
257  //cout<<"u.ncol "<<u.ncol<<" u.nrow "<<u.nrow<<endl;
258  for(int i=u.ncol-1;i>=0;i--)
259  {
260  coeff mult_coeff=(coeff)1;
261  int j;
262  //
263 #ifdef ASYNC2
264  tabmut[i].lock();
265 #endif
266  vider_pile<component,workspace,mon,COEFF>
267  (stack+i*LEVELSTACK,nbstack[i],&(tmpPk[i]),compo.exceed[i],
268  compo.sizeexceed[i],&w);
269 
270 #ifdef ASYNC2
271  tabmut[i].unlock();
272 #endif
273  //
274  nbstack[i]=0;
275  for (j=((i==(u.ncol-1))?(u.nnz-1):(u.colptr[i+1]-1))
276  ;(j>=(u.colptr)[i]);j--)
277  if (i==u.rowind[j])
278  {
279  mult_coeff=((COEFF*)u.nzval)[j];
280  break;
281  }
282  if(Iszero(mult_coeff)) continue;
283  mult_coeff=((coeff)1)/mult_coeff;
284  tmpPk[i]*mult_coeff;
285  //on reporte aussi sur l'exceed les modifs
286  for(j=0;j<compo.sizeexceed[i];j++)
287  compo.exceed[i][j]*=mult_coeff;
288  //fin du report
289  for (j=((i==(u.ncol-1))?(u.nnz-1):(u.colptr[i+1]-1))
290  ;(j>=(u.colptr)[i]);j--)
291  {
292  if (i!=u.rowind[j])//t==j
293  {
294 #ifdef ASYNC2
295  tabmut[u.rowind[j]].lock();
296 #endif
297 
298  if(((COEFF*)u.nzval)[j]!=(coeff)0)
299  {
300  stack[u.rowind[j]*LEVELSTACK+nbstack[u.rowind[j]]].coeff
301  =((COEFF*)u.nzval)[j];
302  stack[u.rowind[j]*LEVELSTACK+nbstack[u.rowind[j]]].p
303  =&tmpPk[i];
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=
306  compo.sizeexceed[i];
307  nbstack[u.rowind[j]]++;
308  if(nbstack[u.rowind[j]]==LEVELSTACK)
309  {
310 #ifndef ASYNC2
311  vider_pile<component,workspace,mon,COEFF>
312  (stack+u.rowind[j]*LEVELSTACK,LEVELSTACK
313  ,&tmpPk[u.rowind[j]],compo.exceed[u.rowind[j]],
314  compo.sizeexceed[u.rowind[j]],&w);
315 
316  // ,&tmpPk[u.rowind[j]],compo.exceed[u.rowind[i]],
317  // compo.sizeexceed[u.rowind[i]],&w);
318  nbstack[u.rowind[j]]=0;
319 #else
320  // tabmut[u.rowind[j]].lock();//on lock le mutex ici
321  //et c le thread qui delockera qd il aura fini
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]]),
326  std::ref(compo.sizeexceed[u.rowind[j]]),
327  nbstack+u.rowind[j],
328  std::ref(tabmut[u.rowind[j]]),&vw[u.rowind[j]]));
329  if(listthread.size()==NBTHREAD)
330  {
331  for(auto iterfuture=listthread.begin();
332  iterfuture!=listthread.end();iterfuture++)
333  iterfuture->join();
334  listthread.erase(listthread.begin(),listthread.end());
335  }
336 #endif
337  }
338 #ifdef ASYNC2
339  else
340  {
341  tabmut[u.rowind[j]].unlock();
342  }
343 #endif
344  }
345 #ifdef ASYNC2
346  else
347  {
348  tabmut[u.rowind[j]].unlock();
349  }
350 #endif
351 
352 
353  }
354  }
355  }
356 #ifdef ASYNC2
357 for(auto iterfuture=listthread.begin();
358  iterfuture!=listthread.end();iterfuture++)
359  iterfuture->join();
360  listthread.erase(listthread.begin(),listthread.end());
361  for(auto w : vw)
362  destroy_space(&w);
363 #endif
364  // for(int i=0;i<u.ncol;i++)
365  // cout<<"u nbstack "<<i<<" "<<nbstack[i]<<endl;
366 #ifdef PASCOMPRIS
367  typename list<pol >::iterator iterPk=Pk.begin();
368  for(typename vector<pol >::iterator iter=tmpPk.begin()
369  ;iter!=tmpPk.end();iter++)
370  Pk.push_back(*iter);
371 #endif
372  MAC_REV_FREE<stack_elem>(stack,(LEVELSTACK*taille*sizeof(stack_elem)));
373  free(nbstack);
374 #ifdef DEBUG
375  cout<<"apres SolveU"<<endl;
376  for(int i=0;i<tmpPk.size();i++)
377  {
378  cout<<"compo.sizeexceed[i]<<endl; "<<compo.sizeexceed[i]<<endl;
379  copy(compo.exceed[i],compo.exceed[i]+compo.sizeexceed[i],ostream_iterator<mon>(cout," "));
380  cout<<endl;
381  copy(compo.poly[i].nf,compo.poly[i].nf+compo.poly[i].size,ostream_iterator<coeff>(cout," "));
382  cout<<endl;
383  cout<<"compo "<<compo.poly[i].ind<<endl;
384  }
385 #endif
386  //return Pk;
387 }
388 
389 template<typename workspace, typename component, typename coeff>
390 void SolveL(const harewell<coeff> & l, component &compo, workspace &w)
391 //list<pol<mon,COEFF> >& SolveL(const harewell<COEFF> &l
392 // ,list<pol<mon,COEFF> > &Pk
393 // ,workspace &w)
394 {
395  // typedef list<pol<mon,COEFF> > typPk;
396  //typedef pol<mon,COEFF> elem_typ;
397  //vector<pol<mon,COEFF> > tmpPk;
398 
399  typedef typename component::pol pol_t;
400  int t;
401  const int taille=l.nrow;//compo.poly.size();
402  auto &tmpPk=compo.poly;//c le vecteur des polynomes de la component
403 
404  stack_elem *stack=(stack_elem*)MAC_REV_MALLOC<stack_elem>
405  (LEVELSTACK*(taille)*sizeof(stack_elem));
406  int *nbstack=(int*)malloc((taille)*sizeof(int));
407 #ifdef ASYNC2
408  list<std::thread > listthread;
409  mutex *tabmut=new mutex[taille];
410  vector<workspace> vw(taille);
411  for(auto w :vw)
412  {
413  w.sizenf=0;
414  w.size=0;
415  w.tabnf=NULL;
416  w.tabcoeff=NULL;
417  }
418 
419 #endif
420 
421  for(int i=0;i<taille;i++)
422  nbstack[i]=0;
423 
424 #ifdef DEBUG
425 cout<<"avant SolveL"<<endl;
426  for(int i=0;i<tmpPk.size();i++)
427  {
428  cout<<"compo "<<compo.poly[i].ind<<endl;
429  copy(compo.exceed[i],compo.exceed[i]+compo.sizeexceed[i],ostream_iterator<mon>(cout," "));
430  copy(compo.poly[i].nf,compo.poly[i].nf+compo.poly[i].size,ostream_iterator<mon>(cout," "));
431  cout<<endl;
432 
433  }
434 #endif
435  //ALGO A REVOIR
436 
437  // for(typPk::iterator iter=Pk.begin();iter!=Pk.end();iter++)
438  // tmpPk.push_back(*iter);
439  // Pk.erase(Pk.begin(),Pk.end());
440  // cout<<"l.ncol "<<l.ncol<<" l.nrow "<<l.nrow<<endl;
441  // auto itertmppk=tmpPk.begin();
442  for(int i=0;i<l.ncol;i++)
443  {
444  int j=l.colptr[i];
445 #ifdef DEBUG
446  cout<<"vider pile"<<endl;
447  copy(compo.exceed[i],compo.exceed[i]+compo.sizeexceed[i],ostream_iterator<mon>(cout," "));
448  cout<<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," --- "));
451 #endif
452 #ifdef ASYNC2
453  tabmut[i].lock();
454 #endif
455 
456  vider_pile<component,workspace,mon,COEFF>
457  (stack+i*LEVELSTACK,nbstack[i],&(tmpPk[i]),compo.exceed[i],
458  compo.sizeexceed[i],&w);
459 #ifdef ASYNC2
460  tabmut[i].unlock();
461 #endif
462 
463  nbstack[i]=0;
464  for (;(j<l.nnz)&&(j<(l.colptr)[i+1]);j++)
465  {
466  if (i!=l.rowind[j])
467  {
468 #ifdef ASYNC2
469  tabmut[l.rowind[j]].lock();
470 #endif
471 
472  if((((COEFF*)l.nzval)[j])!=(COEFF)0)
473  {
474  //avant#ifdef ASYNC2
475  // tabmut[l.rowind[j]].lock();
476  //#endif
477 
478  // cout<<"L:rowind "<<l.rowind[j]<<endl;
479  // cout<<"nbstack "<<nbstack[l.rowind[j]]<<endl;
480  //cout<<"taille*LEVELSTACK "<<taille*LEVELSTACK<<endl;
481  stack[l.rowind[j]*LEVELSTACK+nbstack[l.rowind[j]]].coeff
482  =((COEFF*)l.nzval)[j];
483  stack[l.rowind[j]*LEVELSTACK+nbstack[l.rowind[j]]].p
484  =&(tmpPk[i]);
485  stack[l.rowind[j]*LEVELSTACK+nbstack[l.rowind[j]]].exceed
486  =compo.exceed[i];
487  stack[l.rowind[j]*LEVELSTACK+nbstack[l.rowind[j]]].sizeexceed
488  =compo.sizeexceed[i];
489  nbstack[l.rowind[j]]++;
490  //AVANT #ifdef ASYNC2
491  //avnat tabmut[l.rowind[j]].unlock();
492  //avant#endif
493  //cout<<"nbstack ici"<<nbstack[l.rowind[j]]<<endl;
494  if(nbstack[l.rowind[j]]==LEVELSTACK)
495  {
496 #ifndef ASYNC2
497  vider_pile<component,workspace,mon,COEFF>
498  (stack+l.rowind[j]*LEVELSTACK,LEVELSTACK
499  ,&tmpPk[l.rowind[j]],compo.exceed[l.rowind[j]],
500  compo.sizeexceed[l.rowind[j]],&w);
501  //ICI ON A BESOIN de l'acces
502  nbstack[l.rowind[j]]=0;
503 #else
504  //cout<<"je declenche une vidange"<<endl;
505  //tabmut[l.rowind[j]].lock();//on lock le mutex tout de suite
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]]),
510  std::ref(compo.sizeexceed[l.rowind[j]]),
511  nbstack+l.rowind[j],std::ref(tabmut[l.rowind[j]]),
512  &vw[l.rowind[j]]));
513  if(listthread.size()==NBTHREAD)
514  {
515  for(auto iterfuture=listthread.begin();
516  iterfuture!=listthread.end();iterfuture++)
517  iterfuture->join();
518  listthread.erase(listthread.begin(),listthread.end());
519  }
520 #endif
521 
522 
523  }
524 #ifdef ASYNC2
525  else//on est non nul et on vide pas la pile
526  {
527  tabmut[l.rowind[j]].unlock();
528  }
529 #endif
530  }
531 #ifdef ASYNC2
532  else//coeffciient nul
533  {
534  tabmut[l.rowind[j]].unlock();
535  }
536 #endif
537  }
538  }
539  }
540  // for(int i=0;i<l.ncol;i++)
541  // cout<<"nbstack "<<i<<" "<<nbstack[i]<<endl;
542  //vider_pile(stack+i*LEVELSTACK,nbstack[i],&tmpPk[i],&w);
543  // list<pol<mon, COEFF> >::iterator iterPk=Pk.begin();
544  //for(vector<pol<mon , COEFF> >::iterator iter=tmpPk.begin()
545  // ;iter!=tmpPk.end();iter++,iterPk++)
546  // Pk.push_back(*iter);
547 #ifdef ASYNC2
548 for(auto iterfuture=listthread.begin();
549  iterfuture!=listthread.end();iterfuture++)
550  iterfuture->join();
551  listthread.erase(listthread.begin(),listthread.end());
552  for(auto &w : vw)
553  destroy_space(&w);
554 #endif
555 
556  MAC_REV_FREE<stack_elem>(stack,(LEVELSTACK*taille*sizeof(stack_elem)));
557  free(nbstack);
558 #ifdef DEBUG
559 cout<<"apres SolveL"<<endl;
560  for(int i=0;i<tmpPk.size();i++)
561  {
562  copy(compo.exceed[i],compo.exceed[i]+compo.sizeexceed[i],ostream_iterator<mon>(cout," "));
563  cout<<endl;
564  copy(compo.poly[i].nf,compo.poly[i].nf+compo.poly[i].size,ostream_iterator<coeff>(cout," "));
565  cout<<endl;
566 
567  cout<<"compo "<<compo.poly[i].ind<<endl;
568  }
569 #endif
570  //return Pk;
571 }
572 
573 
574 template<typename typmat ,typename typPk, typename mon, typename typMk, typename workspace,
575 typename typserv>
576 //typserv a virer ne sert que pour le debug
577 void
578 Solve(typmat &S, typmat &L,
579  component<typPk,mon> &compo,int **pr,int **pc
580  ,typMk &tmpMk, workspace &w, typserv & serv)
581 {
582  typmat U;
583  int *Pr,*Pc,maxsize=0;
584  int *tmppr;
585  int *tmppc;
586  struct timeval t1,t2;
587  //#ifdef DEBUG
588  // vector<mon> tmpMk(compo.poly.size());
589  //#endif
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;
595  t1=t2;
596 #if 0
597  cout<<"L"<<endl;
598 affdebug(L);
599  cout<<"R"<<endl;
600  affdebug(S);
601 cout<<"PR "<<endl;
602  copy(Pr,Pr+L.nrow,ostream_iterator<int>(cout," "));cout<<endl;
603 #endif
604  tmppr=(int*)malloc(sizeof(int)*L.nrow);
605  tmppc=(int*)malloc(sizeof(int)*L.nrow);
606 
607 #if 0
608 for(int i=0; i<compo.poly.size();i++)
609  {
610  tmpMk[i]=compo.poly[i].ind;
611  tmpMk[i].SetCoeff(1);
612  }
613 #endif
614 
615 
616  inverse(Pr,L.nrow);
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) ;
622  Dopermu(compo.sizeexceed,tmppr);
623  free(tmppr);
624 
625 
626  copy(Pc,Pc+S.ncol,tmppc);
627  inverse(tmppc,S.ncol);
628  Dopermu(tmpMk,tmppc);
629 
630  free(tmppc);
631 
632 
633 
634 
635  auto tmpPk=compo.poly;
636 #ifdef DEBUG
637  cout<<"avant SolveL"<<endl;
638  for(int i=0;i<tmpPk.size();i++)
639  {
640  cout<<"compo "<<compo.poly[i].ind<<endl;
641  copy(compo.exceed[i],compo.exceed[i]+compo.sizeexceed[i],ostream_iterator<mon>(cout," "));
642  cout<<endl;
643  copy(compo.poly[i].nf,compo.poly[i].nf+compo.poly[i].size,ostream_iterator<typename typPk::value_type::coeff_t>(cout," "));
644  cout<<endl;
645  cout<<invconv<Poly>(compo.poly[i],serv)<<endl;
646  cout<<"----------------------------------------------"<<endl;
647  }
648 #endif
649  SolveL(L,compo,w);
650  //
651  reorder_ind(S,tmpMk,compo,serv);
652  //
653 
654 #ifdef DEBUG
655 cout<<"apres SolveLLL"<<endl;
656  for(int i=0;i<tmpPk.size();i++)
657  {
658  cout<<"l'ind "<<compo.poly[i].ind<<endl;
659  for(int j=0;j<S.ncol;j++)
660  if(S(i,j)!=0)
661  cout<<tmpMk[j]*S(i,j)<<"+ ";
662  copy(compo.exceed[i],compo.exceed[i]+compo.sizeexceed[i],ostream_iterator<mon>(cout," "));
663  cout<<endl;
664  cout<<invconv<Poly>(compo.poly[i],serv)<<endl;
665  }
666 #endif
667  SolveU(S,compo,w);//SolveU(S,TildePk);
668  *pc=Pc;*pr=Pr;
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;
672  t1=t2;
673 }
674 
675 template<typename typmat, typename typMk, typename component, typename typserv>
676 void reorder_ind(const typmat &tmpmat, const typMk &verytmpMk, component &compo, typserv &serv)
677 {
678  //ici on remet les ind a la bonne valeur
679  //on s'occuppe aussi de rajouter en exceed les monomes des colonnes nulles
680  //on suppose verytmpMk deja permute par Pc
681  typedef typename typMk::value_type::coeff_t coeff;
682  int j=0;
683  typename typMk::const_iterator itermon=verytmpMk.begin();
684 
685  for(auto iter_in_poly=compo.poly.begin();
686  itermon!=verytmpMk.end();iter_in_poly++,itermon++,j++)
687  {
688  // cout<<" dans verytmp "<<*itermon<<
689  // invconv<Poly>(*iter_in_poly,serv)<<endl;
690  if(!Iszero(tmpmat(j,j)))
691  {
692  iter_in_poly->ind=*itermon;
693  iter_in_poly->ind.SetCoeff(1);
694  }
695  else
696  {
697  //On rajoute aux exceed des autre polyn\çomes de la composante les
698  //les monomes correspondant a cette colonne
699  for(int i=tmpmat.colptr[j];i<tmpmat.colptr[j+1];i++)
700  if(!(((coeff*)tmpmat.nzval)[i]==0))
701  {
702  //il y a eu permutation des colonnes il
703  // faut donc se fier a itermon plutot qu'aux ind
704  mon tmpmon=*itermon;
705  coeff tmpcoeff=((coeff*)tmpmat.nzval)[i];
706 
707  tmpmon.SetCoeff(tmpcoeff);
708  compo.exceed[tmpmat.rowind[i]]=(mon*)
709  MAC_REV_REALLOC<mon>(compo.exceed[tmpmat.rowind[i]],
710  compo.sizeexceed[tmpmat.rowind[i]]*sizeof(mon),
711  (compo.sizeexceed[tmpmat.rowind[i]]+1)*sizeof(mon));
712 
713  compo.exceed[tmpmat.rowind[i]][compo.sizeexceed[tmpmat.rowind[i]]]=tmpmon;
714  compo.sizeexceed[tmpmat.rowind[i]]++;
715  }
716  iter_in_poly->ind=mon(0);
717 
718  }
719  }
720 }
721 
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
void free(void *)
C GetCoeff() const
Definition: Monom.hpp:67
Definition: pol.hpp:6
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 * malloc(YYSIZE_T)
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
Home  |  Download & InstallContributions