-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AMReX Algebra: AlgVector and SpMatrix (#4259)
This implements distributed vector and sparse matrix. The functionalities are limited so far. However, there are enough functions implemented for a simple matrix and vector based GMRES solver with a weighted Jacobi smoother. This is still experimental and is not ready for users yet.
- Loading branch information
1 parent
96db0a6
commit 50e25ec
Showing
21 changed files
with
1,883 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#ifndef AMREX_ALG_PARTITION_H_ | ||
#define AMREX_ALG_PARTITION_H_ | ||
#include <AMReX_Config.H> | ||
|
||
#include <AMReX_INT.H> | ||
#include <AMReX_ParallelDescriptor.H> | ||
#include <AMReX_Vector.H> | ||
|
||
#include <memory> | ||
|
||
namespace amrex { | ||
|
||
class AlgPartition | ||
{ | ||
public: | ||
AlgPartition (); | ||
explicit AlgPartition (Long global_size); | ||
explicit AlgPartition (Vector<Long> const& rows); | ||
explicit AlgPartition (Vector<Long>&& rows) noexcept; | ||
|
||
void define (Long global_size); | ||
void define (Vector<Long> const& rows); | ||
void define (Vector<Long>&& rows); | ||
|
||
[[nodiscard]] bool empty () const { return m_ref->m_row.empty(); } | ||
|
||
[[nodiscard]] Long operator[] (int i) const { return m_ref->m_row[i]; } | ||
[[nodiscard]] Long numGlobalRows () const { return m_ref->m_row.back(); } | ||
[[nodiscard]] int numActiveProcs () const { return m_ref->m_n_active_procs; } | ||
|
||
[[nodiscard]] Vector<Long> const& dataVector () const { return m_ref->m_row; } | ||
|
||
[[nodiscard]] bool operator== (AlgPartition const& rhs) const noexcept; | ||
[[nodiscard]] bool operator!= (AlgPartition const& rhs) const noexcept; | ||
|
||
private: | ||
struct Ref | ||
{ | ||
friend class AlgPartition; | ||
Ref () = default; | ||
explicit Ref (Long global_size); | ||
explicit Ref (Vector<Long> const& rows); | ||
explicit Ref (Vector<Long>&& rows); | ||
void define (Long global_size); | ||
void define (Vector<Long> const& rows); | ||
void define (Vector<Long>&& rows); | ||
void update_n_active_procs (); | ||
|
||
Vector<Long> m_row; // size: nprocs + 1 | ||
int m_n_active_procs = 0; | ||
}; | ||
|
||
std::shared_ptr<Ref> m_ref; | ||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#include <AMReX_AlgPartition.H> | ||
|
||
namespace amrex { | ||
|
||
AlgPartition::AlgPartition () | ||
: m_ref(std::make_shared<Ref>()) | ||
{} | ||
|
||
AlgPartition::AlgPartition (Long global_size) | ||
: m_ref(std::make_shared<Ref>(global_size)) | ||
{} | ||
|
||
AlgPartition::AlgPartition (Vector<Long> const& rows) | ||
: m_ref(std::make_shared<Ref>(rows)) | ||
{} | ||
|
||
AlgPartition::AlgPartition (Vector<Long>&& rows) noexcept | ||
: m_ref(std::make_shared<Ref>(std::move(rows))) | ||
{} | ||
|
||
void AlgPartition::define (Long global_size) | ||
{ | ||
m_ref->define(global_size); | ||
} | ||
|
||
void AlgPartition::define (Vector<Long> const& rows) | ||
{ | ||
m_ref->define(rows); | ||
} | ||
|
||
void AlgPartition::define (Vector<Long>&& rows) | ||
{ | ||
m_ref->define(std::move(rows)); | ||
} | ||
|
||
bool AlgPartition::operator== (AlgPartition const& rhs) const noexcept | ||
{ | ||
return m_ref == rhs.m_ref || m_ref->m_row == rhs.m_ref->m_row; | ||
} | ||
|
||
bool AlgPartition::operator!= (AlgPartition const& rhs) const noexcept | ||
{ | ||
return !operator==(rhs); | ||
} | ||
|
||
AlgPartition::Ref::Ref (Long global_size) | ||
{ | ||
define(global_size); | ||
} | ||
|
||
AlgPartition::Ref::Ref (Vector<Long> const& rows) | ||
: m_row(rows) | ||
{ | ||
update_n_active_procs(); | ||
} | ||
|
||
AlgPartition::Ref::Ref (Vector<Long>&& rows) | ||
: m_row(std::move(rows)) | ||
{ | ||
update_n_active_procs(); | ||
} | ||
|
||
void AlgPartition::Ref::define (Long global_size) | ||
{ | ||
auto nprocs = Long(ParallelDescriptor::NProcs()); | ||
Long sz = global_size / nprocs; | ||
Long extra = global_size - sz*nprocs; | ||
m_row.resize(nprocs+1); | ||
for (Long i = 0; i < nprocs; ++i) { | ||
if (i < extra) { | ||
m_row[i] = i*(sz+1); | ||
} else { | ||
m_row[i] = i*sz + extra; | ||
} | ||
} | ||
m_row[nprocs] = global_size; | ||
|
||
update_n_active_procs(); | ||
} | ||
|
||
void AlgPartition::Ref::define (Vector<Long> const& rows) | ||
{ | ||
m_row = rows; | ||
update_n_active_procs(); | ||
} | ||
|
||
void AlgPartition::Ref::define (Vector<Long>&& rows) | ||
{ | ||
m_row = std::move(rows); | ||
update_n_active_procs(); | ||
} | ||
|
||
void AlgPartition::Ref::update_n_active_procs () | ||
{ | ||
AMREX_ASSERT(m_row.size() == ParallelDescriptor::NProcs()+1); | ||
m_n_active_procs = 0; | ||
for (int i = 0, N = int(m_row.size())-1; i < N; ++i) { | ||
if (m_row[i] < m_row[i+1]) { ++m_n_active_procs; } | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.