Patch: Make Field Centerings Table Always Dynamic

Jeffrey Oldham oldham at codesourcery.com
Thu Aug 30 19:04:16 UTC 2001


We change the implementation of canonicalCentering tables from a
static object to a dynamically allocated table.  This resolves a
runtime execution problem for KCC/Irix and simplifies the code.  Prior
to this patch, gcc used the dynamic code and all other compilers used
the static code, which apparently was wrong.

2001-08-30  Jeffrey D. Oldham  <oldham at codesourcery.com>

        * FieldCentering.cmpl.cpp
        (CanonicalCentering<Dim>::CanonicalCentering): Make dynamic
        centering table construction unconditional.
        * FieldCentering.h (CanonicalCentering::~CanonicalCentering):
        Destroy dynamic centering table for all implementations.
        (CanonicalCentering::class_count_m): Always used.
        (CanonicalCentering::centering_table_m): Always used.

Tested on       Irix/KCC 4.0c and Linux gcc 3.0.1 by compiling Pooma library and the Field tests
Approved by     Stephen Smith
Applied to      mainline

Thanks,
Jeffrey D. Oldham
oldham at codesourcery.com
-------------- next part --------------
Index: FieldCentering.cmpl.cpp
===================================================================
RCS file: /home/pooma/Repository/r2/src/Field/FieldCentering.cmpl.cpp,v
retrieving revision 1.1
diff -c -p -r1.1 FieldCentering.cmpl.cpp
*** FieldCentering.cmpl.cpp	2001/08/30 01:15:06	1.1
--- FieldCentering.cmpl.cpp	2001/08/30 16:59:13
*************** CanonicalCentering<Dim>::CanonicalCenter
*** 46,53 ****
    Centering<Dim>::Positions positions[Dim][2];
    enum { x = 0, y, z };
  
! #if __GNUC__
!   // Avoid a gcc 3.0 and 2.96 error.
    if (class_count_m == 0) {
      centering_table_m = new Centering<Dim>**[CellType+1];
      for (int i = 0; i <= CellType; ++i) {
--- 46,52 ----
    Centering<Dim>::Positions positions[Dim][2];
    enum { x = 0, y, z };
  
!   // Create the tables if necessary.
    if (class_count_m == 0) {
      centering_table_m = new Centering<Dim>**[CellType+1];
      for (int i = 0; i <= CellType; ++i) {
*************** CanonicalCentering<Dim>::CanonicalCenter
*** 57,64 ****
      }
    }
    ++class_count_m;
- 
- #endif // __GNUC__
  
    // Add the cell centerings.
    centering = Centering<Dim>(CellType, Continuous);
--- 56,61 ----
Index: FieldCentering.h
===================================================================
RCS file: /home/pooma/Repository/r2/src/Field/FieldCentering.h,v
retrieving revision 1.1
diff -c -p -r1.1 FieldCentering.h
*** FieldCentering.h	2001/08/30 01:15:06	1.1
--- FieldCentering.h	2001/08/30 16:59:13
*************** public:
*** 384,393 ****
  
    CanonicalCentering();
  
- #if __GNUC__
-   // Avoid a gcc 3.0 and 2.96 error.
    //---------------------------------------------------------------------------
    // Deallocate centering_table_m.
    ~CanonicalCentering () {
      if (--class_count_m == 0) {
        for (int i = 0; i <= CellType; ++i) {
--- 384,392 ----
  
    CanonicalCentering();
  
    //---------------------------------------------------------------------------
    // Deallocate centering_table_m.
+ 
    ~CanonicalCentering () {
      if (--class_count_m == 0) {
        for (int i = 0; i <= CellType; ++i) {
*************** public:
*** 398,404 ****
        delete [] centering_table_m;
      }
    }
- #endif // __GNUC__
  
    //---------------------------------------------------------------------------
    // Return the desired centering.
--- 397,402 ----
*************** private:
*** 440,457 ****
      return answer;
    }
  
- #if __GNUC__
-   // Avoid a gcc 3.0 and 2.96 error.
    // Number of extent objects.
    static int class_count_m;
!   static Centering<Dim>*** centering_table_m;
! #else
    // Table containing the centerings, which are the cross product of
    // the centering type, discontinuous xor continuous, all the
    // possible combinations of dimensions.  We ignore illegal entries
    // such as centering_table_m[x][y][0].
!   static Centering<Dim> centering_table_m[CellType+1][2][1<<Dim];
! #endif // __GNUC__
  };
  
  //-----------------------------------------------------------------------------
--- 438,453 ----
      return answer;
    }
  
    // Number of extent objects.
+ 
    static int class_count_m;
! 
    // Table containing the centerings, which are the cross product of
    // the centering type, discontinuous xor continuous, all the
    // possible combinations of dimensions.  We ignore illegal entries
    // such as centering_table_m[x][y][0].
! 
!   static Centering<Dim>*** centering_table_m;
  };
  
  //-----------------------------------------------------------------------------
*************** std::ostream &operator<<(std::ostream &o
*** 498,506 ****
  // Define CanonicalCentering's static members.
  //-----------------------------------------------------------------------------
  
- #if __GNUC__
- // Avoid a gcc 3.0 and 2.96 error.
  // Number of extent objects.
  template <int Dim>
  int CanonicalCentering<Dim>::class_count_m = 0;
  
--- 494,501 ----
  // Define CanonicalCentering's static members.
  //-----------------------------------------------------------------------------
  
  // Number of extent objects.
+ 
  template <int Dim>
  int CanonicalCentering<Dim>::class_count_m = 0;
  
*************** int CanonicalCentering<Dim>::class_count
*** 508,519 ****
  // the centering type, discontinuous xor continuous, all the
  // possible combinations of dimensions.  We ignore illegal entries
  // such as centering_table_m[x][y][0].
  template <int Dim>
  Centering<Dim>*** CanonicalCentering<Dim>::centering_table_m = 0;
- #else
- template<int Dim>
- Centering<Dim> CanonicalCentering<Dim>::centering_table_m[CellType+1][2][1<<Dim];
- #endif // __GNUC__
  
  
  //-----------------------------------------------------------------------------
--- 503,511 ----
  // the centering type, discontinuous xor continuous, all the
  // possible combinations of dimensions.  We ignore illegal entries
  // such as centering_table_m[x][y][0].
+ 
  template <int Dim>
  Centering<Dim>*** CanonicalCentering<Dim>::centering_table_m = 0;
  
  
  //-----------------------------------------------------------------------------


More information about the pooma-dev mailing list