SkillAgentSearch skills...

FSPARSE

A Modern Fortran sparse matrices gallery

Install / Use

/learn @jalvesz/FSPARSE
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

fsparse DOI

FSPARSE: Fortran Sparse Gallery library

FSparse is an initiative to build a OOP API of sparse matrices with some basic kernels and utility functions using Modern Fortran.

This project is very much a work in progress, contributions are wellcome.

Available Matrices

| Matrix type | no data | real | complex | |-------------|---------|------|---------| | COO | COO_t | COO_?p | COO_c?p | | CSR | CSR_t | CSR_?p | CSR_c?p | | CSC | CSC_t | CSC_?p | CSC_c?p | | ELL | ELL_t | ELL_?p | ELL_c?p | | SELL-C | SELLC_t | SELLC_?p | SELLC_c?p |

COO: COordinate Sparse format

CSR: Compressed Sparse Row format

CSC: Compressed Sparse Column format

ELL: ELLPACK

SELL-C: sliced ELLPACK format

(Where ? stands for the precision s,d,q)

Available Kernels

Conversion

Conversion subroutines follow the naming pattern _sourcetype2targettype_m ex:

call dense2coo( dense , coo )

| Matrix | dense | COO | CSR | |--------|-------|-------|-------| | dense | | ✅ | | | COO | ✅ | | ✅ | | CSR | | ✅ | | | CSC | | | | | ELL | | | | | SELL-C | | | ✅ |

Sparse Matrix-Vector product

(available) Matrix vector products are interfaced by the procedure

call matvec( Mat , vec_x, vec_y ) ! vec_y = vec_y + Mat * vec_x

| Matrix | full | symmetric | |--------|-------|------------------| | COO | ✅ | ✅ | | CSR | ✅ | ✅ | | CSC | ✅ | (?) | | ELL | ✅ | ❌ | | SELL-C | ✅ | ❌ |

A taste of FSPARSE

use fsparse
use iso_fortran_env, only: sp=>real32
type(COO_sp) :: COO
real(sp), allocatable :: dense(:,:)

allocate( dense(4,5) )
dense = reshape([9.0,4.0,0.0,4.0,0.0, &
                 7.0,8.0,0.0,0.0,0.0, &
                 -1.0,5.0,0.0,0.0,8.0,&
                 6.0,-3.0,0.0,0.0,0.0],[4,5])

call dense2coo( dense , COO )
use fsparse
use iso_fortran_env, only: dp=>real64
type(COO_dp) :: CSR
real(dp), allocatable :: vec_x(:)
real(dp), allocatable :: vec_y(:)

call CSR%malloc(4,5,10)
CSR%data(:)   = dble([9,-3,4,7,8,-1,8,4,5,6])
CSR%col(:)    = [1,5,1,2,2,3,4,1,3,4]
CSR%rowptr(:) = [1,3,5,8,11]

allocate( vec_x(5) , source = 1._dp )
allocate( vec_y(4) , source = 0._dp )
call matvec( CSR , vec_x, vec_y )

Building and using

FYPP is used to enable a generic programming framework, strongly inspired by the stdlib approach. A simple script is distributed to preprocess all .fypp files into .f90 before building.

Only simple and double preceision

python deployement.py

Adding quad precission support

python deployement.py --with_qp

The project was built using the Fortran Package Manager. A manifest file is included to build and test with FPM. For example:

fpm build --profile release
fpm test --profile release

To use fsparse within your FPM project, add the following to your fpm.toml file:

[dependencies]
fsparse = { git="https://github.com/jalvesz/FSPARSE" }

Inspiration & References

Iterative Methods for Sparse Linear Systems

Efficient Sparse Matrix-Vector Multiplication on cuda

gsl sparse matrices

Calcul Scientifique Parallèle

Implementing a Sparse Matrix Vector Product for the SELL-C/SELL-C-σ formats on NVIDIA GPUs

Authors and contributors

Acknowledgement

Compilation of this library was possible thanks to Transvalor S.A. research activities

View on GitHub
GitHub Stars35
CategoryDevelopment
Updated2mo ago
Forks3

Languages

Fortran

Security Score

80/100

Audited on Jan 4, 2026

No findings