https://github.com/arpit-babbar/conjugategradientsgpu

https://github.com/arpit-babbar/conjugategradientsgpu

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.3%) to scientific vocabulary
Last synced: 9 months ago · JSON representation

Repository

Basic Info
  • Host: GitHub
  • Owner: Arpit-Babbar
  • License: mit
  • Language: Julia
  • Default Branch: master
  • Size: 22.5 KB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created over 1 year ago · Last pushed over 1 year ago
Metadata Files
Readme License

README.md

ConjugateGradients.jl

ConjugateGradients.jl is a flexible, non-allocating Julia implementation of the conjugate gradient and biconjugate gradient stabilized methods.

Requirements

  • Julia 1.2 and up

Installation

julia julia> ] pkg> add ConjugateGradients

Why use ConjugateGradients.jl?

There are a few great iterative solver packages available for Julia: IterativeSolvers.jl, KrylovMethods.jl, and Krylov.jl. These are all very well rounded and complete packages.

This package, ConjugateGradients.jl, is built around reducing allocations as much as possible for a particular type of problem. As far as I know, if your program will be using an iterative solver within another iterative process, this module will result in less allocations compared to the previously mentioned packages*.

Also, in other iterative solvers, calls to BLAS functions are preferred for obvious reasons. This package uses Julia's multiple dispatch functionality to decide whether to use BLAS or native Julia code to make calculations based on the type associated with the arrays. This gives greater flexibility with types not represented by floating point numbers.

* Hint: take a look at ILUZero.jl if this type of solver would be beneficial to your project. Combined, these packages can help reduce allocations in those hot paths.

How to use

julia julia> using ConjugateGradients

For the conjugate gradient method to solve for x in Ax=b:

julia x, exit_code, num_iters = cg(A, b; kwargs...) julia exit_code, num_iters = cg!(A, b, x; kwargs...)

For the biconjugate gradient stabilized method:

julia x, exit_code, num_iters = bicgstab(A, b; kwargs...) julia exit_code, num_iters = bicgstab!(A, b, x; kwargs...)

Where A must be able to be applied as a function such that A(b, x) and the kwargs are: * tol = 1e-6: The tolerance of the minimum residual before convergence is accepted. * maxIter = 100: The maximum number of iterations to perform. * tolRho = 1e-40: [bicgstab only] The tolerance of dot(current residual, initial residual). * precon = nothing: The preconditioner. The preconditioner must act as an in-place function of the form f(out, in). * data = nothing: The preallocation of the arrays used for solving the system.

Preallocating

The data keyword points to an object containing the preallocated vectors necessary for the functions. If nothing is provided, these vectors will be allocated at each call. The data objects can be created like so:

julia CGD = CGData(n, T)

julia BCGD = BiCGStabData(n, T)

Here, n is the dimension of the problem and T is the type of the elements in the problem (e.g. Float64).

Deciphering the exit code

The exit_code can be read with the following function:

julia exit_string = reader(exit_code)

A tip for A and the preconditioner

The operator A and the preconditioner must be expressed as functions. If A is a matrix, one can do:

julia x, exit_code, num_iters = cg((x,y) -> mul!(x,A,y), b; kwargs...)

Another useful representation of A is a custom struct. For example, let's consider (B*C + D)x = b. Instead of wasting time to build B*C + D, we can create a non-allocating version of it.

```julia struct MyA B::SparseMatrixCSC{Float64,Int64} C::SparseMatrixCSC{Float64,Int64} D::SparseMatrixCSC{Float64,Int64} cacheVec::Vector{Float64} end

function (t::MyA)(out::Vector{Float64}, x::Vector{Float64}) mul!(t.cacheVec, t.C, x) mul!(out, t.B, t.cacheVec) mul!(t.cacheVec, t.D, x) out .+= t.cacheVec end

A = MyA(B, C, D, zeros(n)) ```

Owner

  • Name: Arpit Babbar
  • Login: Arpit-Babbar
  • Kind: user

GitHub Events

Total
  • Push event: 3
  • Create event: 1
Last Year
  • Push event: 3
  • Create event: 1

Issues and Pull Requests

Last synced: over 1 year ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Dependencies

.github/workflows/CI.yml actions
  • actions/cache v4 composite
  • actions/checkout v4 composite
  • julia-actions/julia-buildpkg latest composite
  • julia-actions/julia-runtest latest composite
  • julia-actions/setup-julia v2 composite