Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_AlgPartition.H
Go to the documentation of this file.
1#ifndef AMREX_ALG_PARTITION_H_
2#define AMREX_ALG_PARTITION_H_
3#include <AMReX_Config.H>
4
5#include <AMReX_INT.H>
8#include <AMReX_Vector.H>
9
10#include <memory>
11
12namespace amrex {
13
26{
27public:
29 AlgPartition ();
31 explicit AlgPartition (Long global_size);
33 explicit AlgPartition (Vector<Long> const& rows);
35 explicit AlgPartition (Vector<Long>&& rows) noexcept;
36
38 void define (Long global_size);
40 void define (Vector<Long> const& rows);
42 void define (Vector<Long>&& rows);
43
45 [[nodiscard]] bool empty () const { return m_ref->m_row.empty(); }
46
48 [[nodiscard]] Long operator[] (int i) const { return m_ref->m_row[i]; }
50 [[nodiscard]] Long numLocalRows () const {
51 int myproc = ParallelContext::MyProcSub();
52 return m_ref->m_row[myproc+1] - m_ref->m_row[myproc];
53 }
55 [[nodiscard]] Long numGlobalRows () const { return m_ref->m_row.back(); }
57 [[nodiscard]] int numActiveProcs () const { return m_ref->m_n_active_procs; }
59 [[nodiscard]] int singleActiveProc () const { return m_ref->m_single_active_proc; }
60
62 [[nodiscard]] Long globalRowBegin () const {
63 return m_ref->m_row[ParallelContext::MyProcSub()];
64 }
65
67 [[nodiscard]] Long globalRowEnd () const {
68 return m_ref->m_row[ParallelContext::MyProcSub()+1];
69 }
70
72 [[nodiscard]] Vector<Long> const& dataVector () const { return m_ref->m_row; }
73
75 [[nodiscard]] bool operator== (AlgPartition const& rhs) const noexcept;
77 [[nodiscard]] bool operator!= (AlgPartition const& rhs) const noexcept;
78
79private:
80 struct Ref
81 {
82 friend class AlgPartition;
83 Ref () = default;
84 explicit Ref (Long global_size);
85 explicit Ref (Vector<Long> const& rows);
86 explicit Ref (Vector<Long>&& rows);
87 void define (Long global_size);
88 void define (Vector<Long> const& rows);
89 void define (Vector<Long>&& rows);
90 void update_n_active_procs ();
91
92 Vector<Long> m_row; // size: nprocs + 1
93 int m_n_active_procs = 0;
94 int m_single_active_proc = -1;
95 };
96
97 std::shared_ptr<Ref> m_ref;
98};
99
100}
101
102#endif
Definition AMReX_AlgPartition.H:26
Long numGlobalRows() const
Total number of rows covered by the partition.
Definition AMReX_AlgPartition.H:55
int singleActiveProc() const
The sole rank owning rows if numActiveProcs() is one, otherwise -1.
Definition AMReX_AlgPartition.H:59
AlgPartition()
Construct an empty partition that must be defined later.
Definition AMReX_AlgPartition.cpp:5
Long globalRowEnd() const
Exclusive global index end on this process.
Definition AMReX_AlgPartition.H:67
int numActiveProcs() const
Number of MPI ranks that own at least one row.
Definition AMReX_AlgPartition.H:57
bool operator==(AlgPartition const &rhs) const noexcept
Compare partitions for identical layouts.
Definition AMReX_AlgPartition.cpp:36
Long globalRowBegin() const
Inclusive global index begin on this process.
Definition AMReX_AlgPartition.H:62
bool empty() const
True if the partition contains no rows.
Definition AMReX_AlgPartition.H:45
Vector< Long > const & dataVector() const
Underlying array describing row offsets (size nproc+1).
Definition AMReX_AlgPartition.H:72
void define(Long global_size)
Recompute an even partition spanning global_size rows.
Definition AMReX_AlgPartition.cpp:21
Long numLocalRows() const
Number of local rows.
Definition AMReX_AlgPartition.H:50
bool operator!=(AlgPartition const &rhs) const noexcept
Negation of operator==.
Definition AMReX_AlgPartition.cpp:41
Long operator[](int i) const
Starting global row index owned by rank i.
Definition AMReX_AlgPartition.H:48
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:29
amrex_long Long
Definition AMReX_INT.H:30
int MyProcSub() noexcept
my sub-rank in current frame
Definition AMReX_ParallelContext.H:76
Definition AMReX_Amr.cpp:50