]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Make the rowstart field of the sparsity pattern class of type std::size_t, to allow...
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 15 Dec 2006 02:34:08 +0000 (02:34 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 15 Dec 2006 02:34:08 +0000 (02:34 +0000)
git-svn-id: https://svn.dealii.org/trunk@14249 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/source/multigrid/mg_tools.all_dimensions.cc
deal.II/deal.II/source/numerics/matrices.all_dimensions.cc
deal.II/doc/news/changes.html
deal.II/lac/include/lac/sparse_decomposition.templates.h
deal.II/lac/include/lac/sparse_ilu.templates.h
deal.II/lac/include/lac/sparse_matrix.templates.h
deal.II/lac/include/lac/sparse_mic.templates.h
deal.II/lac/include/lac/sparsity_pattern.h
deal.II/lac/source/sparse_direct.cc
deal.II/lac/source/sparsity_pattern.cc

index 00aca6f0f601157ded28ea2eeef387cfa80a6126..0ff5d6ca11df5a91fcd7a0825e260403b729cb12 100644 (file)
@@ -60,7 +60,7 @@ MGTools::apply_boundary_values (
   std::set<unsigned int>::const_iterator dof  = boundary_dofs.begin(),
                                         endd = boundary_dofs.end();
   const SparsityPattern    &sparsity    = matrix.get_sparsity_pattern();
-  const unsigned int *sparsity_rowstart = sparsity.get_rowstart_indices();
+  const std::size_t  *sparsity_rowstart = sparsity.get_rowstart_indices();
   const unsigned int *sparsity_colnums  = sparsity.get_column_numbers();
   for (; dof != endd; ++dof)
     {
index d335079911985a403606261f2194ef95d11668c3..0b6fd8ceaedb7be5702657851d01dc0968fce3b0 100644 (file)
@@ -74,7 +74,7 @@ MatrixTools::apply_boundary_values (const std::map<unsigned int,double> &boundar
   std::map<unsigned int,double>::const_iterator dof  = boundary_values.begin(),
                                                endd = boundary_values.end();
   const SparsityPattern    &sparsity    = matrix.get_sparsity_pattern();
-  const unsigned int *sparsity_rowstart = sparsity.get_rowstart_indices();
+  const std::size_t  *sparsity_rowstart = sparsity.get_rowstart_indices();
   const unsigned int *sparsity_colnums  = sparsity.get_column_numbers();
   for (; dof != endd; ++dof)
     {
index 8752cc5f9cfe2dfa8b3ae270593e9fa51097b132..ade9c244f78208a2bc5936c208e79c0bc4b74e32 100644 (file)
@@ -689,12 +689,22 @@ inconvenience this causes.
 
 <ol>
 
-  <li> <p>Improved: The class <code
-       class="class">LAPACKFullMatrix</code> now also uses LU factorization
-       of LAPACK. The new wrapper <code class="class">PreconditionLU</code>
-       allows us to use this as a preconditioner.
-       <br>
-       (GK 2006/10/02)
+  <li> <p>Improved: The <code
+       class="class">SparsityPattern</code> class would produce
+       segmentation faults if one tried to allocate a matrix with more
+       than about 4.2 billion elements (i.e. the number that one can
+       store in a 32-bit unsigned integer). This is now fixed: if you
+       have enough memory, this is now possible on 64-bit
+       systems. (The number of rows is still limited by the 32-bit
+       limit, but this is probably going to be enough for some time to
+       come.) This fix also required changing the return type of the
+       <code>SparsityPattern::get_rowstart_indices</code> function
+       from <code>const unsigned int *</code> to <code>const
+       std::size_t *</code>; since this function should not be used
+       outside of the library anyway, this is probably not a change
+       that affects user code.
+       <br>
+       (WB 2006/12/14)
        </p>
 
   <li> <p>New: The class <code
index 403b599d1c5c9eb18cd4d2a09968865ca7812570..9050076badc575f914b8f6d3e67e770fec7b67e4 100644 (file)
@@ -159,7 +159,7 @@ SparseLUDecomposition<number>::prebuild_lower_bound()
 {
   const unsigned int * const
     column_numbers = this->get_sparsity_pattern().get_column_numbers();
-  const unsigned int * const
+  const std::size_t * const
     rowstart_indices = this->get_sparsity_pattern().get_rowstart_indices();
   const unsigned int N = this->m();
 
@@ -185,7 +185,7 @@ SparseLUDecomposition<number>::copy_from (const SparseMatrix<somenumber>& matrix
 
                                    // note: pointers to the sparsity
                                    // pattern of the old matrix!
-  const unsigned int * const rowstart_indices
+  const std::size_t * const rowstart_indices
     = matrix.get_sparsity_pattern().get_rowstart_indices();
 
   const unsigned int * const column_numbers
index 7cdba0d1d07962bc0e9081fae472e80acc699661..14e2845220b21c0d891596b33f526b1a43db7640 100644 (file)
@@ -67,7 +67,7 @@ void SparseILU<number>::decompose (const SparseMatrix<somenumber> &matrix,
     this->strengthen_diagonal_impl();
 
   const SparsityPattern             &sparsity = this->get_sparsity_pattern();
-  const unsigned int * const rowstart_indices = sparsity.get_rowstart_indices();
+  const std::size_t  * const rowstart_indices = sparsity.get_rowstart_indices();
   const unsigned int * const column_numbers   = sparsity.get_column_numbers();
   
 /*
@@ -185,7 +185,7 @@ void SparseILU<number>::vmult (Vector<somenumber>       &dst,
   Assert (dst.size() == this->m(), ExcDimensionMismatch(dst.size(), this->m()));
   
   const unsigned int N=dst.size();
-  const unsigned int * const rowstart_indices
+  const std::size_t  * const rowstart_indices
     = this->get_sparsity_pattern().get_rowstart_indices();
   const unsigned int * const column_numbers
     = this->get_sparsity_pattern().get_column_numbers();
@@ -253,7 +253,7 @@ void SparseILU<number>::Tvmult (Vector<somenumber>       &dst,
   Assert (dst.size() == this->m(), ExcDimensionMismatch(dst.size(), this->m()));
   
   const unsigned int N=dst.size();
-  const unsigned int * const rowstart_indices
+  const std::size_t  * const rowstart_indices
     = this->get_sparsity_pattern().get_rowstart_indices();
   const unsigned int * const column_numbers
     = this->get_sparsity_pattern().get_column_numbers();
index b4c174dd7f2b988fde60c08bb376b69df9fc58fc..fc43544a1c19b7de897239caebb9a5b6ace00a50 100644 (file)
@@ -933,7 +933,7 @@ SparseMatrix<number>::precondition_Jacobi (Vector<somenumber>       &dst,
   const unsigned int n = src.size();
   somenumber              *dst_ptr = dst.begin();
   const somenumber        *src_ptr = src.begin();
-  const unsigned int *rowstart_ptr = &cols->rowstart[0];
+  const std::size_t  *rowstart_ptr = &cols->rowstart[0];
 
                                   // optimize the following loop for
                                   // the case that the relaxation
@@ -976,7 +976,7 @@ SparseMatrix<number>::precondition_SSOR (Vector<somenumber>       &dst,
   Assert (src.size() == n(), ExcDimensionMismatch (src.size(), n()));
 
   const unsigned int  n            = src.size();
-  const unsigned int *rowstart_ptr = &cols->rowstart[0];
+  const std::size_t  *rowstart_ptr = &cols->rowstart[0];
   somenumber         *dst_ptr      = &dst(0);
 
                                   // forward sweep
index e6081ee045bbee1ba449c4843e1566f6d98ea34a..00de1e17909c18c2f3bbce54ab969fd77bffd12d 100644 (file)
@@ -140,7 +140,7 @@ void SparseMIC<number>::decompose (const SparseMatrix<somenumber> &matrix,
   }
 
   const unsigned int* const col_nums = this->get_sparsity_pattern().get_column_numbers();
-  const unsigned int* const rowstarts = this->get_sparsity_pattern().get_rowstart_indices();
+  const std::size_t* const rowstarts = this->get_sparsity_pattern().get_rowstart_indices();
 
   for(unsigned int row=0; row<this->m(); row++)
     {
@@ -171,7 +171,7 @@ SparseMIC<number>::get_rowsum (const unsigned int row) const
                                    // get start of this row. skip the
                                    // diagonal element
   const unsigned int * const column_numbers = this->get_sparsity_pattern().get_column_numbers();
-  const unsigned int * const rowstart_indices = this->get_sparsity_pattern().get_rowstart_indices();
+  const std::size_t  * const rowstart_indices = this->get_sparsity_pattern().get_rowstart_indices();
   const unsigned int * const rowend = &column_numbers[rowstart_indices[row+1]];
 
                                    // find the position where the part
@@ -197,7 +197,7 @@ SparseMIC<number>::vmult (Vector<somenumber>       &dst,
   Assert (dst.size() == this->m(), ExcDimensionMismatch(dst.size(), this->m()));
 
   const unsigned int N=dst.size();
-  const unsigned int * const rowstart_indices = this->get_sparsity_pattern().get_rowstart_indices();
+  const std::size_t  * const rowstart_indices = this->get_sparsity_pattern().get_rowstart_indices();
   const unsigned int * const column_numbers   = this->get_sparsity_pattern().get_column_numbers();
                                    // We assume the underlying matrix A is:
                                    // A = X - L - U, where -L and -U are
index 48b6905bcec9cf4652c7abe8d166f7fd7100b67d..8b36a7be7c3ffc6dda34149cd684220ec5f2c101 100644 (file)
@@ -1257,7 +1257,7 @@ class SparsityPattern : public Subscriptor
                                      * avoid programs relying on outdated
                                      * information!
                                      */
-    inline const unsigned int * get_rowstart_indices () const;
+    inline const std::size_t * get_rowstart_indices () const;
 
                                     /**
                                      * @deprecated. Use @p row_length and
@@ -1396,7 +1396,7 @@ class SparsityPattern : public Subscriptor
                                      * may be larger than the actually used
                                      * part of the array.
                                      */
-    unsigned int max_vec_len;
+    std::size_t max_vec_len;
 
                                     /**
                                      * Maximum number of elements per
@@ -1439,7 +1439,7 @@ class SparsityPattern : public Subscriptor
                                      * number of elements that was allocated
                                      * is stored in #max_dim.
                                      */
-    unsigned int *rowstart;
+    std::size_t *rowstart;
 
                                     /**
                                      * Array of column numbers. In
@@ -1961,7 +1961,7 @@ SparsityPattern::optimize_diagonal () const
 
 
 inline
-const unsigned int *
+const std::size_t *
 SparsityPattern::get_rowstart_indices () const
 {
   return rowstart;
index da5c303053c52415776c2a9a6653948ef6a6f277..a2d3097924e8de1f9f637224ebf6ef88819a10a2 100644 (file)
@@ -661,7 +661,7 @@ SparseDirectMA27::initialize (const SparsityPattern &sp)
   
   const unsigned int
     n_rows           = sparsity_pattern->n_rows();
-  const unsigned int * const
+  const std::size_t * const
     rowstart_indices = sparsity_pattern->get_rowstart_indices();
   const unsigned int * const
     col_nums         = sparsity_pattern->get_column_numbers();
@@ -991,7 +991,7 @@ SparseDirectMA27::fill_A (const SparseMatrix<number> &matrix)
   const SparsityPattern &sparsity_pattern = matrix.get_sparsity_pattern ();
   
   const unsigned int n_rows = sparsity_pattern.n_rows();
-  const unsigned int *rowstart_indices = sparsity_pattern.get_rowstart_indices();
+  const std::size_t  *rowstart_indices = sparsity_pattern.get_rowstart_indices();
   const unsigned int *col_nums         = sparsity_pattern.get_column_numbers();
 
   unsigned int global_index = 0;
@@ -1236,7 +1236,7 @@ SparseDirectMA47::initialize (const SparseMatrix<double> &m)
   
   const unsigned int
     n_rows           = sparsity_pattern.n_rows();
-  const unsigned int * const
+  const std::size_t * const
     rowstart_indices = sparsity_pattern.get_rowstart_indices();
   const unsigned int * const
     col_nums         = sparsity_pattern.get_column_numbers();
@@ -1508,7 +1508,7 @@ SparseDirectMA47::fill_A (const SparseMatrix<double> &matrix)
   const SparsityPattern &sparsity_pattern = matrix.get_sparsity_pattern ();
   
   const unsigned int n_rows = sparsity_pattern.n_rows();
-  const unsigned int *rowstart_indices = sparsity_pattern.get_rowstart_indices();
+  const std::size_t  *rowstart_indices = sparsity_pattern.get_rowstart_indices();
   const unsigned int *col_nums         = sparsity_pattern.get_column_numbers();
 
   unsigned int global_index = 0;
index e49158f19ae3014f6f599eebe0b9c3da8c078997..e8155916729f73c4d9fe6d1bc529423d94b13751 100644 (file)
@@ -299,7 +299,7 @@ SparsityPattern::reinit (
       max_row_length = 0;
       compressed = false;
       return;
-    };
+    }
 
                                   // first, if the matrix is
                                   // quadratic and special treatment
@@ -320,7 +320,7 @@ SparsityPattern::reinit (
                                   // note that the number of elements
                                   // per row is bounded by the number
                                   // of columns
-  unsigned int vec_len = 0;
+  std::size_t vec_len = 0;
   for (unsigned int i=0; i<m; ++i)
     vec_len += std::min((diagonal_optimized ?
                         std::max(row_lengths[i], 1U) :
@@ -337,36 +337,64 @@ SparsityPattern::reinit (
   if (vec_len == 0)
     {
       vec_len = 1;
-      if (colnums) delete[] colnums;
+      if (colnums)
+       {
+         delete[] colnums;
+         colnums = 0;
+       }
+      
       max_vec_len = vec_len;
       colnums = new unsigned int[max_vec_len];
     }
   
   max_row_length = (row_lengths.size() == 0 ?
                    0 :
-                   std::min (*std::max_element(row_lengths.begin(), row_lengths.end()),
+                   std::min (*std::max_element(row_lengths.begin(),
+                                               row_lengths.end()),
                              n));
 
   if (diagonal_optimized && (max_row_length==0) && (m!=0))
     max_row_length = 1;
   
                                   // allocate memory for the rowstart
-                                  // values, if necessary
+                                  // values, if necessary. even
+                                  // though we re-set the pointers
+                                  // again immediately after deleting
+                                  // their old content, set them to
+                                  // zero in between because the
+                                  // allocation might fail, in which
+                                  // case we get an exception and the
+                                  // destructor of this object will
+                                  // be called -- where we look at
+                                  // the non-nullness of the (now
+                                  // invalid) pointer again and try
+                                  // to delete the memory a second
+                                  // time.
   if (rows > max_dim)
     {
-      if (rowstart) delete[] rowstart;
+      if (rowstart)
+       {
+         delete[] rowstart;
+         rowstart = 0;
+       }
+
       max_dim = rows;
-      rowstart = new unsigned int[max_dim+1];
-    };
+      rowstart = new std::size_t[max_dim+1];
+    }
 
                                   // allocate memory for the column
                                   // numbers if necessary
   if (vec_len > max_vec_len)
     {
-      if (colnums) delete[] colnums;
+      if (colnums)
+       {
+         delete[] colnums;
+         colnums = 0;
+       }
+      
       max_vec_len = vec_len;
       colnums = new unsigned int[max_vec_len];
-    };
+    }
 
                                   // set the rowstart array 
   rowstart[0] = 0;
@@ -414,7 +442,7 @@ SparsityPattern::compress ()
                                   // elements there are, in order to
                                   // allocate the right amount of
                                   // memory
-  const unsigned int nonzero_elements
+  const std::size_t nonzero_elements
     = std::count_if (&colnums[rowstart[0]],
                     &colnums[rowstart[rows]],
                     std::bind2nd(std::not_equal_to<unsigned int>(), invalid_entry));
@@ -647,7 +675,7 @@ SparsityPattern::max_entries_per_row () const
                                   // gives us a sharp bound
   unsigned int m = 0;
   for (unsigned int i=1; i<rows; ++i)
-    m = std::max (m, rowstart[i]-rowstart[i-1]);
+    m = std::max (m, static_cast<unsigned int>(rowstart[i]-rowstart[i-1]));
 
   return m;
 }
@@ -939,7 +967,7 @@ SparsityPattern::block_read (std::istream &in)
   if (colnums)
   delete[] colnums;
 
-  rowstart = new unsigned int[max_dim+1];
+  rowstart = new std::size_t[max_dim+1];
   colnums  = new unsigned int[max_vec_len];
   
                                    // then read data

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.