Skip to content

Commit 669b876

Browse files
authored
v1.5.5 update
v1.5.5 update: - pcgsolve with sparse matrix and OMP implementation now available for "Jacobi" preconditioner; - general performance improvements and bug fixes
1 parent 9e0f90f commit 669b876

File tree

9 files changed

+240
-115
lines changed

9 files changed

+240
-115
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: cPCG
22
Type: Package
33
Title: Efficient and Customized Preconditioned Conjugate Gradient Method for Solving System of Linear Equations
4-
Version: 1.5.0
5-
Date: 2019-04-09
4+
Version: 1.5.5
5+
Date: 2019-04-12
66
Author: Yongwen Zhuang
77
Maintainer: Yongwen Zhuang <[email protected]>
88
Description: Solves system of linear equations using (preconditioned) conjugate gradient algorithm, with improved efficiency using Armadillo templated 'C++' linear algebra library, and flexibility for utilizing openMP for sparse matrix format, and user-specified preconditioning method. Please check <https://github.com/styvon/cPCG> for latest updates.

R/RcppExports.R

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,31 @@ pcgsolve <- function(A, b, preconditioner = "Jacobi", tol = 1e-6, maxIter = 1000
5656
#' @param tol Tolerance for conjugate gradient algorithm.
5757
#' @param maxIter Max number of iterations for conjugate gradient algorithm.
5858
#' @param nThreads Number of threads for OMP.
59-
#' @param nSubThreads Number of threads for OMP nested tasks.
6059
#' @return A n-vector of A_inv b
61-
cgsolve_sparseOMP <- function(A, b, tol = 1e-6, maxIter = 1000L, nThreads = 1L, nSubThreads = 1L) {
62-
.Call(`_cPCG_cgsolve_sparseOMP`, A, b, tol, maxIter, nThreads, nSubThreads)
60+
cgsolve_sparseOMP <- function(A, b, tol = 1e-6, maxIter = 1000L, nThreads = 1L) {
61+
.Call(`_cPCG_cgsolve_sparseOMP`, A, b, tol, maxIter, nThreads)
62+
}
63+
64+
#' Preconditioned conjugate gradient method
65+
#'
66+
#' Preconditioned conjugate gradient method for solving system of linear equations Ax = b,
67+
#' where A is symmetric and positive definite.
68+
#'
69+
#' @title Solve for x in Ax = b using preconditioned conjugate gradient method.
70+
#' @param A matrix, symmetric and positive definite.
71+
#' @param b vector, with same dimension as number of rows of A.
72+
#' @param preconditioner string, method for preconditioning: \code{"Jacobi"} (default), \code{"SSOR"}, or \code{"ICC"}.
73+
#' @param tol numeric, threshold for convergence, default is \code{1e-6}.
74+
#' @param maxIter numeric, maximum iteration, default is \code{1000}.
75+
#' @param nThreads Number of threads for OMP.
76+
#' @return A vector representing solution x.
77+
#' @examples
78+
#' \dontrun{
79+
#' test_A <- matrix(c(4,1,1,3), ncol = 2)
80+
#' test_b <- matrix(1:2, ncol = 1)
81+
#' pcgsolve_sparseOMP(test_A, test_b, "ICC",nThreads=2)
82+
#' }
83+
pcgsolve_sparseOMP <- function(A, b, preconditioner = "Jacobi", tol = 1e-6, maxIter = 1000L, nThreads = 1L) {
84+
.Call(`_cPCG_pcgsolve_sparseOMP`, A, b, preconditioner, tol, maxIter, nThreads)
6385
}
6486

man/cgsolve_sparseOMP.Rd

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/pcgsolve_sparseOMP.Rd

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/RcppExports.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ BEGIN_RCPP
4747
END_RCPP
4848
}
4949
// cgsolve_sparseOMP
50-
arma::vec cgsolve_sparseOMP(const arma::sp_mat& A, const arma::vec& b, float tol, int maxIter, int nThreads, int nSubThreads);
51-
RcppExport SEXP _cPCG_cgsolve_sparseOMP(SEXP ASEXP, SEXP bSEXP, SEXP tolSEXP, SEXP maxIterSEXP, SEXP nThreadsSEXP, SEXP nSubThreadsSEXP) {
50+
arma::vec cgsolve_sparseOMP(const arma::sp_mat& A, const arma::vec& b, float tol, int maxIter, int nThreads);
51+
RcppExport SEXP _cPCG_cgsolve_sparseOMP(SEXP ASEXP, SEXP bSEXP, SEXP tolSEXP, SEXP maxIterSEXP, SEXP nThreadsSEXP) {
5252
BEGIN_RCPP
5353
Rcpp::RObject rcpp_result_gen;
5454
Rcpp::RNGScope rcpp_rngScope_gen;
@@ -57,8 +57,23 @@ BEGIN_RCPP
5757
Rcpp::traits::input_parameter< float >::type tol(tolSEXP);
5858
Rcpp::traits::input_parameter< int >::type maxIter(maxIterSEXP);
5959
Rcpp::traits::input_parameter< int >::type nThreads(nThreadsSEXP);
60-
Rcpp::traits::input_parameter< int >::type nSubThreads(nSubThreadsSEXP);
61-
rcpp_result_gen = Rcpp::wrap(cgsolve_sparseOMP(A, b, tol, maxIter, nThreads, nSubThreads));
60+
rcpp_result_gen = Rcpp::wrap(cgsolve_sparseOMP(A, b, tol, maxIter, nThreads));
61+
return rcpp_result_gen;
62+
END_RCPP
63+
}
64+
// pcgsolve_sparseOMP
65+
arma::vec pcgsolve_sparseOMP(const arma::sp_mat& A, arma::vec b, std::string preconditioner, float tol, int maxIter, int nThreads);
66+
RcppExport SEXP _cPCG_pcgsolve_sparseOMP(SEXP ASEXP, SEXP bSEXP, SEXP preconditionerSEXP, SEXP tolSEXP, SEXP maxIterSEXP, SEXP nThreadsSEXP) {
67+
BEGIN_RCPP
68+
Rcpp::RObject rcpp_result_gen;
69+
Rcpp::RNGScope rcpp_rngScope_gen;
70+
Rcpp::traits::input_parameter< const arma::sp_mat& >::type A(ASEXP);
71+
Rcpp::traits::input_parameter< arma::vec >::type b(bSEXP);
72+
Rcpp::traits::input_parameter< std::string >::type preconditioner(preconditionerSEXP);
73+
Rcpp::traits::input_parameter< float >::type tol(tolSEXP);
74+
Rcpp::traits::input_parameter< int >::type maxIter(maxIterSEXP);
75+
Rcpp::traits::input_parameter< int >::type nThreads(nThreadsSEXP);
76+
rcpp_result_gen = Rcpp::wrap(pcgsolve_sparseOMP(A, b, preconditioner, tol, maxIter, nThreads));
6277
return rcpp_result_gen;
6378
END_RCPP
6479
}
@@ -67,7 +82,8 @@ static const R_CallMethodDef CallEntries[] = {
6782
{"_cPCG_icc", (DL_FUNC) &_cPCG_icc, 1},
6883
{"_cPCG_cgsolve", (DL_FUNC) &_cPCG_cgsolve, 4},
6984
{"_cPCG_pcgsolve", (DL_FUNC) &_cPCG_pcgsolve, 5},
70-
{"_cPCG_cgsolve_sparseOMP", (DL_FUNC) &_cPCG_cgsolve_sparseOMP, 6},
85+
{"_cPCG_cgsolve_sparseOMP", (DL_FUNC) &_cPCG_cgsolve_sparseOMP, 5},
86+
{"_cPCG_pcgsolve_sparseOMP", (DL_FUNC) &_cPCG_pcgsolve_sparseOMP, 6},
7187
{NULL, NULL, 0}
7288
};
7389

src/RcppExports.o

5.13 KB
Binary file not shown.

src/cPCG.so

-11.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)