3 #include <fei_set_shared_ids.hpp>
4 #include <fei_CommMap.hpp>
5 #include <fei_CommUtils.hpp>
6 #include <fei_TemplateUtils.hpp>
7 #include <snl_fei_RecordCollection.hpp>
8 #include <fei_SharedIDs.hpp>
9 #include <fei_LinearDecomposition.hpp>
13 void copy_into_shared_ids(
const fei::CommMap<int>::Type& procs_to_ids_and_sharing_procs,
23 ip_iter = procs_to_ids_and_sharing_procs.begin(),
24 ip_end = procs_to_ids_and_sharing_procs.end();
26 for(; ip_iter != ip_end; ++ip_iter) {
27 const std::vector<int>& ids_and_procs = ip_iter->second;
28 size_t vsize = ids_and_procs.size();
30 while(offset < vsize) {
31 int id = ids_and_procs[offset++];
32 int num_procs = ids_and_procs[offset++];
34 sharedIDs.
addSharedID(
id, num_procs, &ids_and_procs[offset]);
41 void copy_remotelyowned_ids_into_CommMap(
int myProc,
42 const fei::LinearDecomposition<int>& lindecomp,
44 fei::CommMap<int>::Type& procs_to_shared_ids)
47 int ID = records.getRecordWithLocalID(i)->getID();
48 int proc = lindecomp.which_proc(ID);
58 int lowest_global_id,
int highest_global_id)
64 if (numProcs < 2)
return;
67 fei::LinearDecomposition<int> lindecomp(myProc,numProcs,
68 lowest_global_id, highest_global_id);
72 fei::CommMap<int>::Type procs_to_shared_ids;
73 copy_remotelyowned_ids_into_CommMap(myProc, lindecomp, records, procs_to_shared_ids);
79 fei::CommMap<int>::Type procs_to_owned_ids;
80 fei::exchangeCommMapData<int>(comm, procs_to_shared_ids, procs_to_owned_ids);
83 fei::CommMap<int>::Type owned_ids_to_procs;
86 o_iter = procs_to_owned_ids.begin(), o_end = procs_to_owned_ids.end();
88 for(; o_iter != o_end; ++o_iter) {
89 int proc = o_iter->first;
90 std::vector<int>& ids = o_iter->second;
91 for(
size_t i=0; i<ids.size(); ++i) {
99 fei::CommMap<int>::Type procs_to_owned_ids_and_sharing_procs;
101 for(o_iter=procs_to_owned_ids.begin(); o_iter!=procs_to_owned_ids.end(); ++o_iter) {
102 int proc = o_iter->first;
103 std::vector<int>& ids = o_iter->second;
104 for(
size_t i=0; i<ids.size(); ++i) {
105 std::vector<int>& sharing_procs = owned_ids_to_procs[ids[i]];
106 int num_sharing_procs = sharing_procs.size();
107 if (num_sharing_procs > 1) {
108 addItemsToCommMap(proc, 1, &ids[i], procs_to_owned_ids_and_sharing_procs,
false);
109 addItemsToCommMap(proc, 1, &num_sharing_procs, procs_to_owned_ids_and_sharing_procs,
false);
110 addItemsToCommMap(proc, num_sharing_procs, &sharing_procs[0], procs_to_owned_ids_and_sharing_procs,
false);
115 fei::CommMap<int>::Type procs_to_shared_ids_and_sharing_procs;
116 fei::exchangeCommMapData<int>(comm, procs_to_owned_ids_and_sharing_procs,
117 procs_to_shared_ids_and_sharing_procs);
119 copy_into_shared_ids(procs_to_owned_ids_and_sharing_procs, records, sharedIDs);
120 copy_into_shared_ids(procs_to_shared_ids_and_sharing_procs, records, sharedIDs);
void addItemsToCommMap(int proc, size_t numItems, const T *items, typename CommMap< T >::Type &comm_map, bool keep_sorted_and_unique=true)
std::vector< int > & getOwningProcs()
map_type & getSharedIDs()
void set_shared_ids(MPI_Comm comm, const snl_fei::RecordCollection &records, fei::SharedIDs< int > &sharedIDs, int lowest_global_id, int highest_global_id)
size_t getNumRecords() const
void addSharedID(const T &ID, size_t numSharingProcs, const int *sharingProcs)
int localProc(MPI_Comm comm)
fei::Record< int > * getRecordWithID(int ID)
int numProcs(MPI_Comm comm)