forked from AMReX-Codes/amrex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAMReX_AlgPartition.cpp
59 lines (48 loc) · 1.28 KB
/
AMReX_AlgPartition.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#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->m_row = rows;
AMREX_ASSERT(m_row.size() == ParallelDescriptor::NProcs());
}
void AlgPartition::define (Vector<Long>&& rows)
{
m_ref->m_row = std::move(rows);
AMREX_ASSERT(m_row.size() == ParallelDescriptor::NProcs());
}
AlgPartition::Ref::Ref (Long global_size)
{
define(global_size);
}
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;
}
}