Borderbasix

pol2terspecial-async.hpp
Go to the documentation of this file.
1 #ifdef ASYNC
2 template<typename typlistplus, typename Base>
3 void compute_ancestors(typlistplus &listplus, Base & b)
4 {
5  //
6  //
7  //cet algo repose sur le fait que les composantes sont placées dans l'ordre d'inclusion
8  // on a pas de petite composante avant une plus grosse
9  //a changer par la suite
10  //
11  //
12  typedef typename typlistplus::value_type::monom_t mon;
13  for (auto &tmpresmul : listplus)
14  {
15  // typename typlistplus::value_type tmpresmul=iter.get();
16  mon tmp=tmpresmul.poly.ind;
17 
18  //Pour etre ancetre il faut diviser
19  //et etre dans la meme composante de B
20  mon *candidate_ancestor=NULL;
21  tmp.SetCoeff(1);
22  for(auto &iterbase : b)
23  {
24  mon *compancestor=NULL;
25  int isincomponent=0;
26  for(int i=0;i<iterbase.taille1;i++)
27  if(isdivisible(iterbase.accept[i],tmp,b))
28  {
29  isincomponent=1;
30 #ifdef DEBUG
31  cout<<"je break ici"<<endl;
32 #endif
33  break;//pas la peine d'aller plus loin on est dans la composante
34  }
35  if(isincomponent)//sinon ca sert a rien
36  {
37  for(int i=0;i<iterbase.taille2;i++)
38  if(isdivisible(iterbase.refuse[i],tmp,b))
39  {
40  if(compancestor)//on a deux monomomes qui divisent
41  {
42  candidate_ancestor=NULL;
43 #ifdef DEBUG
44  cout<<"je break ici"<<endl;
45 #endif
46  break;//pas la peine d'aller plus loin
47  }
48  else
49  {
50 #ifdef DEBUG
51  cout<<"g trouvé ici un gus "<<iterbase.refuse[i]<<endl;
52 #endif
53  compancestor=&iterbase.refuse[i];
54  }
55  }
56  }
57  if(compancestor)
58  {
59 #ifdef DEBUG
60  cout<<"je passe ici compancestor non null"<<endl;
61 #endif
62  candidate_ancestor=compancestor;
63  }
64  }
65  tmpresmul.poly.ancestor=candidate_ancestor;
66  // listplus.push_back(tmpresmul);
67  }
68 #ifdef DEBUG
69  for(auto &&iter : listplus)
70  {
71  cout<<"ancestor ---- "<<iter->poly.ind<<endl;
72  if (iter.ancestor)
73  cout<<"\t\t -> "<<*(iter->poly.ancestor)<<endl;
74  else
75  cout<<"\e[31mcaca\e(B\e[m"<<endl;
76  }
77 #endif
78 }
79 
80 template<typename typgraph, typename typlistplus,
81  typename typmon2face, typename Base>
82 void makegraph(typgraph & G, const typlistplus & list_plus,
83  typmon2face &mon2face,
84  Base &b)
85 {
86  //on commence par numeroter les faces
87  //Et on associe les ind et leur face
88  //->>>>>>>>>>>>>on utilise une map
89  typedef typename typlistplus::value_type::monom_t mon;
90  // typedef typename typPk::value_type::order_t ord;
91  typedef my_Dlex<mon> ord;
92  int numface=0;
93  map<typename mon::rep_t,int> root2face;//associee le monome ancetre à sa face
94  //map<typename mon::rep_t,int> mon2face;//associe l'ind a sa face
95  //le root c'est un monome pres de l'ancetre
96  //qui represente l'ind sur la face
97  for(auto iterlist=list_plus.begin();iterlist!=list_plus.end();iterlist++)
98  {
99  typename typlistplus::value_type::pol poly=iterlist->poly;
100  mon root=*(poly.ancestor);
101  int count=0;
102  for(int i=0;i<b.nbvars;i++)
103  if(poly.ind.GetDegree(i)>root.GetDegree(i))
104  {
105  root*=mon(i,1);
106  count++;
107  }
108  //ICI il faut repasser pour s'assurer que le root a bien exactement
109  // nvars-1 position augmentées par rapport a l'ancetre
110  //en cas de multiappartenance on choisi celle qui est la plus petite
111  //dans l'ordre lexico (la multiappartenance c qd l'ind est sur une
112  //intersefction de deux faces
113  for(int i=0;(count<(b.nbvars-1)) && (i<b.nbvars);i++)
114  if(poly.ancestor->GetDegree(i)==root.GetDegree(i))
115  {
116  root*=mon(i,1);
117  count++;
118  }
119  if(root2face.count(root.rep)==0)
120  root2face[root.rep]=numface++;
121  mon2face[poly.ind.rep]=root2face[root.rep];
122  }
123 #ifdef DEBUG
124  cout<<"roottoface"<<endl;
125  for(auto &i :root2face)
126  cout<<i.first<<" --- "<<i.second<<endl;
127  cout<<"mon2face"<<endl;
128  for(auto &i :mon2face)
129  cout<<i.first<<" --- "<<i.second<<endl;
130 #endif
131  //on allour le graph
132  G.resize(numface);
133  for(auto &i : G)
134  {
135  i.resize(numface);
136  for(auto &j :i)
137  j=0;
138  }
139  //Ensuite on construit le graph
140 
141  for(auto iterlist=list_plus.begin();iterlist!=list_plus.end();iterlist++)
142  {
143 // cout<<"ici on traite "<<iterpk->ind<<endl;
144  for(int i=0;i<iterlist->sizeexceed;i++)
145  G[mon2face[iterlist->poly.ind.rep]][mon2face[iterlist->exceed[i].rep]]=1;
146  // On considere le graph dense
147  }
148 
149 }
150 namespace pol2terasync{
151 mutex synchromutex;
152 int flag=1;
153 mutex tmpmutex;
154 }
155 
156 template <typename typdump,typename Base,typename mon, typename monomial_server>
157 void wrap_mult(resmul<pol<mon,COEFF> > &res, int i,const pol<mon, COEFF> &p,
158  const typdump &dump, const Base &b, monomial_server &serv)
159 {
160  pol2terasync::synchromutex.lock();
161  // cout<<"je suis parti"<<endl;
162  res=mult(i,p,dump,b,serv);
163  //cout<<"g fini"<<endl;
164  pol2terasync::synchromutex.unlock();
165 }
166 
167 template<typename typdump,typename Base,typename mon, typename monomial_server>
169  mult(int i,const pol<mon, COEFF> &p,const typdump &dump,
170  const Base &b, monomial_server &serv)
171 {
172  static const mon monzero=mon(0);
173  typedef typename mon::coeff_t coeff;
174  static const COEFF zero=0;
175  // static int flag=1;
177  resmul<pol<mon,COEFF> > res;//ICI IL FAUT METTRE LES CHAMPS ET RETOURNER RET
178  res.exceed=(mon*)MAC_REV_MALLOC<mon>((p.size+1)*sizeof(mon));
179  int *stockindicetab=(int*)malloc(p.size*sizeof(int));
180  int noquo=0,maxind=0,pp=0,q=0,compt_coeff=0;
181  int comptsize=0;
182  COEFF *tmpspace;
183  w.sizenf=0;
184  pol2terasync::tmpmutex.lock();
186  {
188  init_pointer<COEFF>();
189  //flag=0;cout<<"pouet pouet"<<endl;
190  }
191  pol2terasync::tmpmutex.unlock();
192  //ici on determine l'espace de travail necessaire pour la suite;
193  //tmpmutex.lock();
194  for(int j=0;j<p.sizenf;++j)
195  if (p.nfind[j])
196  {
197 
198  for(int k=0;k<8;k++)
199  if(((p.nfind[j]>>k)&1))
200  {
201 #ifdef REENTRANT
202  int stockindice2=serv.mulind_th(8*j+k,i,b);
203 #else
204  int stockindice2=serv.mulind(8*j+k,i,b);
205 #endif
206  //pour affichage
207 
208  cout<<"stockindice2 "<<8*j+k<<" "<<i<<" "<<stockindice2<<endl;
209  cout<<"i "<<i<<" j "<<j<<" k "<<k<<endl;
210  //pour affichage
211  if(stockindice2<0)
212  stockindice2=-1*(8*j+k)-1;
213  stockindicetab[pp++]=stockindice2;
214  if (stockindice2>=maxind)
215  maxind=stockindice2;
216  }
217  }
218 
219  //for(;maxind/8+1>=w.sizenf;increase_space(&w));
220  w.sizenf=maxind/8+1;
221  w.tabnf=(unsigned char*)malloc(maxind/8+1);
222  w.size=8*w.sizenf;
223  // cout<<"w.size() "<<w.size<<endl;
224  w.tabcoeff=(coeff*)MAC_REV_MALLOC<coeff>(w.size*sizeof(coeff));
225  for(int i=0;i<w.sizenf;i++)
226  w.tabnf[i]=0;
227  for(int i=0;i<w.size;i++)
228  w.tabcoeff[i]=0;
229 
230  for(int j=0;j<pp;j++)
231  if(stockindicetab[j]>=0)
232  {
233  w.tabcoeff[stockindicetab[j]]+=p.nf[j];
234  if(!Iszero(w.tabcoeff[stockindicetab[j]]))
235  w.tabnf[stockindicetab[j]/8]|=1<<(stockindicetab[j]%8);
236  }
237  else
238  {
239  pol<mon,COEFF> tmp;
240 #ifdef REENTRANT
241  tmp=serv.nf_th(i,-1*(stockindicetab[j]+1),dump,b);
242 #else
243  tmp=serv.nf(i,-1*(stockindicetab[j]+1),dump,b);
244 #endif
245  if (tmp.size!=-1)
246  {
247  int compteurtmp=0;
248  //On fait un plus dense dans tmpspace
249  int k,l;
250  unsigned long *tmpptr=(unsigned long*)tmp.nfind;
251  unsigned long mask=1;
252  for(;tmp.sizenf>=w.sizenf;increase_space(&w));
253 
254  for(k=0;k<tmp.sizenf/sizeof(unsigned long);k++)
255  if(tmpptr[k])
256  {
257  mask=tmpptr[k];
258  ((unsigned long*)w.tabnf)[k]|=mask;
259  for(l=0;l<8*sizeof(unsigned long);l+=8,mask>>=8)
260  {
261  if(mask&255)
262  {
263  tabfun2[mask&255](
264  w.tabcoeff+(8*sizeof(unsigned long)*k+l)
265  ,&(p.nf[j]),tmp.nf+compteurtmp);
266  compteurtmp+=nbbits[mask&255];
267  }
268  }
269  }
270 
271  for(k=tmp.sizenf-(tmp.sizenf%sizeof(unsigned long))
272  ;k<tmp.sizenf;k++)
273  if(tmp.nfind[k])
274  {
275  w.tabnf[k]|=tmp.nfind[k];
276  mask=1;
277  for(l=0;l<8;l++,mask<<=1)
278  {
279  if(tmp.nfind[k]&mask)
280  w.tabcoeff[8*k+l]-=p.nf[j]*tmp.nf[compteurtmp++];
281  if(Iszero(w.tabcoeff[8*k+l]))
282  w.tabnf[k]&=~mask;
283 
284  }
285  }
286  }
287  else
288  {
289  //On est tombé sur un monome du degre courant
290  //qui est sur le bord
291  mon tmpmon;
292  res.exceed[noquo]=mon(i,1);
293 
294  serv.int2mon(-1*(stockindicetab[j]+1),tmpmon);
295 
296  res.exceed[noquo]*=tmpmon;//int2mon<mon>(j);
297  res.exceed[noquo]*=p.nf[j];
298  ++noquo;
299  };
300  }
301 
302  res.poly.ind=p.ind;
303  res.poly.ind*=mon(i,1);
304  res.exceed[noquo++]=res.poly.ind;
305  res.sizeexceed=noquo;
306  res.exceed=(mon*)MAC_REV_REALLOC<mon>(res.exceed,(p.size+1)*sizeof(mon)
307  ,(noquo)*sizeof(mon));
308  res.poly.ind.SetCoeff(noquo+1);
309  res.poly.size=0;
310  pp=0;
311  for(int j=0;j<w.sizenf;j++)
312  if(w.tabnf[j])
313  {
314  for(int m=0;m<8;m++)
315  if(Iszero(w.tabcoeff[8*j+m]))
316  w.tabnf[j]&=~(1<<m);
317  if(w.tabnf[j])
318  {
319  res.poly.size+=nbbits[w.tabnf[j]];
320  pp=j;
321  }
322  }
323  res.poly.nf=(COEFF*)MAC_REV_MALLOC<COEFF>(res.poly.size*sizeof(COEFF));
324  res.poly.sizenf=pp+1;
325  res.poly.nfind=(unsigned char *)malloc(res.poly.sizenf);
326  pp=0;
327  for(int j=0;j<res.poly.sizenf;j++)
328  {
329  if(w.tabnf[j])
330  for(int k=0;k<8;k++)
331  if((w.tabnf[j]>>k)&1)
332  {
333  res.poly.nf[pp++]=w.tabcoeff[8*j+k];
334  w.tabcoeff[8*j+k]=zero;
335  }
336  res.poly.nfind[j]=w.tabnf[j];
337  w.tabnf[j]=0;
338  }
339  free(stockindicetab);
340  destroy_space(&w);
341 
342  return res;
343 }
344 
345 template<typename typPk, typename typMk, typename typdump, typename Base,
346  typename typplus, typename typwork, typename typserv>
347 void compute_newpol(typplus &listplus, typPk &Pk, typMk &tmpMk, typdump &dump,
348  Base &b, int &k, typwork &w, typserv &serv)
349 {
350  typedef typename typdump::value_type dumpstruct;
351  typedef typename typPk::value_type pol;
352  typedef typename typMk::value_type mon;
353  // list<std::future<typename typplus::value_type> >listfuture;
354  list<std::thread >listfuture;
355  map<mon,int,my_Dlex<typename typMk::value_type> > mapint;
356  int nbface=0;
357  int nbthreadrunning=0;
359 #ifdef unimul
360 serv.reinit_multiple();
361 #endif
362 #ifdef uninf
363  serv.reinit_nf();
364 #endif
365 
366  cout<<"debut compute newpol"<<endl;
367  //construction des pol ord sup
368  for(int i=0;i<b.nbvar();i++)
369  {
370  for(typename typPk::iterator iter=Pk.begin();iter!=Pk.end();iter++)
371  {
372  // cout<<"avant gooddir l'ind "<<iter->ind<<" "<<i<<endl;
373  // cout<<"GoodDir((*iter).ind,i,b)) "<<GoodDir((*iter).ind,i,b)<<endl;
374  pol2terasync::synchromutex.lock();
375  if(GoodDir((*iter).ind,i,b))
376  {
377  mon tmpmon=iter->ind*mon(i,1);
378  tmpmon.SetCoeff(1);
379  if(mapint.count(tmpmon)==0)
380  {
381 
383  mapint[tmpmon]=nbface++;
384  tmpMk.push_back(tmpmon);
385  // listplus.push_back(tmp);
386  std::thread t=std::thread(
387  wrap_mult<typdump, Base, mon, typserv>
388  ,std::ref(tabmul[nbthreadrunning++]),i
389  ,std::ref(*iter),std::ref(dump),
390  std::ref(b),
391  std::ref(serv));
392  //t.join();
393  listfuture.push_back(std::move(t));
394 
395 #if 0
396  listfuture.push_back(
397  std::async(std::launch::async,
398  mult<typdump, Base, mon, typserv>
399  ,i,std::ref(*iter),std::ref(dump),
400  std::ref(b),
401  std::ref(serv)));
402 #endif
403  //on a deja fait le push_back avant l'appel à mult
404  //
405  if(listfuture.size()==NBFUTURE)
406  {
407  pol2terasync::synchromutex.unlock();
408  int compt_th=0;
409  // cout<<"------------------------------------------"<<endl;
410  // for(auto iterfuture=listfuture.begin();
411  // iterfuture!=listfuture.end();iterfuture++)
412  for(auto &iterfuture : listfuture)
413  {//iterfuture->wait();
414  //listplus.push_back(iterfuture->get());
415  iterfuture.join();
416  listplus.push_back(std::move(tabmul[compt_th++]));
417  }
418  listfuture.erase(listfuture.begin(),listfuture.end());
419  nbthreadrunning=0;
420  pol2terasync::synchromutex.lock();
421  }
422  }
423  }
424  pol2terasync::synchromutex.unlock();
425 
426  }
427  }
428  int compt_th=0;
429  for(auto &iterfuture : listfuture)
430  // for(auto iterfuture=listfuture.begin();
431  // iterfuture!=listfuture.end();iterfuture++)
432  {
433  iterfuture.join();
434  // listplus.push_back(iterfuture->get());
435  listplus.push_back(std::move(tabmul[compt_th++]));
436  }
437  listfuture.erase(listfuture.begin(),listfuture.end());
438 
439  cout<<"fin compute newpol"<<endl;
440 
441 }
442 
443 template<typename typMat,typename typPk,typename typP,
444  typename typMk,typename Base,typename typdump,typename typexceed,
445  typename typsizeexceed, typename workspace, typename monomial_server>
446 int newpkmkMatrixofSolve(typMat &mat,typMat & L,typPk &Pk, typP &P,typMk &Mk,
447  int &k,Base &b, typdump &dump,typexceed &exceed_ret,
448  typsizeexceed & sizeexceed_ret, workspace &w, monomial_server &serv)
449 {
450 
451 typedef typename typMk::value_type mon;
452  typedef typename typP::value_type::order_t ord;
453  typedef typename typPk::value_type pol;
454  typedef typename pol::coeff_t coeff;
455  typedef typename typP::value_type polyalp;
456  typedef component<vector<pol>,mon> compo;
457  typPk recall;//to be erased as soon as treat_crochet et compute_...
458  //have been patched
459  map<typename mon::rep_t,int> mon2face, mon2col;
460  vector<vector<int> > G;
461  vector<int> vec;
462  typPk tmpPk,workvect,convcrochet;
463  typMk tmpMk;
464  //list<mon *> exceed,exceedcrochet;
465  vector<mon *> exceed,exceedcrochet;
466  list<int> sizeexceed,sizeexceedcrochet;
467  int nbproj=0,flagdoplus=1;
468  int nbcompo=0,*pr,*pc;
469  list<compo>listcomp;
470  compo crochet;//ceci est le regroupement des crochet
471  // list<list<mon *> > listexceed;
472  // list<list<int> > listsizeexceed;
473  int indexinside=0;
474  list<resmul<pol> > list_plus;
475  list<std::future<resmul<pol> > >list_future;
476  list<resmul<pol> > list_conv;
477  //
478  struct timeval t1,t2;
479  gettimeofday(&t1,NULL);
480  mat.destroystore();mat.ncol=0;mat.nrow=0;mat.nnz=0;
481  exceed_ret.erase(exceed_ret.begin(),exceed_ret.end());
482  sizeexceed_ret.erase(sizeexceed_ret.begin(),sizeexceed_ret.end());
483  //prise en compte des pol pas encore introduits
484  cerr<<"k on entering newpkmkmatrixof "<<k<<endl;
485  typP ttmpP=Crochet(P,k+1);//
486  if (!ttmpP.empty())
487  {
488  for(auto & p : ttmpP)
489  cout<<"crochet ici"<<p<<endl;
490 //flagdo plus est positinne dans cett fonction au cas ou il ait chute de degre
491  treat_noempty_crochet(P, ttmpP, tmpPk, tmpMk, Pk,
492  Mk, dump, b, flagdoplus, k, recall, exceed, sizeexceed, serv);
493  cout<<"en sortie tmpPk.size "<<tmpPk.size()<<endl;
494  //tmpPk est non vide que si on chute de degre
495  //on fait alors comme si on venait de les calculer
496  for(auto &i :tmpPk)
497  {
498  resmul<pol> tmp;
499  tmp.poly=i;
500  tmp.exceed=(mon*)MAC_REV_MALLOC<mon>(sizeof(mon));
501  tmp.sizeexceed=1;
502  *tmp.exceed=i.ind;
503  list_plus.push_back(tmp);
504  }
505 
506  }
507  if(flagdoplus)
508  {
509  cout<<"newpol"<<endl;
510  compute_newpol(list_plus,Pk,tmpMk,dump, b, k, w,serv);
511  cout<<"fin newpol "<<list_plus.size()<<endl;
512  }
513  //Ces polynomes la n'ont pas d'ind à proprement parler
514  //Il ne faut pas les prendre en compte pour faire le graph
515  //
516  //
517  //Il faut effacer tmpMk et le reconstruire apres coup en
518  //fonction des composantes fortement connexes decouvertes
519  //
520  for(auto & p : ttmpP)
521  cout<<"crochet ici"<<p<<endl;
522  conv_merge(convcrochet,ttmpP,exceedcrochet,sizeexceedcrochet,b,serv);
523  crochet.poly.resize(convcrochet.size());
524  crochet.sizeexceed.resize(convcrochet.size());
525  copy(convcrochet.begin(),convcrochet.end(),crochet.poly.begin());
526  crochet.exceed=exceedcrochet;
527  copy(sizeexceedcrochet.begin(),sizeexceedcrochet.end(),crochet.sizeexceed.begin());
528 #if 1 //def DEBUG1
529  cout<<"crochet "<<endl;
530  for(int i=0;i<crochet.poly.size();i++)
531  {
532  cout<<"ind "<<crochet.poly[i].ind<<endl;
533  copy(crochet.exceed[i],crochet.exceed[i]+crochet.sizeexceed[i],ostream_iterator<mon>(cout," + "));
534  cout<<invconv<Poly>(crochet.poly[i],serv)<<endl;
535  }
536 #endif
537  //
538  // cout<<"icccccccccccccccccccccccccccccccccccccccccccccccccccccci"<<endl;
539  auto itersizeexceed=sizeexceed.begin();
540  // for(auto &p : exceed)
541  // copy(p,p+*(itersizeexceed++),ostream_iterator<mon>(cout," "));
542  //crochet.sizeexceed=sizeexceedcrochet;
545  //relire ce suit pour verifier les matrices pas carres
548 
549  //On constuit le graphe
550  //Revoir l'alloc de G
551  //treat_nonmaximal_degree_elem(P, ttmpP, tmpPk, tmpMk, Pk,
552  // Mk, dump, b, flagdoplus, k, recall, exceed, sizeexceed, serv);
553 
554  compute_ancestors(list_plus,b);
555  makegraph(G, list_plus, mon2face,b);
556  //On construit le grpahe et
557  //on conserve l'appairage entre les ind et le faces
558  vec.resize(G.size(),-1);
559 #ifdef DEBUG1
560  cout<<"le graph"<<endl;
561  for(auto &v : G)
562  {
563  for(auto i: v)
564  cout<<i<<", ";
565  cout<<endl;
566  }
567 #endif
568  cout<<"je rentre ds tarjan "<<G.size()<<" "<<tmpMk.size()<<endl;
569  tarjan( G, vec);
570  cout<<"alloc pr "<<tmpPk.size()<<" "<<tmpMk.size()<<endl;
571  pr=(int *)malloc(list_plus.size()*sizeof(int));
572  pc=(int *)malloc(tmpMk.size()*sizeof(int));
573  tmpMk.erase(tmpMk.begin(),tmpMk.end());
574  //
575  //On construit les listes de pol a partir des Comp Connexes
576  for_each(vec.begin(),vec.end(),[&nbcompo](int i){nbcompo=(nbcompo<i?i:nbcompo);});
577  //nbcompo est l'index de la derniere composante
578  for(int i=0;i<=nbcompo;i++)
579  {
580  typPk tmp;
581  list<mon*> tmpexceed;
582  list<int> tmpsizeexceed;
583  compo tmpcomp;
584  int j=0;
585  for_each(list_plus.begin(),list_plus.end(),
586  [&]
588  {
589  if(vec[mon2face[iter.poly.ind.rep]]==i)
590  {
591  tmpcomp.poly.push_back(iter.poly);
592  tmpcomp.sizeexceed.push_back(iter.sizeexceed);
593  tmpcomp.exceed.push_back(iter.exceed);
594  }
595  });//fin de la lambda et du foreach
596  listcomp.push_back(tmpcomp);
597  }
598  gettimeofday(&t2,NULL);
599  cout<<"\e[31m Temps poly+graph "<<t2.tv_sec-t1.tv_sec+1e-6*(t2.tv_usec-t1.tv_usec);
600  cout<<"\e(B\e[m"<<endl;
601 
602 //Pour chaque liste matrice + solve
603 // itersizeexceed=sizeexceed.begin();
604 // iterexceed=exceed!.begin();
605  int prout=0;
606  int numcompo=0;
607  cout<<"nb total de compo dans la loiste "<<listcomp.size()<<endl;
608  for(auto iter=listcomp.begin();iter!=listcomp.end();iter++,numcompo++)
609  {
610  //il faut construit tmpMK pour la composante
611  int *tmppr,*tmppc;
612  typMk verytmpMk;
613  typMat tmpmat;
614 #ifdef DEBUG1
615  cout<<"pour la composante "<<prout++<<endl;
616  {
617  auto toto=iter->sizeexceed.begin();
618  typename vector<pol>::iterator tutu=iter->poly.begin();
619  for(auto m : iter->exceed)
620  {
621  cout<<"sizeexceed ici "<<*toto<<endl;
622  copy(m,m+*(toto++),ostream_iterator<mon>(cout," + ")),cout<<endl;;
623  cout<<tutu->ind<<endl;
624  if(tutu->size)
625  copy(tutu->nf,tutu->nf+tutu->size,ostream_iterator<coeff>(cout," ")),cout<<endl;
626  cout<<invconv<Poly>(*(tutu++),serv)<<endl;
627  cout<<"------------------------------------ "<<endl;
628  }
629  }
630 #endif
631  for(auto &&iterind : iter->poly)
632  {
633  verytmpMk.push_back(iterind.ind);
634  // cout<<"je push "<<iterind.ind<<endl;
635  }
636  gettimeofday(&t1,NULL);
637  construct_matrix_from_newpol_nofree(tmpmat, iter->poly, verytmpMk,
638  iter->exceed, iter->sizeexceed, P);
639 
640 #ifdef DEBUG
641  cout<<"matrix of comp"<<endl;
642  affdebug(tmpmat);
643  cout<<"\e[32mpour la composante \e[37m"<<prout<<endl;
644  {
645  auto toto=iter->sizeexceed.begin();
646  typename vector<pol>::iterator tutu=iter->poly.begin();
647  for(auto m : iter->exceed)
648  {
649  copy(m,m+*(toto++),ostream_iterator<mon>(cout," - ")),cout<<endl;;
650  cout<<tutu->ind<<endl;
651  cout<<"size tutu "<<tutu->size<<endl;
652  if(tutu->size)
653  copy(tutu->nf,tutu->nf+tutu->size,ostream_iterator<coeff>(cout," "));
654  cout<<invconv<Poly>(*(tutu++),serv)<<endl;
655  cout<<"------------------------------------ "<<endl;
656  }
657  }
658 #endif
659 #ifdef DEBUG
660  cout<<"la petite matrice"<<endl;
661  affdebug(tmpmat);
662 #endif
663  /*
664  modifier constructmatrix pour ressortir les exceed a cote de la composante
665  //FAIT
666  */
667 
668 
669  //P est la pour forwareder les types ord et pol
670  //On resoud
671  // pr et pc sont alloués avec malloc
672  // dans la fonction solve
673  // il faut les desallouer
674  //
675  //Ceci est une fonction solve a ecrire pour reporter
676  //les operations sur les poly aussi sur les exceed
677  //
678  gettimeofday(&t2,NULL);
679  cout<<"\e[31m Temps contrustmatrix "<<t2.tv_sec-t1.tv_sec+1e-6*(t2.tv_usec-t1.tv_usec);
680  cout<<"\e(B\e[m"<<endl;
681  t1=t2;
682  Solve(tmpmat,L,*iter,&tmppr,&tmppc,verytmpMk,w,serv);
683 #ifdef DEBUG11
684  cout<<"\e[31mApres SOLVE \e[37m"<<prout<<endl;
685  {
686  auto toto=iter->sizeexceed.begin();
687  typename vector<pol>::iterator tutu=iter->poly.begin();
688  for(auto m : iter->exceed)
689  {
690  copy(m,m+*(toto++),ostream_iterator<mon>(cout," - ")),cout<<endl;;
691  cout<<tutu->ind<<endl;
692  cout<<invconv<Poly>(*(tutu++),serv)<<endl;
693  }
694  }
695 #endif
696  gettimeofday(&t2,NULL);
697  cout<<"\e[31m Temps Solve "<<t2.tv_sec-t1.tv_sec+1e-6*(t2.tv_usec-t1.tv_usec);
698  cout<<"\e(B\e[m"<<endl;
699  t1=t2;
700 // copy(tmppc,tmppc+verytmpMk.size(),ostream_iterator<int>(cout," "));
701 // cout<<endl;
702  // inverse(tmppc,verytmpMk.size());
703  // Dopermu(verytmpMk,tmppc);
704  for(auto &m :verytmpMk)
705  {
706  m.SetCoeff(1);
707  tmpMk.push_back(m);
708  }
709 #if 0
710  // ces operations sont faites dans reorder ind entre solveL et solveU
711  {
712  //ici on remet les ind a la bonne valeur
713  //a inclure dans une petite fonction inline apres
714  int j=0;
715  typename typMk::iterator itermon=verytmpMk.begin();
716 
717  for(auto iter_in_poly=iter->poly.begin();
718  itermon!=verytmpMk.end();iter_in_poly++,itermon++,j++)
719  {
720  cout<<" dans verytmp "<<*itermon<<
721  invconv<typename typP::value_type>(*iter_in_poly,serv)<<endl;
722 
723  if(!Iszero(tmpmat(j,j)))
724  {
725  //cout<<"ligne "<<j<<" je mets le monome "<<*itermon<<" "<<iter->ind.GetCoeff()<<endl:
726  iter_in_poly->ind=*itermon;//*(iter_in_poly->ind.GetCoeff());
727  iter_in_poly->ind.SetCoeff(1);
728  }
729  else
730  {
731  //On rajoute aux exceed des autre polyn\çomes de la composante les
732  //les monomes correspondant a cette colonne
733  for(int i=tmpmat.colptr[j];i<tmpmat.colptr[j+1];i++)
734  if(!(((coeff*)tmpmat.nzval)[i]==0))
735  {
736  //il y a eu permiutation des colonnes il
737  // faut donc se fier a itermon plutot qu'aux ind
738  mon tmpmon=*itermon;//iter_in_poly->ind;
739  coeff tmpcoeff=((coeff*)tmpmat.nzval)[i];
740  //Bon maintenant on regarde si le coefficient diagonal de U de la
741  //ligne tmpmat.rowind[i] est non nul et si c'est le cas
742  //il fautr diviser par lui
743  if(!Iszero(tmpmat(tmpmat.rowind[i],tmpmat.rowind[i])))
744  tmpcoeff/=tmpmat(tmpmat.rowind[i],tmpmat.rowind[i]);
745  //Apres on peut affecter
746  tmpmon.SetCoeff(tmpcoeff);
747  iter->exceed[tmpmat.rowind[i]]=(mon*)
748  MAC_REV_REALLOC<mon>(iter->exceed[tmpmat.rowind[i]],
749  iter->sizeexceed[tmpmat.rowind[i]]*sizeof(mon),
750  (iter->sizeexceed[tmpmat.rowind[i]]+1)*sizeof(mon));
751 
752  iter->exceed[tmpmat.rowind[i]][iter->sizeexceed[tmpmat.rowind[i]]]=tmpmon;
753  iter->sizeexceed[tmpmat.rowind[i]]++;
754  }
755  iter_in_poly->ind=mon(0);
756 
757  }
758  }
759  }
760 #endif
761 
762 #ifdef CACABOUDIN// 1//ICICICICI
763  cout<<"apres solve les poly de la compo"<<endl;
764  for(int i=0;i<iter->poly.size();i++)
765  {
766  cout<<"ind "<<iter->poly[i].ind<<endl;
767  copy(iter->exceed[i],iter->exceed[i]+iter->sizeexceed[i],
768  ostream_iterator<mon>(cout," + "));cout<<endl;
769  cout<<invconv<typename typP::value_type>(iter->poly[i],serv)<<endl;
770  cout<<"--------------------********************"<<endl;
771  }
772  for(auto i : iter->poly)
773  cout<<"ind "<<i.ind<<endl;
774  copy(iter->sizeexceed.begin(),iter->sizeexceed.end(),ostream_iterator<int>(cout," "));
775  cout<<"iciiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"<<endl;
776 
777 
778 #endif
779  cout<<"update "<<endl;
780  //mise a jour des autres polynomes et recnstruction de la matrice complete
781  cout<<"la map"<<endl;
782 #if 1
783  map<typename mon::rep_t,resmul<typename compo::typPk::value_type> > mon2pol;
784  {
785  auto iterexceed=iter->exceed.begin();
786  auto itersizeexceed=iter->sizeexceed.begin();
787  auto iterpoly=iter->poly.begin();
788  int i=0;
789  for(auto iterpoly=iter->poly.begin();iterpoly!=iter->poly.end();
790  iterpoly++,iterexceed++,itersizeexceed++,i++)
791  {
793  tmp.poly=*iterpoly;
794  tmp.exceed=*iterexceed;
795  tmp.sizeexceed=*itersizeexceed;
796  if(!(tmpmat(i,i)==0)) mon2pol[iterpoly->ind.rep]=tmp;
797  //on augmente le workspace pour update apres
798  for(;w.sizenf<iterpoly->sizenf;increase_space(&w));
799  }
800  }
801 #endif
802  cout<<"le graph"<<endl;
803  //on regarde pour chaque sommet de la composante les arcs sortant
804  //ceux qui aboutissent a des sommets qui ne sont pas dans la compo
805  //indiquent un update a faire
806  vector<char> toupdate(nbcompo+1,0);
807  int indexcompo=0;
808 #if 1
809  for(int i_vec=0;i_vec<G.size();i_vec++)
810  {
811  if(vec[i_vec]==numcompo)
812  {
813  //on a trouvé un sommet dans la composante
814  //en cours de traitement
815  for(int j=0;j<G.size();j++)
816  {
817  // cout<<"G["<<j<<"]["<<i_vec<<"] "<<G[j][i_vec]<<endl;
818  // cout<<"<<<<<<"<<vec[j]<<" "<<numcompo<<endl;
819 // if(G[i_vec][j] && vec[j]!=numcompo)
820  if(G[j][i_vec] && vec[j]!=numcompo)
821  {
822  toupdate[vec[j]]=1;
823  //On rajoute les composantes qui vont m'updater
824  //a celle trouvee
825  for(int j_graph=0;j_graph<G.size();j_graph++)
826  G[j][j_graph]|=G[i_vec][j_graph];
827  //on a plus besoin re parser cet update
828  G[j][i_vec]=0;
829 
830  }
831  }
832  }
833  }
834 #endif
835 #ifdef ASYNCUPDATE
836  list<std::thread> list_up;
837 #endif
838 
839  cout<<"les poly"<<endl;
840  for(auto itercomp=listcomp.begin();itercomp!=listcomp.end();
841  itercomp++,indexcompo++)
842  //le test est fait dans update pol
843  if(toupdate[indexcompo])
844  {
845 #ifdef CACABOUDIN// 1//ICICICICICICI
846  cout<<"la compo a updater avant"<<endl;
847  for(int i=0;i<itercomp->poly.size();i++)
848  {
849  cout<<"ind "<<itercomp->poly[i].ind<<endl;
850  copy(itercomp->exceed[i],itercomp->exceed[i]+itercomp->sizeexceed[i],
851  ostream_iterator<mon>(cout," + "));cout<<endl;
852  cout<<invconv<typename typP::value_type>(itercomp->poly[i],serv)<<endl;
853  cout<<"--------------------********************"<<endl;
854  }
855 #endif
856 #ifndef ASYNCUPDATE
857  update_pol(*itercomp,*iter,mon2pol,w,serv);
858 #else
859  list_up.push_back(std::thread(wrap_update_pol<compo,
861  >,monomial_server>,
862  std::ref(*itercomp),
863  std::ref(*iter),std::ref(mon2pol),std::ref(serv)));
864  if(list_up.size()>=NBFUTURE)
865  {
866  for(auto &i : list_up)
867  i.join();
868  list_up.erase(list_up.begin(),list_up.end());
869  }
870 #endif
871 
872 #if 0//ICVICICICICI
873  cout<<"la compo apres update"<<endl;
874  for(int i=0;i<itercomp->poly.size();i++)
875  {
876  cout<<"ind "<<itercomp->poly[i].ind<<endl;
877  copy(itercomp->exceed[i],itercomp->exceed[i]+itercomp->sizeexceed[i],
878  ostream_iterator<mon>(cout," + "));cout<<endl;
879  cout<<invconv<typename typP::value_type>(itercomp->poly[i],serv)<<endl;
880  cout<<"--------------------********************"<<endl;
881  }
882 #endif
883  }
884 #ifdef ASYNCUPDATE
885  for(auto &i : list_up)
886  i.join();
887  list_up.erase(list_up.begin(),list_up.end());
888 #endif
889 
890  //update_pol(*itercomp,*iter,w,serv);
891  // cout<<"fin update "<<endl;
892  cout<<"avant update du crochet "<<endl;
893  for(int i=0;i<crochet.poly.size();i++)
894  {
895  cout<<"ind "<<crochet.poly[i].ind<<endl;
896  copy(crochet.exceed[i],crochet.exceed[i]+crochet.sizeexceed[i],ostream_iterator<mon>(cout," + "));
897  cout<<invconv<Poly>(crochet.poly[i],serv)<<endl;
898  }
899 
900  update_pol(crochet,*iter,mon2pol,w,serv);//on fait uassi agir sur les polynomes du crochet
901  cout<<"fin des updates "<<endl;
902 #if 1
903  cout<<"apres update du crochet "<<endl;
904  for(int i=0;i<crochet.poly.size();i++)
905  {
906  cout<<"ind "<<crochet.poly[i].ind<<endl;
907  copy(crochet.exceed[i],crochet.exceed[i]+crochet.sizeexceed[i],ostream_iterator<mon>(cout," + "));
908  cout<<invconv<Poly>(crochet.poly[i],serv)<<endl;
909  }
910 #endif
911  reconstruct_mat(mat,tmpmat);
912 #ifdef DEBUG1
913  affdebug(mat);
914  //il faut reconstruire les pr et pc globaux
915  cout<<"indexinside "<<indexinside<<endl;
916 #endif
917  reconstruct_pr_pc(pr,pc,tmppr,tmppc,tmpmat.ncol,indexinside);
918  indexinside+=verytmpMk.size();
919  free(tmppr);
920  free(tmppc);
921  }
922  //Reconstruction des tmpPk tmpMk classiques
923  // Pour la matrice
924  // On gere aussi ici le cas des coefficient des colonnes de pivot nul
925  //comme ca on connait les indices de ligne et colonne
926  //
927  typPk verytmpPk;
928 
929  for(auto c : listcomp)
930  {
931  for(auto &p: c.poly)
932  verytmpPk.push_back(p);
933  for(auto &p: c.exceed)
934  exceed_ret.push_back(p);
935  for(auto &p: c.sizeexceed)
936  {
937  // cout<<"sizeexceed "<<p<<endl;
938  sizeexceed_ret.push_back(p);
939  }
940 
941  }
942  cout<<"apres reconstruction des Pk "<<endl;
943 #ifdef DEBUG
944  copy(sizeexceed_ret.begin(),sizeexceed_ret.end(),ostream_iterator<int>(cout," **--** "));cout<<endl;
945 #endif
946  //On rajoute les poly de crochet dans Pk
947  //ET (c'est important pour addB on incrmente nrow ce mat en fonction
948  for(auto &p : crochet.poly)
949  {
950  p.ind=mon(0);
951  verytmpPk.push_back(p);
952  }
953  for(auto &p : crochet.exceed)
954  exceed_ret.push_back(p);
955  for(auto &p : crochet.sizeexceed)
956  sizeexceed_ret.push_back(p);
957 
958 #if 1
959  int indexmat=0;
960  for(auto m : tmpMk)
961  {
962  // cout<<"mon2col "<<m.rep<<" "<<indexmat<<endl;
963  mon2col[m.rep]=indexmat++;
964  }
965  indexmat=0;
966  cout<<"avant updatematrix "<<endl;
967 #ifdef DEBUG
968  copy(sizeexceed_ret.begin(),sizeexceed_ret.end(),ostream_iterator<int>(cout," **--** "));cout<<endl;
969 #endif
970 #ifdef GLOBALUPDATE
971  global_update_matrix(mat,listcomp,mon2col);
972 #else
973  for(auto c : listcomp)
974  {
975  update_matrix(mat,c,mon2col,indexmat);
976  indexmat+=c.poly.size();
977  }
978 #endif
979  cout<<"apres updatematrix"<<endl;
980  //affdebug(mat);
981  //copy(sizeexceed_ret.begin(),sizeexceed_ret.end(),ostream_iterator<int>(cout," **--** "));cout<<endl;
982 #endif
983 
984 
985  mat.nrow+=crochet.poly.size();
986 #ifdef DEBUG
987  cout<<"verytmp"<<endl;
988  for(auto &p :verytmpPk)
989  cout<<invconv<typename typP::value_type>(p,serv)<<endl;
990 #endif
991  Pk=verytmpPk;
992  Mk=tmpMk;
993  return flagdoplus;
994 }
995 
996 
997 template<typename typP,typename typdump,typename Base,
998  template<typename mon, typename pol> class monomial_server, typename mon>
999 void algo_borderbases(typP P,typdump &dump,Base &b,
1000  monomial_server<mon,pol2ter<mon,typename mon::coeff_t> > &serv)
1001 {
1002  typedef typename typP::value_type polyalp;
1003  typedef list<pol2ter<mon,typename mon::coeff_t> > typPk;
1004  typedef list<typename typPk::value_type::monom_t> typMk;
1005  // typedef typename typMk::value_type mon;
1006  typedef typename typPk::value_type pol;
1007 
1008  typMk Mk;
1009  typMk Spoldejavu;
1010  typPk Pk,S;
1011  typPk recall;
1013  typedef harewell<typename typP::value_type::coeff_t> typMat;
1014  typMat Mat,L;
1015  int nouveaumon,allpolused=0,maxdeg,k,*pr,*pc;
1016  vector<typename typMk::value_type*> exceed;
1017  list<int> sizeexceed;
1018  //cout<<"avant init"<<endl;
1019 
1020  init_algo<typMat>(P,nouveaumon,maxdeg,k,Pk,Mk,b,dump,w,serv);
1021  //cout<<"apres init"<<endl;
1022 #ifdef GOTZMANN
1023  int nextdim=-1;
1024  initial_mon(k,b,dump,serv);
1025  while((!critere_got(b,dump,serv))||(k<=maxdeg))
1026 #else
1027  while(nouveaumon||(k<=maxdeg))
1028 #endif
1029  {
1030  int killspol;
1031 #ifdef VERBOSE
1032  cout<<"Spolordsup"<<endl;
1033 #endif
1034  S=Spolordsup(Pk,b,Spoldejavu);
1035  for(typename typPk::iterator iter=S.begin();iter!=S.end();iter++)
1036  {
1037  // cout<<"poly de taille "<<iter->size<<endl;
1038  cout<<invconv<typename typP::value_type>(*iter,serv)<<endl;
1039  }
1040 #ifdef DEBUG
1041 cout<<"poly a la fin de la boulcle de l'algo "<<Pk.size()<<endl;
1042 for(typename typPk::iterator iter=Pk.begin();iter!=Pk.end();iter++)
1043  {
1044  // cout<<"poly de taille "<<iter->size<<endl;
1045  cout<<invconv<typename typP::value_type>(*iter,serv)<<endl;
1046 }
1047  cout<<endl<<"newpkmkmatrixof"<<endl;
1048 #endif
1049 
1050  killspol=!newpkmkMatrixofSolve(Mat,L,Pk,P,Mk,k,b,dump,exceed,sizeexceed
1051  ,w,serv);
1052 #ifdef DEBUG
1053  cout<<"poly apres solve (attention exceed)"<<endl;
1054  copy(sizeexceed.begin(),sizeexceed.end(),ostream_iterator<int>(cout," *** "));cout<<endl;
1055  for(typename typPk::iterator iter=Pk.begin();iter!=Pk.end();iter++)
1056  {
1057 
1058  cout<<invconv<typename typP::value_type>(*iter,serv)<<endl;
1059  }
1060 #endif
1061  if(killspol) S.erase(S.begin(),S.end());
1062  if (k+1>=maxdeg) allpolused=1;
1063  if(Mk.size()==0) nouveaumon=0;
1064  // cout<<"le rang "<<my_rank(Mat)<<endl;
1065  // cout<<"Mk.size() "<<Mk.size()<<endl;
1066  // copy(Mk.begin(),Mk.end(),ostream_iterator<mon>(cout," "));
1067  // cout<<endl;
1068  if ((unsigned)my_rank(Mat)==Mk.size())
1069  //matrice de rang plein
1070  //donc tous les exceed sont vides
1071  {
1072  typMk tmpSpoldejavu;
1073  typPk redspol,secd=secondmembre(Mat,Pk);;
1074  //secondmembre2(Mat,Pk,secd);
1075  //typename typPk::iterator iter=Pk.begin();
1076 #ifdef VERBOSE
1077  cout<<"matrice de rang plein "<<endl;
1078 #endif
1079  Dump(Pk,dump);
1080 #ifdef GOTZMANN
1081  nextmon(k,b,dump,serv);
1082 #endif
1083 #ifdef VERBOSE
1084  cout<<"secd/size() "<<secd.size()<<endl;
1085 #endif
1086  ReduceSpol(S,dump,redspol,b,w,serv);//tmpSpoldejavu);
1087  my_merge(redspol,secd);
1088 #ifdef VERBOSE
1089  cout<<"redspol.size "<<redspol.size()<<endl;
1090 #endif
1091  if(redspol.size()==0)
1092  {
1093  k++;
1094  my_merge(Spoldejavu,tmpSpoldejavu);
1095  L.destroystore();
1096  continue;
1097  //la matrice a rang plein
1098  //ET les Spol\secondmembre de ce niveau se ,reduisent a 0
1099  }
1100  else
1101  {
1102  //on a des spol\secondmembre qui se reduisent pas a 0
1103  //cad un defaut de commuatation
1104  int tmpdeg=mindeg(redspol,serv);
1105  max_degppcm=k+2;
1106  nouveaumon=1;
1107 #ifdef VERBOSE
1108  cout<<"redspol.size() "<<redspol.size()<<endl;
1109 #endif
1110 
1111  if (tmpdeg==(k+1))
1112  my_merge(Spoldejavu,tmpSpoldejavu);
1113  k=tmpdeg;
1114 
1115  recover(Pk,Mk,dump,k);
1116 
1117  forget(b,dump,k,recall);
1118 #ifdef VERBOSE
1119  cout<<"debut newcrochetchoix"<<endl;
1120 #endif
1121  NewCrochetchoix(P,Pk,Mk,redspol,k,dump,b,recall,w,serv);
1122 #ifdef VERBOSE
1123  cout<<"fin newcrochetchoix"<<endl;
1124 #endif
1125  NewDestroyredspol(redspol,Pk);
1126  serv.compress(Pk,dump,b,k);
1127  Dump(Pk,dump);
1128 #ifdef GOTZMANN
1129  nextmon(k,b,dump,serv);
1130 #endif
1131  L.destroystore();
1132  //misa jour de B dans crochet choix!!
1133  continue;
1134  }
1135  }
1136  else
1137  //la matrice n'est pas de rang plein
1138  {
1139 #ifdef VERBOSE
1140  cout<<"matrice de rang pas plein "<<endl;
1141 #endif
1142  typPk secd;
1143 #ifdef VERBOSE
1144  cout<<"addB"<<endl;
1145 #endif
1146 #ifdef DEBUG11
1147  cout<<"avant addB "<<Pk.size()<<endl;
1148  auto iterexceed=exceed.begin();
1149  auto itersizeexceed=sizeexceed.begin();
1150  for(typename typPk::iterator iter=Pk.begin();iter!=Pk.end();iter++,iterexceed++,itersizeexceed++)
1151  {
1152  cout<<"ind "<<iter->ind<<" est sikzeexceed "<<*itersizeexceed<<endl;
1153  copy(*iterexceed,*iterexceed+*itersizeexceed,ostream_iterator<mon>(cout," + "));
1154  cout<<endl;
1155  cout<<invconv<typename typP::value_type>(*iter,serv)<<endl;
1156  }
1157 #endif
1158  AddB(Mat,Pk,Mk,exceed,sizeexceed,dump,b,serv);
1159 #if 0
1160  cout<<"apres addB "<<Pk.size()<<endl;
1161  for(typename typPk::iterator iter=Pk.begin();iter!=Pk.end();iter++)
1162  {
1163  cout<<invconv<typename typP::value_type>(*iter,serv)<<endl;
1164  }
1165 #endif
1166  //
1167  //secondmembre supprime des trucs dans Pk!!
1168  //
1169  // cout<<"second membre"<<endl;
1170  secd=secondmembre(Mat,Pk);
1171  // cout<<"voisin"<<endl;
1172  rajoute_voisins(Pk,Mk,dump,b,w,serv);
1173  // cout<<"fin voisin"<<endl;
1174  //ne selectionne que les non nuls
1175  if(secd.size()==0)
1176  {
1177  typPk redspol;
1178  Dump(Pk,dump);
1179 #ifdef GOTZMANN
1180  nextmon(k,b,dump,serv);
1181 #endif
1182 
1183  ReduceSpol(S,dump,redspol,b,w,serv);//,Spoldejavu);
1184 #ifdef NO_TWICE
1185 for(typename typPk::iterator iter=redspol.begin();iter!=redspol.end();iter++)
1186  P.push_back(invconv<polyalp>(*iter));
1187 #endif
1188  if(redspol.size()==0)
1189  {
1190  k++;
1191  L.destroystore();
1192  continue;
1193  //la matrice a pas rang plein second membre =0
1194  //ET les Spol de ce niveau se ,reduisent a 0
1195  }
1196  else
1197  {
1198  //on a des spol qui se reduisent pas a 0
1199  //cad un defaut de commutation
1200  k=mindeg(redspol,serv);
1201  recover(Pk,Mk,dump,k);
1202  forget(b,dump,k,recall);
1203 #ifdef VERBOSE
1204  cout<<"il ya un passage par mat rang pas"
1205  <<"plein et pol non zero"<<endl;
1206 #endif
1207  NewCrochetchoix(P,Pk,Mk,redspol,k,dump,b,recall,w,serv);
1208  NewDestroyredspol(redspol,Pk);
1209  serv.compress(Pk,dump,b,k);
1210  Dump(Pk,dump);
1211 #ifdef GOTZMANN
1212  nextmon(k,b,dump,serv);
1213 #endif
1214 
1215  L.destroystore();
1216  continue;
1217  }
1218  }
1219  else
1220  {
1221  //on a des pol qui se reduisent pas a 0
1222  //cad un defaut de commuatation dans les coins
1223  typPk redspol;
1224  Dump(Pk,dump);
1225 #ifdef GOTZMANN
1226  nextmon(k,b,dump,serv);
1227 #endif
1228  ReduceSpol(S,dump,redspol,b,w,serv);//,Spoldejavu);
1229  my_merge(secd,redspol);
1230 #ifdef NO_TWICE
1231 for(typename typPk::iterator iter=redspol.begin();iter!=redspol.end();iter++)
1232  P.push_back(invconv<polyalp>(*iter));
1233 #endif
1234  k=mindeg(secd,serv);
1235  recover(Pk,Mk,dump,k);
1236  forget(b,dump,k,recall);
1237 #if 0
1238  cout<<"poly avant newcrochetchoix (attention exceed)"<<endl;
1239  copy(sizeexceed.begin(),sizeexceed.end(),ostream_iterator<int>(cout," *** "));cout<<endl;
1240  for(typename typPk::iterator iter=Pk.begin();iter!=Pk.end();iter++)
1241  {
1242 
1243  cout<<invconv<typename typP::value_type>(*iter,serv)<<endl;
1244  }
1245 #endif
1246 
1247  NewCrochetchoix(P,Pk,Mk,secd,k,dump,b,recall,w,serv);
1248 #if 0
1249  cout<<"poly apres newcrochetchoix (attention exceed)"<<endl;
1250  copy(sizeexceed.begin(),sizeexceed.end(),ostream_iterator<int>(cout," *** "));cout<<endl;
1251  for(typename typPk::iterator iter=Pk.begin();iter!=Pk.end();iter++)
1252  {
1253 
1254  cout<<invconv<typename typP::value_type>(*iter,serv)<<endl;
1255  }
1256 #endif
1257 
1258  NewDestroyredspol(secd,Pk);
1259  serv.compress(Pk,dump,b,k);
1260  Dump(Pk,dump);
1261 #ifdef GOTZMANN
1262  nextmon(k,b,dump,serv);
1263 #endif
1264 
1265  L.destroystore();
1266  continue;
1267  }
1268 
1269  }
1270  }
1271 
1272  Mat.destroystore();
1273  //while nouveau mon etc...
1274  destroy_space(&w);
1275 #ifdef VERBOSE
1276  cout<<"sortie d'algo flash et dimension "<<endl;
1277 #endif
1278  return ;//dump;
1279  //comme ca on conserve le tri par degre des formes normales et
1280  //donc la construction des operateurs de multiplication se
1281  //fait plus vite.. :-)
1282 
1283 }
1284 
1285 
1286 #ifdef FUN
1287 template<typename typcompo, typename typP, typename typwork, typename typserv>
1288 void treatment_component(typcompo &iter,int numcompo, int nbcompo, typP &P,
1289  typwork &w, typserv &serv)
1290 {
1291  //il faut construit tmpMK pour la composante
1292  int *tmppr,*tmppc;
1293  typMk verytmpMk;
1294  typMat tmpmat;
1295  for(auto &&iterind : iter->poly)
1296  {
1297  verytmpMk.push_back(iterind.ind);
1298  // cout<<"je push "<<iterind.ind<<endl;
1299  }
1300  gettimeofday(&t1,NULL);
1301  construct_matrix_from_newpol_nofree(tmpmat, iter->poly, verytmpMk,
1302  iter->exceed, iter->sizeexceed, P);
1303 
1304  //P est la pour forwareder les types ord et pol
1305  //On resoud
1306  // pr et pc sont alloués avec malloc
1307  // dans la fonction solve
1308  // il faut les desallouer
1309  //
1310  //Ceci est une fonction solve a ecrire pour reporter
1311  //les operations sur les poly aussi sur les exceed
1312  //
1313  gettimeofday(&t2,NULL);
1314 #ifdef VERBOSE
1315  cout<<"\e[31m Temps contrustmatrix "<<t2.tv_sec-t1.tv_sec+1e-6*(t2.tv_usec-t1.tv_usec);
1316  cout<<"\e(B\e[m"<<endl;
1317 #endif
1318  t1=t2;
1319  Solve(tmpmat,L,*iter,&tmppr,&tmppc,verytmpMk,w,serv);
1320 
1321  gettimeofday(&t2,NULL);
1322 #ifdef VERBOSE
1323  cout<<"\e[31m Temps Solve "<<t2.tv_sec-t1.tv_sec+1e-6*(t2.tv_usec-t1.tv_usec);
1324  cout<<"\e(B\e[m"<<endl;
1325 #endif
1326  t1=t2;
1327  for(auto &m :verytmpMk)
1328  {
1329  m.SetCoeff(1);
1330  tmpMk.push_back(m);
1331  }
1332 #ifdef VERBOSE
1333  cout<<"update "<<endl;
1334  //mise a jour des autres polynomes et recnstruction de la matrice complete
1335  cout<<"la map"<<endl;
1336 #endif
1337  map<typename mon::rep_t,resmul<typename compo::typPk::value_type> > mon2pol;
1338  {
1339  auto iterexceed=iter->exceed.begin();
1340  auto itersizeexceed=iter->sizeexceed.begin();
1341  auto iterpoly=iter->poly.begin();
1342  int i=0;
1343  for(auto iterpoly=iter->poly.begin();iterpoly!=iter->poly.end();
1344  iterpoly++,iterexceed++,itersizeexceed++,i++)
1345  {
1347  tmp.poly=*iterpoly;
1348  tmp.exceed=*iterexceed;
1349  tmp.sizeexceed=*itersizeexceed;
1350  if(!(tmpmat(i,i)==0)) mon2pol[iterpoly->ind.rep]=tmp;
1351  //on augmente le workspace pour update apres
1352  for(;w.sizenf<iterpoly->sizenf;increase_space(&w));
1353  }
1354  }
1355 #ifdef VERBOSE
1356  cout<<"le graph"<<endl;
1357 #endif
1358  //on regarde pour chaque sommet de la composante les arcs sortant
1359  //ceux qui aboutissent a des sommets qui ne sont pas dans la compo
1360  //indiquent un update a faire
1361  vector<char> toupdate(nbcompo+1,0);
1362  int indexcompo=0;
1363  for(int i_vec=0;i_vec<G.size();i_vec++)
1364  {
1365  if(vec[i_vec]==numcompo)
1366  {
1367  //on a trouvé un sommet dans la composante
1368  //en cours de traitement
1369  for(int j=0;j<G.size();j++)
1370  {
1371  if(G[j][i_vec] && vec[j]!=numcompo)
1372  {
1373  toupdate[vec[j]]=1;
1374  //On rajoute les composantes qui vont m'updater
1375  //a celle trouvee
1376  for(int j_graph=0;j_graph<G.size();j_graph++)
1377  G[j][j_graph]|=G[i_vec][j_graph];
1378  //on a plus besoin re parser cet update
1379  G[j][i_vec]=0;
1380  }
1381  }
1382  }
1383  }
1384 #ifdef ASYNCUPDATE
1385  list<std::thread> list_up;
1386 #endif
1387 #ifdef VERBOSE
1388  cout<<"les poly"<<endl;
1389 #endif
1390  for(auto itercomp=listcomp.begin();itercomp!=listcomp.end();
1391  itercomp++,indexcompo++)
1392  //le test est fait dans update pol
1393  if(toupdate[indexcompo])
1394  {
1395 #ifndef ASYNCUPDATE
1396  update_pol(*itercomp,*iter,mon2pol,w,serv);
1397 #else
1398  list_up.push_back(std::thread(wrap_update_pol<compo,
1400  >,monomial_server>,
1401  std::ref(*itercomp),
1402  std::ref(*iter),std::ref(mon2pol),std::ref(serv)));
1403  if(list_up.size()>=NBFUTURE)
1404  {
1405  for(auto &i : list_up)
1406  i.join();
1407  list_up.erase(list_up.begin(),list_up.end());
1408  }
1409 #endif
1410  }
1411 #ifdef ASYNCUPDATE
1412  for(auto &i : list_up)
1413  i.join();
1414  list_up.erase(list_up.begin(),list_up.end());
1415 #endif
1416 #ifdef VERBOSE
1417  cout<<"avant update du crochet "<<endl;
1418  for(int i=0;i<crochet.poly.size();i++)
1419  { cout<<"ind "<<crochet.poly[i].ind<<endl;
1420  copy(crochet.exceed[i],crochet.exceed[i]+crochet.sizeexceed[i],ostream_iterator<mon>(cout," + "));
1421  cout<<invconv<Poly>(crochet.poly[i],serv)<<endl;
1422  }
1423 #endif
1424  update_pol(crochet,*iter,mon2pol,w,serv);
1425  //on fait uassi agir sur les polynomes du crochet
1426 #ifdef VERBOSE
1427  cout<<"fin des updates "<<endl;
1428  cout<<"apres update du crochet "<<endl;
1429  for(int i=0;i<crochet.poly.size();i++)
1430  {
1431  cout<<"ind "<<crochet.poly[i].ind<<endl;
1432  copy(crochet.exceed[i],crochet.exceed[i]+crochet.sizeexceed[i],ostream_iterator<mon>(cout," + "));
1433  cout<<invconv<Poly>(crochet.poly[i],serv)<<endl;
1434  }
1435 #endif
1436  reconstruct_mat(mat,tmpmat);
1437  reconstruct_pr_pc(pr,pc,tmppr,tmppc,tmpmat.ncol,indexinside);
1438  indexinside+=verytmpMk.size();
1439  free(tmppr);
1440  free(tmppc);
1441 }
1442 #endif
1443 
1444 #endif
1445 
void int2mon(const int &i, mon &res)
Definition: placemon3.hpp:664
Definition: dlexorder.hpp:4
Definition: workspace.hpp:11
void wrap_update_pol(typcomp &comp_to_update, typcomp &updating_comp, typserv &serv)
Definition: pol2terspecial.hpp:1372
Definition: pol2terspecial.hpp:36
Definition: dump.hpp:2
void compute_newpol(typPk &Pk, typPk &tmpPk, typMk &tmpMk, typdump &dump, typexceed &exceed, typsizeexceed &sizeexceed, Base &b, int &k, typrecall &recall, typwork &w, typserv &serv)
Definition: corealgo3.hpp:1323
void tarjan(typgraph &G, typvec &vec)
Definition: pol2terspecial.hpp:263
void AddB(const typmat &mat, typPk &Pk, const typMk &Mk, const typexceed &exceed, const typsizeexceed &sizeexceed, const typdump &dump, typB &b, monomial_server &serv)
Definition: pol2terspecial.hpp:2470
void affdebug(const typmat &m)
Definition: io.hpp:30
list< polbis< mono, T > > & Solve(typmat &S, std::list< polbis< mono, T > > &TildePk, int **pr, int **pc, workspace &w)
Definition: pol2bisspecial.hpp:609
void treat_noempty_crochet(typP &P, typttmpP &ttmpP, typPk &tmpPk, typMk &tmpMk, typPk &Pk, typMk &Mk, typdump &dump, Base &b, int &flagdoplus, int &k, typrecall &recall, typexceed &exceed, typsizeexceed &sizeexceed, typserv &serv)
Definition: corealgo3.hpp:1251
int isdivisible(const mon &m1, const mon &m2, int nbvar)
Definition: isdivisible.hpp:5
void compute_ancestors(typPk &tmpPk, Base &b)
Definition: pol2terspecial.hpp:62
void free(void *)
int sizeexceed
Definition: pol2terspecial.hpp:24
Definition: pol.hpp:6
long nextdim(std::vector< int > &coeff_mac, int k)
Definition: macaulay.hpp:45
void my_merge(T &l1, const T &l2)
Definition: corealgo.hpp:35
pol poly
Definition: pol2terspecial.hpp:22
int newpkmkMatrixofSolve(typMat &mat, typMat &L, typPk &Pk, typP &P, typMk &Mk, int &k, Base &b, typdump &dump, typexceed &exceed_ret, typsizeexceed &sizeexceed_ret, workspace &w, monomial_server &serv)
Definition: pol2terspecial.hpp:495
typpol mult(int i, const typpol &pol, const typdump &dump, const Base &b, mon **exce, int &exsize)
Definition: corealgo.hpp:1077
void reconstruct_mat(typMat &mat, const typMat &tmpmat)
Definition: pol2terspecial.hpp:1687
void NewDestroyredspol(typPk &redspol, const typPk &Pk)
Definition: corealgo.hpp:2824
long flag
Definition: alp_f2c.H:52
void * malloc(YYSIZE_T)
void recover(typPk &Pk, typMk &Mk, const typdump &dump, int k)
Definition: dump.hpp:192
coeff * tabcoeff
Definition: workspace.hpp:12
void Dump(const typPk &Pk, typdump &dump)
Definition: dump.hpp:48
T coeff_t
Definition: pol.hpp:9
void nextmon(const Base &b, typdump &dump, typserv &serv)
Definition: gotzman.hpp:74
int nbvar()
Definition: types.hpp:37
void global_update_matrix(typmat &m, typlistcomp &listcomp, typmap &mon2col)
Definition: pol2terspecial.hpp:1024
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
int critere_got(const Base &b, typdump &dump, typserv &serv)
Definition: gotzman.hpp:191
void reconstruct_pr_pc(int *&pr, int *&pc, int *tmppr, int *tmppc, int sizetmp, int indexinside)
Definition: pol2terspecial.hpp:1720
typPk Spolordsup(typPk Pk, const Base &b)
Definition: corealgo.hpp:147
MSKint32t k
Definition: mosek.h:2713
R rep
Definition: Monom.hpp:30
void rajoute_voisins(typPk &Pk, const typMk &Mk, const typdump &dump, Base &b, workspace &w, monomial_server &serv)
Definition: IsinB3.hpp:111
C coeff_t
Definition: Monom.hpp:26
int nbbits[256]
Definition: pol2ter.hpp:4
Definition: pol2terspecial.hpp:17
void(* tabfun2[32])(COEFF *, COEFF *, pol< mon, COEFF > *, int *)
Definition: auxfun.hpp:418
Definition: placemon3.hpp:14
void conv_merge(typPk &Pk, typP &P, typexceed &ex, typsize &sizeex, const Base &b)
Definition: corealgo.hpp:1297
mon * exceed
Definition: pol2terspecial.hpp:23
void ReduceSpol(typPk &S, const typdump &dump, typPk &redspol, const Base &b)
Definition: corealgo.hpp:2217
Definition: pol2ter.hpp:15
R rep_t
Definition: Monom.hpp:27
Mon mon
Definition: solver_bb_floating.cpp:136
int nbvars
Definition: types.hpp:17
#define NBFUTURE
Definition: pol2terspecial.hpp:14
void increase_space(workspace< coeff > *w)
Definition: workspace.hpp:19
Definition: types.hpp:14
exponent_t GetDegree() const
Definition: Monom.hpp:70
void NewCrochetchoix(typP &P, typPk &Pk, typMk &Mk, typPk &redspol, int &k, typdump &dump, Base &b, typrecall &recall)
Definition: corealgo.hpp:2594
MSKrealt * c
Definition: mosek.h:2678
MSKint32t MSKint32t MSKint32t i
Definition: mosek.h:2278
int Iszero(const Scl< MPQ > &c)
Definition: Iszero.hpp:14
int GoodDir(const typmon &m, int i, const Base &b)
Definition: corealgo.hpp:1278
int sizenf
Definition: workspace.hpp:15
void makegraph(typgraph &G, const typPk tmpPk, const typexceed &exceed, const typsizeexceed &sizeexceed, typmon2face &mon2face, Base &b)
Definition: pol2terspecial.hpp:140
int size
Definition: pol.hpp:10
#define COEFF
Definition: symbo2.hpp:8
void forget(Base &b, typdump &dump, int k, typrecall &recall)
Definition: dump.hpp:75
cont< pol< mon, T > > Crochet(const cont< pol< mon, T > > &P, int k)
Definition: corealgo.hpp:6
int mulind(int indexbase, int var, const typBase &b)
Definition: placemon3.hpp:126
void update_pol(typcomp &comp_to_update, typcomp &updating_comp, workspace *w, typserv &serv)
void initial_mon(const Base &b, typdump &dump, typserv &serv)
Definition: gotzman.hpp:57
void update_matrix(typmat &m, typcomp &c, typmap &mon2col, int indexmat)
Definition: pol2terspecial.hpp:1125
#define pol
Definition: pol2ter.hpp:3
int size
Definition: workspace.hpp:14
void SetCoeff(const C &c)
Definition: Monom.hpp:68
void compress(typPk &Pk, typdump &dump, const Base &b, int k)
Definition: placemon3.hpp:1076
int mindeg(const typPk &l)
Definition: corealgo.hpp:2422
mon ind
Definition: pol.hpp:11
T * nf
Definition: pol.hpp:12
void construct_matrix_from_newpol_nofree(typMat &mat, typPk &tmpPk, typMk &tmpMk, typexceed &exceed, typsizeexceed &sizeexceed, typP &P)
Definition: pol2terspecial.hpp:342
Home  |  Download & InstallContributions