Skip to content

Commit

Permalink
fix with --features "mpi"
Browse files Browse the repository at this point in the history
  • Loading branch information
mscroggs committed Mar 21, 2024
1 parent d50c7c2 commit 5eb2d3e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
13 changes: 11 additions & 2 deletions sparse/src/distributed_vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,41 @@
use crate::traits::index_layout::IndexLayout;

use mpi::datatype::{Partition, PartitionMut};
use mpi::traits::*;
use mpi::traits::{Communicator, Equivalence, Root};
use rlst_dense::array::DynamicArray;
use rlst_dense::types::{RlstResult, RlstScalar};
use rlst_dense::{rlst_dynamic_array1, traits::*};
use rlst_dense::{
rlst_dynamic_array1,
traits::{RawAccess, RawAccessMut, Shape},
};

use crate::index_layout::DefaultMpiIndexLayout;

/// Distributed vector
pub struct DistributedVector<'a, Item: RlstScalar + Equivalence, C: Communicator> {
index_layout: &'a DefaultMpiIndexLayout<'a, C>,
local: DynamicArray<Item, 1>,
}

impl<'a, Item: RlstScalar + Equivalence, C: Communicator> DistributedVector<'a, Item, C> {
/// Crate new
pub fn new(index_layout: &'a DefaultMpiIndexLayout<'a, C>) -> Self {
DistributedVector {
index_layout,
local: rlst_dynamic_array1!(Item, [index_layout.number_of_local_indices()]),
}
}
/// Local part
pub fn local(&self) -> &DynamicArray<Item, 1> {
&self.local
}

/// Mutable local part
pub fn local_mut(&mut self) -> &mut DynamicArray<Item, 1> {
&mut self.local
}

/// Send to root
pub fn to_root(&self) -> Option<DynamicArray<Item, 1>> {
let comm = self.index_layout().comm();
let root_process = comm.process_at_rank(0);
Expand Down Expand Up @@ -61,6 +69,7 @@ impl<'a, Item: RlstScalar + Equivalence, C: Communicator> DistributedVector<'a,
}
}

/// Create from root
pub fn from_root(
index_layout: &'a DefaultMpiIndexLayout<'a, C>,
other: &Option<DynamicArray<Item, 1>>,
Expand Down
12 changes: 12 additions & 0 deletions sparse/src/ghost_communicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,29 @@ use rlst_dense::types::RlstScalar;

use crate::traits::index_layout::IndexLayout;

/// Ghost communicator
pub struct GhostCommunicator {
/// Global receive indices
pub global_receive_indices: Vec<usize>,
/// Local send indices
pub local_send_indices: Vec<usize>,
/// Neighbourhood send counts
pub neighborhood_send_counts: Vec<i32>,
/// Neighbourhood receive counts
pub neighborhood_receive_counts: Vec<i32>,
/// Neighbourhood send displacements
pub neighborhood_send_displacements: Vec<i32>,
/// Neighbourhood receive displacements
pub neighborhood_receive_displacements: Vec<i32>,
/// Total send count
pub total_send_count: usize,
/// Total receive count
pub total_receive_count: usize,
neighbor_comm: SimpleCommunicator,
}

impl GhostCommunicator {
/// Create new ghost communicator
pub fn new<C: Communicator, Layout: IndexLayout>(
ghost_indices: &[usize],
layout: &Layout,
Expand Down Expand Up @@ -151,6 +161,7 @@ impl GhostCommunicator {
}
}

/// Forward send ghosts
pub fn forward_send_ghosts<T: RlstScalar + Equivalence>(
&self,
local_values: &[T],
Expand All @@ -176,6 +187,7 @@ impl GhostCommunicator {
);
}
}
/// Backward send ghosts
pub fn backward_send_ghosts<Acc: Fn(&mut T, &T), T: RlstScalar + Equivalence>(
&self,
local_values: &mut [T],
Expand Down
4 changes: 4 additions & 0 deletions sparse/src/index_layout/default_mpi_index_layout.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! Default index layout
use crate::traits::index_layout::IndexLayout;
use mpi::traits::Communicator;
use rlst_dense::types::RlstResult;

/// Default index layout
pub struct DefaultMpiIndexLayout<'a, C: Communicator> {
size: usize,
my_rank: usize,
Expand All @@ -10,6 +12,7 @@ pub struct DefaultMpiIndexLayout<'a, C: Communicator> {
}

impl<'a, C: Communicator> DefaultMpiIndexLayout<'a, C> {
/// Crate new
pub fn new(size: usize, comm: &'a C) -> Self {
let comm_size = comm.size() as usize;

Expand Down Expand Up @@ -79,6 +82,7 @@ impl<'a, C: Communicator> DefaultMpiIndexLayout<'a, C> {
comm,
}
}
/// MPI communicator
pub fn comm(&self) -> &C {
self.comm
}
Expand Down
11 changes: 11 additions & 0 deletions sparse/src/sparse/mpi_csr_mat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use rlst_dense::traits::Shape;
use rlst_dense::traits::{RawAccess, RawAccessMut};
use rlst_dense::types::RlstScalar;

/// Distributed CSR matrix
pub struct MpiCsrMatrix<'a, T: RlstScalar + Equivalence, C: Communicator> {
mat_type: SparseMatType,
shape: [usize; 2],
Expand All @@ -27,6 +28,7 @@ pub struct MpiCsrMatrix<'a, T: RlstScalar + Equivalence, C: Communicator> {
}

impl<'a, T: RlstScalar + Equivalence, C: Communicator> MpiCsrMatrix<'a, T, C> {
/// Create new
pub fn new(
shape: [usize; 2],
indices: Vec<usize>,
Expand Down Expand Up @@ -90,34 +92,42 @@ impl<'a, T: RlstScalar + Equivalence, C: Communicator> MpiCsrMatrix<'a, T, C> {
}
}

/// Matrix type
pub fn mat_type(&self) -> &SparseMatType {
&self.mat_type
}

/// Local shape
pub fn local_shape(&self) -> [usize; 2] {
self.local_matrix.shape()
}

/// Column indices
pub fn indices(&self) -> &[usize] {
&self.global_indices
}

/// Indices at which each row starts
pub fn indptr(&self) -> &[usize] {
self.local_matrix.indptr()
}

/// Matrix entries
pub fn data(&self) -> &[T] {
self.local_matrix.data()
}

/// Domain layout
pub fn domain_layout(&self) -> &'a DefaultMpiIndexLayout<'a, C> {
self.domain_layout
}

/// Range layout
pub fn range_layout(&self) -> &'a DefaultMpiIndexLayout<'a, C> {
self.range_layout
}

/// Create from root
pub fn from_root(
csr_mat: Option<CsrMatrix<T>>,
domain_layout: &'a DefaultMpiIndexLayout<'a, C>,
Expand Down Expand Up @@ -259,6 +269,7 @@ impl<'a, T: RlstScalar + Equivalence, C: Communicator> MpiCsrMatrix<'a, T, C> {
)
}

/// Matrix multiplication
pub fn matmul<'b>(
&self,
alpha: T,
Expand Down

0 comments on commit 5eb2d3e

Please sign in to comment.