home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / gnu / gcc / bug / 1987 < prev    next >
Encoding:
Text File  |  1992-07-25  |  6.9 KB  |  305 lines

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!cis.ohio-state.edu!wisdom.weizmann.ac.il!vogr
  3. From: vogr@wisdom.weizmann.ac.il (Ogranovich Vadim)
  4. Subject: GCC-2.2.1-bug-report
  5. Message-ID: <9207251441.AA08244@white.wisdom.weizmann.ac.il>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Sat, 25 Jul 1992 22:41:56 GMT
  10. Approved: bug-gcc@prep.ai.mit.edu
  11. Lines: 292
  12.  
  13. Hello,
  14. This is a programm which fails GCC 2.2.1 for DEC.
  15. I'm sorry but I really could not reduce the size and
  16. locate the error-causing spot. ( Read continuation after
  17. the code ).
  18.  
  19. #include <stream.h>
  20.  
  21. int const TRUE =1;
  22. int const FALSE =0;
  23.  
  24. enum Rescale {
  25.   half,  // "halves" the # of slices and doubles the coupled meshsize
  26.   same,
  27.   twice  // "doubles" the # of slices and halfs the coupled meshsize
  28. };
  29.  
  30. class Vector {
  31. public:
  32.   double h;
  33.   int n;
  34.   double &value(int);
  35. };
  36.  
  37. void interpolation(Vector &from, Vector &to);
  38.  
  39.  
  40. class GridAttr {
  41. public:
  42.   int  nx;
  43.   int  ny;
  44.   double  x0, y0;  // left-down corner. Default zeros
  45.   double  x1, y1;  // right-upper corner. Default ones
  46.   
  47.   double hx;     // x-mesh-size
  48.   double hy;     // y-mesh-size
  49.   
  50.   inline double x(int i) { return x0 + hx*i; }
  51.   inline double y(int i) { return y0 + hy*i; }
  52.  
  53.   GridAttr(int nnx, int nny, 
  54.        double xx0 = 0.0, double xx1 = 1.0,
  55.        double yy0 = 0.0, double yy1 =1.0);
  56.  
  57.   GridAttr(GridAttr &, Rescale xscale = same, Rescale yscale = same);
  58.  
  59. };
  60.  
  61. // from # of slices, right-upper and left-down corners
  62. GridAttr::GridAttr(int nnx, int nny, 
  63.            double xx0 = 0.0, double xx1 = 1.0,
  64.            double yy0 = 0.0, double yy1 =1.0)
  65. : nx(nnx), ny(nny), x1(xx1), y1(yy1), x0(xx0), y0(yy0)
  66. {
  67.   hx = (x1-x0)/(nx-1);
  68.   hy = (y1-y0)/(ny-1);
  69. }
  70.  
  71. GridAttr::GridAttr(GridAttr &from, 
  72.            Rescale xscale = same, Rescale yscale = same)
  73. : x1(from.x1), y1(from.y1), x0(from.x0), y0(from.y0)
  74. {
  75.   switch(xscale) {
  76.   case half:      // 
  77. //    if((from.nx % 2) == 0)
  78. //    cerr << "Warning: halving grid with even #slices\n" << from;
  79.     
  80.     nx = (from.nx + 1)/2;
  81.     break;
  82.     
  83.   case same:
  84.     nx = from.nx;
  85.     break;
  86.     
  87.   case twice:
  88.     nx = 2*from.nx - 1;
  89.     break;
  90.   }
  91.   
  92.   switch(yscale) {
  93.   case half:
  94. //    if((from.ny % 2) == 0)
  95. //    cerr << "Warning: halving grid with even #slices\n" << from;
  96.     
  97.     ny = (from.ny + 1)/2;
  98.     break;
  99.     
  100.   case same:
  101.     ny = from.ny;
  102.     break;
  103.     
  104.   case twice:
  105.     ny = 2*from.ny - 1;
  106.     break;
  107.   }
  108.   
  109.   hx = (x1-x0)/(nx-1);
  110.   hy = (y1-y0)/(ny-1);
  111. }
  112.  
  113. class Grid : public GridAttr {
  114. public:
  115.   double &value(int xs, int ys);
  116.   double dxdx(int xs, int ys)
  117.   { return (value(xs-1, ys) - 2*value(xs, ys) + value(xs+1,ys))/(hx*hx); }
  118.   double dydy(int xs, int ys)
  119.   { return (value(xs, ys-1) - 2*value(xs, ys) + value(xs,ys+1))/(hy*hy); }
  120.  
  121.   Grid(GridAttr &attr, Rescale xscale = same, Rescale yscale = same) : 
  122.   GridAttr(attr, xscale, yscale) {}
  123. };
  124.  
  125.  
  126. // XVector is a column, i.e. all the entries
  127. // have the same X-coordinate
  128.  
  129. class XVector : public Vector {
  130.   Grid &g;
  131.   int xs;
  132. public:
  133.   double &value(int ys) 
  134.   { return g.value(xs, ys); }
  135.   
  136.   XVector(Grid &gg, int xss) : g(gg)
  137.   { xs=xss ; h=gg.hy; n=gg.ny; }
  138. };
  139.  
  140.  
  141. // YVector is a row. i.e. all the entries
  142. // have the same Y-coordinate 
  143.  
  144. class YVector : public Vector {
  145.   Grid &g;
  146.   int ys;
  147. public:
  148.   double &value(int xs) 
  149.   { return g.value(xs, ys); }
  150.   
  151.   YVector(Grid &gg, int yss) : g(gg)
  152.   { ys=yss ; h=gg.hx; n=gg.nx; }
  153. };
  154.  
  155.  
  156.  
  157. class GridGeneral : public Grid {
  158.   double *p;
  159. public:
  160.   double &value(int xs, int ys)
  161.   { return p[xs + ys * nx]; }
  162.  
  163.   void operator +=(Grid &);
  164.  
  165.   GridGeneral(GridAttr attr, Rescale xscale =same, Rescale yscale =same) : 
  166.   (attr, xscale, yscale)
  167.   { p =new double[attr.nx*attr.ny]; }
  168.   ~GridGeneral() { delete p; }
  169. };
  170.  
  171. void GridGeneral::operator +=(Grid &g)
  172. {
  173.   for(int xs=0; xs<nx; xs++)
  174.   for(int ys=0; ys<ny; ys++)
  175.   value(xs, ys)+=g.value(xs, ys);
  176. }
  177.  
  178. void interpolation(Grid &from, GridGeneral &to);
  179. void injection(Grid &from, GridGeneral &to);
  180. void full_weighting(Grid &from, GridGeneral &to);
  181.  
  182.  
  183. class Operator : public GridGeneral {
  184. public:
  185.   double lh_value(int xs, int ys);
  186.   double point_relaxation(int xs, int ys, double rhs);
  187.   Operator(GridAttr &attr, Rescale xscale =same, Rescale yscale =same) : 
  188.   (attr, xscale, yscale) {}
  189. };
  190.  
  191.  
  192. void gauss_seidel(Operator &lhs, Grid &rhs);
  193.  
  194. //
  195. // Coarse-to-fine
  196. // ~~~~~~~~~~~~~~
  197.  
  198. void
  199. interpolation(Vector &from, Vector &to)
  200. {
  201.   int scale =(from.n<to.n) ? 2 : 1;
  202.   
  203.   for(int i=0; i<from.n; i++)    // copying
  204.   to.value(scale*i)=from.value(i);
  205.   
  206.   if(from.n<to.n)        // filling gaps
  207.   for(i=0; i<from.n-1; i++)
  208.   to.value(2*i+1)=0.5*(from.value(i)+from.value(i+1));
  209. }
  210.  
  211.  
  212. void
  213. interpolation(Grid &from, GridGeneral &to)
  214. {
  215.   int scale =(from.nx<to.nx) ? 2 : 1;
  216.   
  217.   for(int i=0; i<from.nx; i++)
  218.   interpolation(XVector(from, i), XVector(to, scale*i));
  219.   
  220.   if(from.nx<to.nx)
  221.   for(i=0; i<to.ny; i++)
  222.   interpolation(YVector(from, i), YVector(to, i));
  223. }
  224.  
  225. //
  226. // Fine-to-coarse
  227. // ~~~~~~~~~~~~~~
  228.  
  229. void
  230. injection(Grid &from, GridGeneral &to)
  231. {
  232.   int xscale=(from.nx=to.nx) ? 1 : 2;
  233.   int yscale=(from.ny=to.ny) ? 1 : 2;
  234.  
  235.   for(int xs=0; xs<to.nx; xs++)
  236.   for(int ys=0; ys<to.ny; ys++)
  237.   to.value(xs, ys)=from.value(xscale*xs, yscale*ys);
  238. }
  239.  
  240.  
  241. void
  242. full_weighting(Grid &from, GridGeneral &to)
  243. {
  244.   int xscale=(from.nx=to.nx) ? 1 : 2;
  245.   int yscale=(from.ny=to.ny) ? 1 : 2;
  246.   
  247.   for(int xs=1; xs<to.nx-1; xs++)
  248.   for(int ys=1; ys<to.ny-1; ys++)
  249.   {
  250.     to.value(xs, ys)=
  251.     from.value(xscale*xs, yscale*ys)+
  252.     (from.nx>to.nx) ? 
  253.     0.5*(from.value(xscale*xs-1, yscale*ys) + 
  254.      from.value(xscale*xs+1, yscale*ys))
  255.     : 0.0 +
  256.     (from.ny>to.ny) ? 
  257.     0.5*(from.value(xscale*xs, yscale*ys-1) + 
  258.      from.value(xscale*xs, yscale*ys+1))
  259.     : 0.0 +
  260.     (from.nx>to.nx && from.ny>to.ny) ?
  261.     0.25*(from.value(xscale*xs-1, yscale*ys-1) + 
  262.       from.value(xscale*xs-1, yscale*ys+1) +
  263.       from.value(xscale*xs+1, yscale*ys-1) + 
  264.       from.value(xscale*xs+1, yscale*ys+1))
  265.     : 0.0;
  266.     to.value(xs, ys)*=.25;
  267.   }
  268. }
  269.  
  270.  
  271.  
  272. Having compiled the program as it is
  273.  
  274. > g++ -Wall bug.C -lg++ -c
  275.  
  276. the compiler produces the following output
  277.  
  278. > /usr/local/bin/gcc: Internal compiler error: program cc1plus got fatal signal 4
  279. > Compilation exited abnormally with code 1 at Sat Jul 25 17:00:35
  280.  
  281.  
  282. If one removes the definition of the function full_weighting(Grid &, GridGeneral &)
  283. from the source then compilation is successful
  284.  
  285. > bug.C:3: warning: `TRUE' defined but not used
  286. > bug.C:4: warning: `FALSE' defined but not used
  287. > /usr/local/bin/gcc: -lg++: linker input file unused since linking not done
  288. > Compilation finished at Sat Jul 25 17:16:29
  289.  
  290. But if instead of the function full_weighting one removed the definitions of
  291. the functions interpolation(Grid &from, GridGeneral &to) and 
  292. injection(Grid &from, GridGeneral &to) compilation would be successful too.
  293.  
  294. And the last remark is that the whole code can be fixed by putting extra
  295. parentheses around the (... ? ... : ... ) operations in the function full_weighting.
  296.  
  297.  
  298. If you need some more details please mail me what namly they are.
  299.  
  300. Best regards.
  301. Vadim
  302.  
  303.