Skip to content

Commit

Permalink
Single Index Layout and refactor of operator framework
Browse files Browse the repository at this point in the history
* WIP: Refactor

* WIP: Refactor

* Tests are passing.

* Fixed warnings

* Small improvements.

* Better inner product call

* Fixed traits in CG code.
  • Loading branch information
tbetcke authored Jan 12, 2025
1 parent edfd2fc commit f095807
Show file tree
Hide file tree
Showing 25 changed files with 381 additions and 376 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ jobs:
components: rustfmt
- name: Install cargo-upgrades
run: cargo install cargo-upgrades
- uses: actions/checkout@v3
- name: Check that dependencies are up to date
run: cargo upgrades
# - uses: actions/checkout@v3
# - name: Check that dependencies are up to date
# run: cargo upgrades
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ paste = "1"
rand = "0.8"

[build-dependencies]
cc = "1.0"
cc = "=1.2.7"
bindgen = "0.71"
cmake = "0.1"
git2 = "0.20"
Expand Down
12 changes: 6 additions & 6 deletions examples/cg_distributed.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Example of a distributed CG iteration across several MPI ranks.
use std::rc::Rc;

use mpi::topology::Communicator;
use rand::Rng;
use rlst::operator::interface::DistributedArrayVectorSpace;
use rlst::operator::Operator;
use rlst::{
CgIteration, DistributedCsrMatrix, Element, EquiDistributedIndexLayout, LinearSpace,
OperatorBase,
};
use rlst::{CgIteration, DistributedCsrMatrix, Element, IndexLayout, LinearSpace, OperatorBase};

pub fn main() {
let universe = mpi::initialize().unwrap();
Expand All @@ -21,7 +21,7 @@ pub fn main() {
let n = 500;
let tol = 1E-5;

let index_layout = EquiDistributedIndexLayout::new(n, 1, &world);
let index_layout = Rc::new(IndexLayout::from_equidistributed_chunks(n, 1, &world));

let mut residuals = Vec::<f64>::new();

Expand Down Expand Up @@ -54,7 +54,7 @@ pub fn main() {
let op = Operator::from(distributed_mat);

// Let's create a right-hand side.
let mut rhs = op.range().zero();
let mut rhs = DistributedArrayVectorSpace::zero(op.range());
rhs.view_mut()
.local_mut()
.fill_from_equally_distributed(&mut rng);
Expand Down
10 changes: 6 additions & 4 deletions examples/distributed_csr_matmul.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Demonstrate the creation of a distributed CSR matrix and its multiplication with a vector.
use std::rc::Rc;

use mpi::traits::Communicator;
use rlst::{assert_array_relative_eq, prelude::*};

Expand All @@ -13,13 +15,13 @@ fn main() {

let dist_mat;

let domain_layout = EquiDistributedIndexLayout::new(313, 1, &world);
let domain_layout = Rc::new(IndexLayout::from_equidistributed_chunks(313, 1, &world));

let mut dist_x = DistributedVector::<_, f64>::new(&domain_layout);
let mut dist_x = DistributedVector::<_, f64>::new(domain_layout.clone());

let range_layout = EquiDistributedIndexLayout::new(507, 1, &world);
let range_layout = Rc::new(IndexLayout::from_equidistributed_chunks(507, 1, &world));

let mut dist_y = DistributedVector::<_, f64>::new(&range_layout);
let mut dist_y = DistributedVector::<_, f64>::new(range_layout.clone());

if rank == 0 {
// Read the sparse matrix in matrix market format.
Expand Down
6 changes: 4 additions & 2 deletions examples/mpi_gather_to_all_vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
mod approx_inv_sqrt_accuracy;

use std::rc::Rc;

use approx::assert_relative_eq;

use mpi::traits::Communicator;
Expand All @@ -16,9 +18,9 @@ pub fn main() {

let rank = world.rank() as usize;

let index_layout = EquiDistributedIndexLayout::new(NDIM, 1, &world);
let index_layout = Rc::new(IndexLayout::from_equidistributed_chunks(NDIM, 1, &world));

let vec = DistributedVector::<_, f64>::new(&index_layout);
let vec = DistributedVector::<_, f64>::new(index_layout.clone());

let local_index_range = vec.index_layout().index_range(rank).unwrap();

Expand Down
6 changes: 4 additions & 2 deletions examples/mpi_gather_vector.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Gather a vector on the root rank.
use std::rc::Rc;

use approx::assert_relative_eq;

use mpi::traits::Communicator;
Expand All @@ -15,9 +17,9 @@ pub fn main() {

let rank = world.rank() as usize;

let index_layout = EquiDistributedIndexLayout::new(NDIM, 1, &world);
let index_layout = Rc::new(IndexLayout::from_equidistributed_chunks(NDIM, 1, &world));

let vec = DistributedVector::<_, f64>::new(&index_layout);
let vec = DistributedVector::<_, f64>::new(index_layout.clone());

let local_index_range = vec.index_layout().index_range(rank).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion examples/mpi_index_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn main() {
let universe = mpi::initialize().unwrap();
let world = universe.world();

let index_layout = EquiDistributedIndexLayout::new(NCHUNKS, CHUNK_SIZE, &world);
let index_layout = IndexLayout::from_equidistributed_chunks(NCHUNKS, CHUNK_SIZE, &world);

if world.rank() == 0 {
println!("Local index range: {:#?}", index_layout.local_range());
Expand Down
6 changes: 4 additions & 2 deletions examples/mpi_scatter_vector.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Scatter a vector on the root rank.
use std::rc::Rc;

use approx::assert_relative_eq;

use mpi::traits::Communicator;
Expand All @@ -15,9 +17,9 @@ pub fn main() {

let rank = world.rank() as usize;

let index_layout = EquiDistributedIndexLayout::new(NDIM, 1, &world);
let index_layout = Rc::new(IndexLayout::from_equidistributed_chunks(NDIM, 1, &world));

let mut vec = DistributedVector::<_, f64>::new(&index_layout);
let mut vec = DistributedVector::<_, f64>::new(index_layout);

let local_index_range = vec.index_layout().index_range(rank).unwrap();

Expand Down
Loading

0 comments on commit f095807

Please sign in to comment.