FEI Package Browser (Single Doxygen Collection)  Version of the Day
fei_LinearDecomposition.hpp
Go to the documentation of this file.
1 #ifndef _fei_LinearDecomposition_hpp_
2 #define _fei_LinearDecomposition_hpp_
3 
4 #include <fei_macros.hpp>
5 #include <fei_CommUtils.hpp>
6 
7 namespace fei {
8 
9 template<typename GlobalIDType>
11 public:
13  GlobalIDType lowest_global_id,
14  GlobalIDType highest_global_id);
16 
19 
20  GlobalIDType first_global_id() const {return first_global;}
21  GlobalIDType last_global_id() const {return last_global;}
22 
26  int which_proc(GlobalIDType id) const;
27 
28 private:
29  GlobalIDType first_global;
30  GlobalIDType last_global;
33  std::vector<GlobalIDType> proc_offsets;
34 };//class LinearDecomposition
35 
36 template<typename GlobalIDType>
38  GlobalIDType lowest_global_id,
39  GlobalIDType highest_global_id)
40  : first_locally_owned_global(0),
41  last_locally_owned_global(0),
42  proc_offsets()
43 {
44  GlobalIDType num_global = highest_global_id - lowest_global_id + 1;
45  GlobalIDType num_local = num_global/numProcs;
46  GlobalIDType remainder = num_global%numProcs;
47 
48  //First have each entry in proc_offsets contain the number of local ids:
49  proc_offsets.assign(numProcs, num_local);
50  for(GlobalIDType i=0; i<remainder; ++i) {
51  ++proc_offsets[i];
52  }
53 
54  //Now convert proc_offsets so that proc_offsets[i] is the i-th proc's
55  //offset into the global space of ids:
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;
60  offset += tmp;
61  }
62 
63  first_global = lowest_global_id;
64  last_global = highest_global_id;
66  last_locally_owned_global = highest_global_id + proc_offsets[localProc] + num_local - 1;
67 }
68 
69 template<typename GlobalIDType>
71 {
72  if (id < first_global || id > last_global) return -1;
73 
74  for(size_t i=1; i<proc_offsets.size(); ++i) {
75  if (first_global+proc_offsets[i] > id) return i-1;
76  }
77 
78  int last_proc = proc_offsets.size() - 1;
79  return last_proc;
80 }
81 
82 }//namespace fei
83 
84 #endif
85 
fei::LinearDecomposition::first_locally_owned_global_id
GlobalIDType first_locally_owned_global_id() const
Definition: fei_LinearDecomposition.hpp:17
fei::LinearDecomposition::~LinearDecomposition
~LinearDecomposition()
Definition: fei_LinearDecomposition.hpp:15
fei_macros.hpp
fei::LinearDecomposition::which_proc
int which_proc(GlobalIDType id) const
Definition: fei_LinearDecomposition.hpp:70
fei::LinearDecomposition
Definition: fei_LinearDecomposition.hpp:10
fei::LinearDecomposition::last_global
GlobalIDType last_global
Definition: fei_LinearDecomposition.hpp:30
fei::LinearDecomposition::LinearDecomposition
LinearDecomposition(int localProc, int numProcs, GlobalIDType lowest_global_id, GlobalIDType highest_global_id)
Definition: fei_LinearDecomposition.hpp:37
fei::LinearDecomposition::proc_offsets
std::vector< GlobalIDType > proc_offsets
Definition: fei_LinearDecomposition.hpp:33
fei::LinearDecomposition::last_global_id
GlobalIDType last_global_id() const
Definition: fei_LinearDecomposition.hpp:21
fei::LinearDecomposition::last_locally_owned_global
GlobalIDType last_locally_owned_global
Definition: fei_LinearDecomposition.hpp:32
fei_CommUtils.hpp
fei
Definition: fei_ArrayUtils.hpp:16
fei::LinearDecomposition::last_locally_owned_global_id
GlobalIDType last_locally_owned_global_id() const
Definition: fei_LinearDecomposition.hpp:18
fei::localProc
int localProc(MPI_Comm comm)
Definition: fei_CommUtils.cpp:13
fei::LinearDecomposition::first_global
GlobalIDType first_global
Definition: fei_LinearDecomposition.hpp:29
fei::LinearDecomposition::first_global_id
GlobalIDType first_global_id() const
Definition: fei_LinearDecomposition.hpp:20
fei::numProcs
int numProcs(MPI_Comm comm)
Definition: fei_CommUtils.cpp:25
fei::LinearDecomposition::first_locally_owned_global
GlobalIDType first_locally_owned_global
Definition: fei_LinearDecomposition.hpp:31