Beispiel #1
0
LisMatrix::~LisMatrix()
{
    int ierr = lis_matrix_destroy(_AA);
    checkLisError(ierr);
    ierr = lis_vector_destroy(_diag);
    checkLisError(ierr);
}
Beispiel #2
0
LisMatrix::~LisMatrix()
{
    int ierr = 0;
    if (_use_external_arrays)
        ierr = lis_matrix_unset(_AA);
    ierr = lis_matrix_destroy(_AA);
    checkLisError(ierr);
    ierr = lis_vector_destroy(_diag);
    checkLisError(ierr);
}
Beispiel #3
0
LisMatrix::LisMatrix(std::size_t n_rows, LisOption::MatrixType mat_type)
    : _n_rows(n_rows), _mat_type(mat_type), _is_assembled(false)
{
    int ierr = lis_matrix_create(0, &_AA);
    checkLisError(ierr);
    ierr = lis_matrix_set_size(_AA, 0, n_rows);
    checkLisError(ierr);
    lis_matrix_get_range(_AA, &_is, &_ie);
    ierr = lis_vector_duplicate(_AA, &_diag);
    checkLisError(ierr);
}
Beispiel #4
0
bool finalizeMatrixAssembly(LisMatrix &mat)
{
    LIS_MATRIX &A = mat.getRawMatrix();

    if (!mat.isAssembled()) {
        int ierr = lis_matrix_set_type(A, static_cast<int>(mat.getMatrixType()));
        checkLisError(ierr);
        ierr = lis_matrix_assemble(A);
        checkLisError(ierr);
        mat._is_assembled = true;
    }
    return true;
}
Beispiel #5
0
void LisMatrix::setZero()
{
    // A matrix has to be destroyed and created again because Lis doesn't provide a
    // function to set matrix entries to zero
    int ierr = lis_matrix_destroy(_AA);
    checkLisError(ierr);
    ierr = lis_matrix_create(0, &_AA);
    checkLisError(ierr);
    ierr = lis_matrix_set_size(_AA, 0, _n_rows);
    checkLisError(ierr);
    ierr = lis_vector_set_all(0.0, _diag);
    checkLisError(ierr);

    _is_assembled = false;
}
Beispiel #6
0
void LisMatrix::multiply(const LisVector &x, LisVector &y) const
{
    if (!_is_assembled)
        throw std::logic_error("LisMatrix::matvec(): matrix not assembled.");
    int ierr = lis_matvec(_AA, const_cast<LisVector*>(&x)->getRawVector(), y.getRawVector());
    checkLisError(ierr);
}
Beispiel #7
0
double LisMatrix::getMaxDiagCoeff()
{
    double abs_max_entry;
    int ierr = lis_vector_get_value(_diag, 0, &abs_max_entry);
    checkLisError(ierr);
    abs_max_entry = std::abs(abs_max_entry);
    for (std::size_t k(1); k<_n_rows; ++k) {
        double tmp;
        ierr = lis_vector_get_value(_diag, k, &tmp);
        checkLisError(ierr);
        if (abs_max_entry < std::abs(tmp)) {
            abs_max_entry = std::abs(tmp);
        }
    }

    return abs_max_entry;
}
Beispiel #8
0
std::size_t LisVector::size() const
{
	LIS_INT dummy;
	LIS_INT size;
	int const ierr = lis_vector_get_size(_vec, &dummy, &size);
	checkLisError(ierr);
	return size;
}
Beispiel #9
0
std::size_t LisVector::size() const
{
    IndexType dummy;
    IndexType size;
    int const ierr = lis_vector_get_size(_vec, &dummy, &size);
    checkLisError(ierr);
    assert(size >= 0);  // For safe implicit conversion to std::size_t.
    return size;
}
Beispiel #10
0
LisMatrix::LisMatrix(std::size_t n_rows, int nnz, IndexType *row_ptr,
                     IndexType *col_idx, double *data)
    : _n_rows(n_rows),
      _mat_type(MatrixType::CRS),
      _is_assembled(false),
      _use_external_arrays(true)
{
    int ierr = lis_matrix_create(0, &_AA);
    checkLisError(ierr);
    ierr = lis_matrix_set_size(_AA, 0, n_rows);
    checkLisError(ierr);
    ierr = lis_matrix_set_csr(nnz, row_ptr, col_idx, data, _AA);
    checkLisError(ierr);
    ierr = lis_matrix_assemble(_AA);
    checkLisError(ierr);
    _is_assembled = true;
    lis_matrix_get_range(_AA, &_is, &_ie);
    ierr = lis_vector_duplicate(_AA, &_diag);
    checkLisError(ierr);
}
Beispiel #11
0
bool LisLinearSolver::solve(LisMatrix &A, LisVector &b, LisVector &x)
{
    finalizeMatrixAssembly(A);

    INFO("------------------------------------------------------------------");
    INFO("*** LIS solver computation");

    // Create solver
    LIS_SOLVER solver;
    int ierr = lis_solver_create(&solver);
    if (!checkLisError(ierr))
        return false;

    lis_solver_set_option(
        const_cast<char*>(_lis_option._option_string.c_str()), solver);
#ifdef _OPENMP
    INFO("-> number of threads: %i", (int) omp_get_max_threads());
#endif
    {
        int precon;
        ierr = lis_solver_get_precon(solver, &precon);
        INFO("-> precon: %i", precon);
    }
    {
        int slv;
        ierr = lis_solver_get_solver(solver, &slv);
        INFO("-> solver: %i", slv);
    }

    // solve
    INFO("-> solve");
    ierr = lis_solve(A.getRawMatrix(), b.getRawVector(), x.getRawVector(), solver);
    if (!checkLisError(ierr))
        return false;

    LIS_INT linear_solver_status;
    ierr = lis_solver_get_status(solver, &linear_solver_status);
    if (!checkLisError(ierr))
        return false;

    INFO("-> status: %d", linear_solver_status);

    {
        int iter = 0;
        ierr = lis_solver_get_iter(solver, &iter);
        if (!checkLisError(ierr))
            return false;

        INFO("-> iteration: %d", iter);
    }
    {
        double resid = 0.0;
        ierr = lis_solver_get_residualnorm(solver, &resid);
        if (!checkLisError(ierr))
            return false;
        INFO("-> residual: %g", resid);
    }
    {
        double time, itime, ptime, p_ctime, p_itime;
        ierr = lis_solver_get_timeex(solver, &time, &itime,
                                     &ptime, &p_ctime, &p_itime);
        if (!checkLisError(ierr))
            return false;
        INFO("-> time total           (s): %g", time);
        INFO("-> time iterations      (s): %g", itime);
        INFO("-> time preconditioning (s): %g", ptime);
        INFO("-> time precond. create (s): %g", p_ctime);
        INFO("-> time precond. iter   (s): %g", p_itime);
    }

    // Clear solver
    ierr = lis_solver_destroy(solver);
    if (!checkLisError(ierr))
        return false;
    INFO("------------------------------------------------------------------");

    return linear_solver_status == LIS_SUCCESS;
}