Developer documentation

strgy_rdslv_parallel.hpp
Go to the documentation of this file.
1 /********************************************************************
2  * This file is part of the source code of the realroot library.
3  * Author(s): J.P. Pavone, GALAAD, INRIA
4  * $Id: parallel.h,v 1.1 2005/07/11 10:03:56 jppavone Exp $
5  ********************************************************************/
6 #ifndef realroot_SOLVE_SBDSLV_PARALLEL_HPP
7 #define realroot_SOLVE_SBDSLV_PARALLEL_HPP
8 //--------------------------------------------------------------------
9 //#include <realroot/debug_stream.hpp>
10 //--------------------------------------------------------------------
11 namespace mmx {
12 //--------------------------------------------------------------------
13 namespace realroot
14 {
15  /* solveur de reduction parallèle */
16  /* ------------------------------- */
17  /* améliorations: */
18  /* (1) rejet acceleré: subdiviser au niveau des intersections entre bornes */
19  /* (2) si (1) est implementé on devrait assez vite arriver a la situation ou il n'y a */
20  /* qu'une borne à traiter => solveur de descartes */
21  /* oops: la version utilisée dans la thèse ne permettait pas les réductions multiples !!! */
22  /* je m'en suis rendu compte un peu tard, à une époque je prétendait que certains */
23  /* systèmes pouvaient être résolus sans subdivision, cela a dû être vrai avec le */
24  /* solveur de descartes que je n'ai plus utilisé par la suite ... */
25 
26  namespace rdslv
27  {
28  template< class system >
30  {
31  typedef typename system::creal_t creal_t;
32  typedef typename system::interval_t interval_t;
33  typedef typename system::vstack_t vstack_t;
34  typedef typename vstack_t::sz_t sz_t;
35 
36  /* incrementation et decrementation de la pile */
37  sz_t pinc ( sz_t iptr )
38  {
39  assert(iptr%4 == 0);
40  sz_t i,s;
41  for ( s = i = 0; i < 4*this->nbp(); s += this->pmsz(iptr+i)+this->pMsz(iptr+i), i += 4 ) ;
42  s = this->allocc(s+2)+2;
43  sz_t inext = this->alloci(this->nbp()*4);
44  for ( i = 0; i < 4*this->nbp(); s += this->pmsz(iptr+i)+this->pMsz(iptr+i), i += 4 )
45  {
46  this->pmsz(inext+i) = this->pmsz(iptr+i);
47  this->pmad(inext+i) = s;
48  this->pMad(inext+i) = s + this->pmsz(iptr+i);
49  this->pMsz(inext+i) = this->pMsz(iptr+i);
50  };
51  return inext;
52  };
53 
54  sz_t pdec( sz_t iptr )
55  {
56  sz_t s,i;
57  for ( s = i = 0; i < 4*this->m_nbp; s += this->pmsz(iptr+i)+this->pMsz(iptr+i), i += 4 ) ;
58  this->m_cpchnk.dec( s + 2 );
59  this->m_ipchnk.dec(4*this->nbp());
60  iptr = iptr - 4*this->nbp();
61  return iptr;
62  };
63 
64 
65  bool process( std::vector<interval_t>& reductions, const vstack_t& vp, const creal_t& eps = 1e-3, int k = 12 )
66  {
67  this->copy(vp); /* duplication de la pile de projections */
68  sz_t iptr, inext, mxsgn, sgn, i, nmult;
69  int itk = 0;
70  nmult = iptr = 0;
71 
72  for ( ; itk >= 0; )
73  {
74  sgn = mxsgn = 0;
75 
76  /* projections basses */
77  for ( mxsgn = i = 0; i < 4*this->nbp(); i += 4 )
78  {
79  if ( this->pmsz(iptr+i) && !(sgn = vctops::sgnchg( this->pmdata(iptr+i),this->pmsz(iptr+i))) )
80  {
81  this->pmsz(iptr+i) = 0;
82  if ( * this->pmdata(iptr+i) > 0.0 ) break;
83  };
84  if ( mxsgn < sgn ) mxsgn = sgn;
85  };
86  if ( i < 4*this->nbp() ) { iptr = pdec(iptr); itk --; continue; };
87 
88  /* projection hautes */
89  for ( i = 0; i < 4*this->nbp(); i += 4 )
90  {
91  if ( this->pMsz(iptr+i) && !(sgn = vctops::sgnchg( this->pMdata(iptr+i), this->pMsz(iptr+i))) )
92  {
93  this->pMsz(iptr+i) = 0;
94  if ( * this->pMdata(iptr+i) < 0.0 ) break;
95  };
96  if ( mxsgn < sgn ) mxsgn = sgn;
97  };
98  if ( i < 4*this->nbp() ) { iptr = pdec(iptr); itk --; continue; };
99 
100  /* si le domaine a été accepté, si la précision ou le quota de multiplication est dépassé. */
101  if ( !mxsgn || (this->pupper(iptr)-this->plower(iptr)) < eps )/* || nmult > m_ssz * m_esz ) */
102  {
103  if ( reductions.size() == 0 || reductions.back().upper() != this->plower(iptr) )
104  reductions.push_back(interval_t(this->plower(iptr),this->pupper(iptr)));
105  else
106  reductions.back().define(reductions.back().lower(),this->pupper( iptr ));
107  iptr = pdec( iptr ); itk --;
108  continue;
109  };
110 
111  /* incrémentation de la pile */
112  inext = pinc(iptr);
113 
114  // sz_t nbcstl = 0;
115  /* subdivision des projections basses */
116  {
117  numerics::rounding<creal_t> rnd( numerics::rnd_dw() );
118  for ( i = 0; i < 4*this->nbp(); i += 4 )
119  if ( this->pmsz(iptr+i) )
120  {
121  nmult += this->pmsz(iptr+i)*(this->pmsz(iptr+i)-1);
122  brnops::decasteljau(this->pmdata(iptr+i),this->pmdata(inext+i),this->pmsz(iptr+i));
123  // nbcstl++;
124  };
125  };
126 
127  /* subdivision des projections hautes */
128  {
129  numerics::rounding<creal_t> rnd( numerics::rnd_up() );
130  for ( i = 0; i < 4*this->nbp(); i += 4 )
131  if ( this->pMsz(iptr+i) )
132  {
133  nmult += this->pMsz(iptr+i)*(this->pMsz(iptr+i)-1);
134  brnops::decasteljau(this->pMdata(iptr+i),this->pMdata(inext+i),this->pMsz(iptr+i) );
135  // nbcstl++;
136  };
137  };
138 
139  /* if ( nbcstl == 0 )
140  {
141  print(iptr);
142  }; */
143 
144  // assert(nbcstl);
145  this->plower(inext) = this->plower(iptr);
146  this->pupper(inext) = (this->plower(iptr)+this->pupper(iptr))/2;
147  this->plower(iptr) = this->pupper(inext);
148  iptr = inext;
149  itk ++;
150  };
151 
152  return reductions.size() != 0;
153  assert(k>0);
154  }
155 
156  };
157  }
158 }
159 //--------------------------------------------------------------------
160 } //namespace mmx
161 /********************************************************************/
162 #endif //
dstack_t::interval_t interval_t
Definition: system_system.h:31
sz_t pinc(sz_t iptr)
Definition: strgy_rdslv_parallel.hpp:37
creal_t * pMdata(sz_t iptr)
Definition: system_vstack.h:40
sz_t alloci(sz_t sz)
Definition: system_vstack.h:49
void decasteljau(real_t *r, unsigned sz, const real_t &t, int str=1)
Definition: loops_brnops.hpp:23
sz_t & pMsz(sz_t iptr)
Definition: system_vstack.h:33
creal_t * pmdata(sz_t iptr)
Definition: system_vstack.h:38
system::interval_t interval_t
Definition: strgy_rdslv_parallel.hpp:32
Definition: strgy_rdslv_parallel.hpp:29
sz_t & pMad(sz_t iptr)
Definition: system_vstack.h:35
memory::linear_allocator< creal_t > m_cpchnk
Definition: system_vstack.h:21
sz_t m_nbp
Definition: system_vstack.h:20
vstack_t::sz_t sz_t
Definition: strgy_rdslv_parallel.hpp:34
Definition: rounding_mode.hpp:71
bool process(std::vector< interval_t > &reductions, const vstack_t &vp, const creal_t &eps=1e-3, int k=12)
Definition: strgy_rdslv_parallel.hpp:65
void copy(const vstack &vs)
Definition: system_vstack.h:103
real_t creal_t
Definition: system_system.h:28
unsigned sz_t
Definition: system_vstack.h:18
sz_t pdec(sz_t iptr)
Definition: strgy_rdslv_parallel.hpp:54
sz_t & pmad(sz_t iptr)
Definition: system_vstack.h:31
bool sgnchg(real_t const *const b, unsigned sz, int st=1)
Definition: loops_vctops.hpp:154
int sgn(FT a)
Sign of a.
Definition: solver_mv_monomial_tests.hpp:416
sz_t nbp() const
Definition: system_vstack.h:21
void dec(sz_t sz)
Definition: system_linear_allocator.h:72
Definition: system_vstack.h:16
system::creal_t creal_t
Definition: strgy_rdslv_parallel.hpp:31
system::vstack_t vstack_t
Definition: strgy_rdslv_parallel.hpp:33
creal_t & plower(sz_t iptr)
Definition: system_vstack.h:43
creal_t & pupper(sz_t iptr)
Definition: system_vstack.h:45
memory::linear_allocator< sz_t > m_ipchnk
Definition: system_vstack.h:24
Definition: array.hpp:12
sz_t allocc(sz_t sz)
Definition: system_vstack.h:48
sz_t & pmsz(sz_t iptr)
Definition: system_vstack.h:29
#define assert(expr, msg)
Definition: shared_object.hpp:57
Home