Skip to content

Commit

Permalink
update to current 1.7.0 released version
Browse files Browse the repository at this point in the history
  • Loading branch information
cdeterman committed Sep 3, 2015
1 parent 7e03678 commit 5da1135
Show file tree
Hide file tree
Showing 34 changed files with 1,405 additions and 1,492 deletions.
26 changes: 25 additions & 1 deletion inst/include/viennacl/compressed_matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,30 @@ class compressed_matrix
}
#endif

/** @brief Assignment a compressed matrix from the product of two compressed_matrix objects (C = A * B). */
compressed_matrix(matrix_expression<const compressed_matrix, const compressed_matrix, op_prod> const & proxy)
: rows_(0), cols_(0), nonzeros_(0), row_block_num_(0)
{
viennacl::context ctx = viennacl::traits::context(proxy.lhs());

row_buffer_.switch_active_handle_id(ctx.memory_type());
col_buffer_.switch_active_handle_id(ctx.memory_type());
elements_.switch_active_handle_id(ctx.memory_type());
row_blocks_.switch_active_handle_id(ctx.memory_type());

#ifdef VIENNACL_WITH_OPENCL
if (ctx.memory_type() == OPENCL_MEMORY)
{
row_buffer_.opencl_handle().context(ctx.opencl_context());
col_buffer_.opencl_handle().context(ctx.opencl_context());
elements_.opencl_handle().context(ctx.opencl_context());
row_blocks_.opencl_handle().context(ctx.opencl_context());
}
#endif

viennacl::linalg::prod_impl(proxy.lhs(), proxy.rhs(), *this);
generate_row_block_information();
}

/** @brief Assignment a compressed matrix from possibly another memory domain. */
compressed_matrix & operator=(compressed_matrix const & other)
Expand Down Expand Up @@ -1022,7 +1046,7 @@ class compressed_matrix
/** @brief Output stream support for compressed_matrix. Output format is same as MATLAB, Octave, or SciPy
*
* @param os STL output stream
* @param val The vector that should be printed
* @param A The compressed matrix to be printed.
*/
template<typename NumericT, unsigned int AlignmentV>
std::ostream & operator<<(std::ostream & os, compressed_matrix<NumericT, AlignmentV> const & A)
Expand Down
77 changes: 41 additions & 36 deletions inst/include/viennacl/linalg/amg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ class amg_coarse_problem_too_large_exception : public std::runtime_error

namespace detail
{
/** @brief Sparse Galerkin product: Calculates A_coarse = trans(P)*A_fine*P
* @param A Operator matrix on fine grid (quadratic)
* @param P Prolongation/Interpolation matrix
* @param C_coarse Result Matrix (Galerkin operator)
/** @brief Sparse Galerkin product: Calculates A_coarse = trans(P)*A_fine*P = R*A_fine*P
*
* @param A_fine Operator matrix on fine grid (quadratic)
* @param P Prolongation/Interpolation matrix
* @param R Restriction matrix
* @param A_coarse Result matrix on coarse grid (Galerkin operator)
*/
template<typename NumericT>
void amg_galerkin_prod(compressed_matrix<NumericT> & A_fine,
Expand All @@ -93,10 +95,11 @@ namespace detail

/** @brief Setup AMG preconditioner
*
* @param A Operator matrices on all levels
* @param P Prolongation/Interpolation operators on all levels
* @param pointvector Vector of points on all levels
* @param tag AMG preconditioner tag
* @param list_of_A Operator matrices on all levels
* @param list_of_P Prolongation/Interpolation operators on all levels
* @param list_of_R Restriction operators on all levels
* @param list_of_amg_level_context Auxiliary datastructures for managing the grid hierarchy (coarse nodes, etc.)
* @param tag AMG preconditioner tag
*/
template<typename NumericT, typename AMGContextListT>
vcl_size_t amg_setup(std::vector<compressed_matrix<NumericT> > & list_of_A,
Expand All @@ -120,9 +123,9 @@ namespace detail

// Calculate number of C and F points on level i.
unsigned int c_points = list_of_amg_level_context[i].num_coarse_;
unsigned int f_points = list_of_A[i].size1() - c_points;
unsigned int f_points = static_cast<unsigned int>(list_of_A[i].size1()) - c_points;

if (f_points == 0 && c_points > tag.get_coarseing_cutoff())
if (f_points == 0 && c_points > tag.get_coarsening_cutoff())
{
std::stringstream ss;
ss << "No further coarsening possible (" << c_points << " coarse points). Consider changing the strong connection threshold or increasing the coarsening cutoff." << std::endl;
Expand All @@ -145,7 +148,7 @@ namespace detail
list_of_R[i].switch_memory_context(tag.get_target_context());

// If Limit of coarse points is reached then stop. Coarsest level is level i+1.
if (tag.get_coarse_levels() == 0 && c_points <= tag.get_coarseing_cutoff())
if (tag.get_coarse_levels() == 0 && c_points <= tag.get_coarsening_cutoff())
return i+1;
}

Expand All @@ -155,41 +158,42 @@ namespace detail

/** @brief Initialize AMG preconditioner
*
* @param mat System matrix
* @param A Operator matrices on all levels
* @param P Prolongation/Interpolation operators on all levels
* @param pointvector Vector of points on all levels
* @param tag AMG preconditioner tag
* @param mat System matrix
* @param list_of_A Operator matrices on all levels
* @param list_of_P Prolongation/Interpolation operators on all levels
* @param list_of_R Restriction operators on all levels
* @param list_of_amg_level_context Auxiliary datastructures for managing the grid hierarchy (coarse nodes, etc.)
* @param tag AMG preconditioner tag
*/
template<typename MatrixT, typename InternalT1, typename InternalT2>
void amg_init(MatrixT const & mat, InternalT1 & A, InternalT1 & P, InternalT1 & R, InternalT2 & amg_context, amg_tag & tag)
void amg_init(MatrixT const & mat, InternalT1 & list_of_A, InternalT1 & list_of_P, InternalT1 & list_of_R, InternalT2 & list_of_amg_level_context, amg_tag & tag)
{
//typedef typename MatrixType::value_type ScalarType;
typedef typename InternalT1::value_type SparseMatrixType;

vcl_size_t num_levels = (tag.get_coarse_levels() > 0) ? tag.get_coarse_levels() : VIENNACL_AMG_MAX_LEVELS;

A.resize(num_levels+1, SparseMatrixType(tag.get_setup_context()));
P.resize(num_levels, SparseMatrixType(tag.get_setup_context()));
R.resize(num_levels, SparseMatrixType(tag.get_setup_context()));
amg_context.resize(num_levels);
list_of_A.resize(num_levels+1, SparseMatrixType(tag.get_setup_context()));
list_of_P.resize(num_levels, SparseMatrixType(tag.get_setup_context()));
list_of_R.resize(num_levels, SparseMatrixType(tag.get_setup_context()));
list_of_amg_level_context.resize(num_levels);

// Insert operator matrix as operator for finest level.
//SparseMatrixType A0(mat);
//A.insert_element(0, A0);
A[0].switch_memory_context(viennacl::traits::context(mat));
A[0] = mat;
A[0].switch_memory_context(tag.get_setup_context());
list_of_A[0].switch_memory_context(viennacl::traits::context(mat));
list_of_A[0] = mat;
list_of_A[0].switch_memory_context(tag.get_setup_context());
}

/** @brief Setup data structures for precondition phase for later use on the GPU
*
* @param result Result vector on all levels
* @param rhs RHS vector on all levels
* @param residual Residual vector on all levels
* @param A Operators matrices on all levels from setup phase
* @param tag AMG preconditioner tag
* @param ctx Optional context in which the auxiliary objects are created (one out of multiple OpenCL contexts, CUDA, host)
* @param result Result vector on all levels
* @param result_backup Copy of result vector on all levels
* @param rhs RHS vector on all levels
* @param residual Residual vector on all levels
* @param A Operators matrices on all levels from setup phase
* @param coarse_levels Number of coarse levels for which the datastructures should be set up.
* @param tag AMG preconditioner tag
*/
template<typename InternalVectorT, typename SparseMatrixT>
void amg_setup_apply(InternalVectorT & result,
Expand Down Expand Up @@ -221,11 +225,12 @@ namespace detail


/** @brief Pre-compute LU factorization for direct solve (ublas library).
* @brief Speeds up precondition phase as this is computed only once overall instead of once per iteration.
*
* Speeds up precondition phase as this is computed only once overall instead of once per iteration.
*
* @param op Operator matrix for direct solve
* @param permutation Permutation matrix which saves the factorization result
* @param A Operator matrix on coarsest level
* @param tag AMG preconditioner tag
*/
template<typename NumericT, typename SparseMatrixT>
void amg_lu(viennacl::matrix<NumericT> & op,
Expand Down Expand Up @@ -294,7 +299,7 @@ class amg_precond< compressed_matrix<NumericT, AlignmentV> >

/** @brief Precondition Operation
*
* @param vec The vector to which preconditioning is applied to
* @param vec The vector to which preconditioning is applied to
*/
template<typename VectorT>
void apply(VectorT & vec) const
Expand All @@ -310,7 +315,7 @@ class amg_precond< compressed_matrix<NumericT, AlignmentV> >
result_list_[level].clear();

// Apply Smoother presmooth_ times.
viennacl::linalg::detail::amg::smooth_jacobi(tag_.get_presmooth_steps(),
viennacl::linalg::detail::amg::smooth_jacobi(static_cast<unsigned int>(tag_.get_presmooth_steps()),
A_list_[level],
result_list_[level],
result_backup_list_[level],
Expand Down Expand Up @@ -341,7 +346,7 @@ class amg_precond< compressed_matrix<NumericT, AlignmentV> >
result_list_[level] += result_backup_list_[level];

// Apply Smoother postsmooth_ times.
viennacl::linalg::detail::amg::smooth_jacobi(tag_.get_postsmooth_steps(),
viennacl::linalg::detail::amg::smooth_jacobi(static_cast<unsigned int>(tag_.get_postsmooth_steps()),
A_list_[level],
result_list_[level],
result_backup_list_[level],
Expand Down
2 changes: 1 addition & 1 deletion inst/include/viennacl/linalg/amg_operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define VIENNACL_LINALG_AMG_OPERATIONS_HPP_

/* =========================================================================
Copyright (c) 2010-2014, Institute for Microelectronics,
Copyright (c) 2010-2015, Institute for Microelectronics,
Institute for Analysis and Scientific Computing,
TU Wien.
Portions of this software are copyright by UChicago Argonne, LLC.
Expand Down
Loading

0 comments on commit 5da1135

Please sign in to comment.