From f8a0745cb0426eb3095dbea24288a64eddab04f0 Mon Sep 17 00:00:00 2001 From: Desire NUENTSA Date: Wed, 13 Jun 2012 18:26:05 +0200 Subject: Build process... --- Eigen/src/SparseLU/SparseLU_Memory.h | 150 +++++++++++++++++------------------ 1 file changed, 73 insertions(+), 77 deletions(-) (limited to 'Eigen/src/SparseLU/SparseLU_Memory.h') diff --git a/Eigen/src/SparseLU/SparseLU_Memory.h b/Eigen/src/SparseLU/SparseLU_Memory.h index b2888e9a0..ea9ef6d89 100644 --- a/Eigen/src/SparseLU/SparseLU_Memory.h +++ b/Eigen/src/SparseLU/SparseLU_Memory.h @@ -54,9 +54,67 @@ #define LU_GluIntArray(n) (5* (n) + 5) #define LU_TempSpace(m, w) ( (2*w + 4 + LU_NO_MARKER) * m * sizeof(Index) \ + (w + 1) * m * sizeof(Scalar) ) - -namespace internal { + + +/** + * Expand the existing storage to accomodate more fill-ins + * \param vec Valid pointer to the vector to allocate or expand + * \param [in,out]length At input, contain the current length of the vector that is to be increased. At output, length of the newly allocated vector + * \param [in]len_to_copy Current number of elements in the factors + * \param keep_prev true: use length and do not expand the vector; false: compute new_len and expand + * \param [in,out]num_expansions Number of times the memory has been expanded + */ +template +int expand(VectorType& vec, int& length, int len_to_copy, bool keep_prev, int& num_expansions) +{ + + float alpha = 1.5; // Ratio of the memory increase + int new_len; // New size of the allocated memory + if(num_expansions == 0 || keep_prev) + new_len = length ; // First time allocate requested + else + new_len = alpha * length ; + + VectorType old_vec; // Temporary vector to hold the previous values + if (len_to_copy > 0 ) + old_vec = vec; // old_vec should be of size len_to_copy... to be checked + + //expand the current vector //FIXME Should be in a try ... catch region + vec.resize(new_len); + /* + * Test if the memory has been well allocated + * otherwise reduce the size and try to reallocate + * copy data from previous vector (if exists) to the newly allocated vector + */ + if ( num_expansions != 0 ) // The memory has been expanded before + { + int tries = 0; + if (keep_prev) + { + if (!vec.size()) return new_len ; + } + else + { + while (!vec.size()) + { + // Reduce the size and allocate again + if ( ++tries > 10) return new_len; + alpha = LU_Reduce(alpha); + new_len = alpha * length ; + vec.resize(new_len); //FIXME Should be in a try catch section + } + } // end allocation + + //Copy the previous values to the newly allocated space + if (len_to_copy > 0) + vec.segment(0, len_to_copy) = old_vec; + } // end expansion + length = new_len; + if(num_expansions) ++num_expansions; + return 0; +} + /** * \brief Allocate various working space for the numerical factorization phase. * \param m number of rows of the input matrix @@ -70,10 +128,10 @@ namespace internal { * NOTE Unlike SuperLU, this routine does not support successive factorization with the same pattern and the row permutation */ template -int LUMemInit(int m, int n, int annz, ScalarVector& work, IndexVector& iwork, int lwork, int fillratio, int panel_size, int maxsuper, int rowblk, GlobalLU_t& glu) +int LUMemInit(int m, int n, int annz, ScalarVector& work, IndexVector& iwork, int lwork, int fillratio, int panel_size, int maxsuper, int rowblk, LU_GlobalLU_t& glu) { - typedef typename ScalarVector::Scalar; - typedef typename IndexVector::Index; + typedef typename ScalarVector::Scalar Scalar; + typedef typename IndexVector::Index Index; int& num_expansions = glu.num_expansions; //No memory expansions so far num_expansions = 0; @@ -82,14 +140,14 @@ int LUMemInit(int m, int n, int annz, ScalarVector& work, IndexVector& iwork, in Index& nzumax = glu.nzumax; Index& nzlumax = glu.nzlumax; nzumax = nzlumax = fillratio * annz; // estimated number of nonzeros in U - nzlmax = std::max(1, m_fill_ratio/4.) * annz; // estimated nnz in L factor + nzlmax = std::max(1., fillratio/4.) * annz; // estimated nnz in L factor // Return the estimated size to the user if necessary if (lwork == IND_EMPTY) { int estimated_size; - estimated_size = LU_GluIntArray(n) * sizeof(Index) + LU_TempSpace(m, m_panel_size) - + (nzlmax + nzumax) * sizeof(Index) + (nzlumax+nzumax) * sizeof(Scalar) + n); + estimated_size = LU_GluIntArray(n) * sizeof(Index) + LU_TempSpace(m, panel_size) + + (nzlmax + nzumax) * sizeof(Index) + (nzlumax+nzumax) * sizeof(Scalar) + n; return estimated_size; } @@ -126,8 +184,8 @@ int LUMemInit(int m, int n, int annz, ScalarVector& work, IndexVector& iwork, in } // LUWorkInit : Now, allocate known working storage - int isize = (2 * m_panel_size + 3 + LU_NO_MARKER) * m + n; - int dsize = m * m_panel_size + LU_NUM_TEMPV(m, m_panel_size, m_maxsuper, m_rowblk); + int isize = (2 * panel_size + 3 + LU_NO_MARKER) * m + n; + int dsize = m * panel_size + LU_NUM_TEMPV(m, panel_size, maxsuper, rowblk); iwork.resize(isize); work.resize(isize); @@ -136,65 +194,6 @@ int LUMemInit(int m, int n, int annz, ScalarVector& work, IndexVector& iwork, in } // end LuMemInit -/** - * Expand the existing storage to accomodate more fill-ins - * \param vec Valid pointer to the vector to allocate or expand - * \param [in,out]length At input, contain the current length of the vector that is to be increased. At output, length of the newly allocated vector - * \param [in]len_to_copy Current number of elements in the factors - * \param keep_prev true: use length and do not expand the vector; false: compute new_len and expand - * \param [in,out]num_expansions Number of times the memory has been expanded - */ -template -int SparseLU::expand(VectorType& vec, int& length, int len_to_copy, bool keep_prev, int& num_expansions) -{ - - float alpha = 1.5; // Ratio of the memory increase - int new_len; // New size of the allocated memory - - if(num_expansions == 0 || keep_prev) - new_len = length ; // First time allocate requested - else - new_len = alpha * length ; - - VectorType old_vec; // Temporary vector to hold the previous values - if (len_to_copy > 0 ) - old_vec = vec; // old_vec should be of size len_to_copy... to be checked - - //expand the current vector //FIXME Should be in a try ... catch region - vec.resize(new_len); - /* - * Test if the memory has been well allocated - * otherwise reduce the size and try to reallocate - * copy data from previous vector (if exists) to the newly allocated vector - */ - if ( num_expansions != 0 ) // The memory has been expanded before - { - int tries = 0; - if (keep_prev) - { - if (!vec.size()) return new_len ; - } - else - { - while (!vec.size()) - { - // Reduce the size and allocate again - if ( ++tries > 10) return new_len; - alpha = LU_Reduce(alpha); - new_len = alpha * length ; - vec.resize(new_len); //FIXME Should be in a try catch section - } - } // end allocation - - //Copy the previous values to the newly allocated space - if (len_to_copy > 0) - vec.segment(0, len_to_copy) = old_vec; - } // end expansion - length = new_len; - if(num_expansions) ++num_expansions; - return 0; -} - /** * \brief Expand the existing storage * \param vec vector to expand @@ -203,18 +202,17 @@ int SparseLU::expand(VectorType& vec, int& length, int len_to_copy, bool keep_p * \param glu Global data structure * \return 0 on success, > 0 size of the memory allocated so far */ -template -int SparseLU::LUMemXpand(VectorType& vec, int& maxlen, int next, LU_MemType memtype, LU_GlobalLu_t& glu) +template +int LUMemXpand(VectorType& vec, int& maxlen, int next, LU_MemType memtype, int& num_expansions) { int failed_size; - int& num_expansions = glu.num_expansions; if (memtype == USUB) - failed_size = expand(vec, maxlen, next, 1, num_expansions); + failed_size = expand(vec, maxlen, next, 1, num_expansions); else - failed_size = expand(vec, maxlen, next, 0, num_expansions); + failed_size = expand(vec, maxlen, next, 0, num_expansions); if (failed_size) - return faileld_size; + return failed_size; // The following code is not really needed since maxlen is passed by reference // and correspond to the appropriate field in glu @@ -236,6 +234,4 @@ int SparseLU::LUMemXpand(VectorType& vec, int& maxlen, int next, LU_MemType memt return 0 ; } - -}// Namespace Internal #endif \ No newline at end of file -- cgit v1.2.3