1 #ifndef _fei_LinearDecomposition_hpp_
2 #define _fei_LinearDecomposition_hpp_
4 #include <fei_macros.hpp>
5 #include <fei_CommUtils.hpp>
9 template<
typename GlobalIDType>
10 class LinearDecomposition {
13 GlobalIDType lowest_global_id,
14 GlobalIDType highest_global_id);
15 ~LinearDecomposition() {}
17 GlobalIDType first_locally_owned_global_id()
const {
return first_locally_owned_global;}
18 GlobalIDType last_locally_owned_global_id()
const {
return last_locally_owned_global;}
20 GlobalIDType first_global_id()
const {
return first_global;}
21 GlobalIDType last_global_id()
const {
return last_global;}
26 int which_proc(GlobalIDType
id)
const;
29 GlobalIDType first_global;
30 GlobalIDType last_global;
31 GlobalIDType first_locally_owned_global;
32 GlobalIDType last_locally_owned_global;
33 std::vector<GlobalIDType> proc_offsets;
36 template<
typename GlobalIDType>
37 LinearDecomposition<GlobalIDType>::LinearDecomposition(
int localProc,
int numProcs,
38 GlobalIDType lowest_global_id,
39 GlobalIDType highest_global_id)
40 : first_locally_owned_global(0),
41 last_locally_owned_global(0),
44 GlobalIDType num_global = highest_global_id - lowest_global_id + 1;
45 GlobalIDType num_local = num_global/numProcs;
46 GlobalIDType remainder = num_global%numProcs;
49 proc_offsets.assign(numProcs, num_local);
50 for(GlobalIDType i=0; i<remainder; ++i) {
56 GlobalIDType offset = 0;
57 for(
size_t i=0; i<proc_offsets.size(); ++i) {
58 GlobalIDType tmp = proc_offsets[i];
59 proc_offsets[i] = offset;
63 first_global = lowest_global_id;
64 last_global = highest_global_id;
65 first_locally_owned_global = lowest_global_id + proc_offsets[localProc];
66 last_locally_owned_global = highest_global_id + proc_offsets[localProc] + num_local - 1;
69 template<
typename GlobalIDType>
70 int LinearDecomposition<GlobalIDType>::which_proc(GlobalIDType
id)
const
72 if (id < first_global || id > last_global)
return -1;
74 for(
size_t i=1; i<proc_offsets.size(); ++i) {
75 if (first_global+proc_offsets[i] >
id)
return i-1;
78 int last_proc = proc_offsets.size() - 1;
int localProc(MPI_Comm comm)
int numProcs(MPI_Comm comm)