Memosa-FVM  0.2
StorageSiteMerger.cpp
Go to the documentation of this file.
1 // This file os part of FVM
2 // Copyright (c) 2012 FVM Authors
3 // See LICENSE file for terms.
4 
5 #ifdef FVM_PARALLEL
6 
7 #include <iostream>
8 #include <fstream>
9 #include <string>
10 #include <sstream>
11 #include "StorageSiteMerger.h"
12 
13 using namespace std;
14 
15 StorageSiteMerger::StorageSiteMerger(int target_proc_id, const set<int>& group, const StorageSite& cell_site )
16 :_groupID(target_proc_id), _group(group), _cellSite(cell_site), _mergeSiteSize(0), _mergeSiteGhostSize(0)
17 {
18  init();
19 }
20 
21 StorageSiteMerger::~StorageSiteMerger()
22 {
23 
24 }
25 
26 
27 void
28 StorageSiteMerger::init()
29 {
30  //subcommunicator
31  int color = _groupID;
32  int key = MPI::COMM_WORLD.Get_rank();
33  _comm = MPI::COMM_WORLD.Split( color, key );
34 }
35 
36 
37 shared_ptr<StorageSite>
38 StorageSiteMerger::merge()
39 {
40  StorageSite::GatherMap::const_iterator it;
41  int tot_adjacent_count = 0; //this will be substracted before sending groupID
42 
43  for ( it = _cellSite.getGatherMap().begin(); it != _cellSite.getGatherMap().end(); it++){
44  const StorageSite* site = it->first;
45  int gatherID = site->getGatherProcID();
46  //this check if neighbour mesh id is in group list, if it is, we want to increse tot_adjacent_count
47  if ( _group.count( gatherID) > 0 ){
48  int interface_count =it->second->getLength();
49  tot_adjacent_count += interface_count;
50  }
51 
52  }
53 
54  int local_size = _cellSite.getCount() - tot_adjacent_count;
55  int ghost_size = local_size - _cellSite.getSelfCount();
56  int self_size = _cellSite.getSelfCount();
57 
58  _comm.Reduce( &self_size , &_mergeSiteSize , 1, MPI::INT, MPI::SUM, _groupID );
59  _comm.Reduce( &ghost_size, &_mergeSiteGhostSize, 1, MPI::INT, MPI::SUM, _groupID );
60  //debug_print();
61  return shared_ptr<StorageSite> ( new StorageSite(_mergeSiteSize) );
62 
63 }
64 
65 
66 void
67 StorageSiteMerger::debug_print()
68 {
69  shared_ptr<StorageSite> tempSite = merge();
70  stringstream ss;
71  ss << "proc" << MPI::COMM_WORLD.Get_rank() << "_storage_site_merger.dat";
72  ofstream debug_file( (ss.str()).c_str() );
73 
74  debug_file << " selfCount = " << _mergeSiteSize << endl;
75  debug_file << " GhostCount = " << _mergeSiteGhostSize << endl;
76  debug_file << " count = " << _mergeSiteSize + _mergeSiteGhostSize << endl;
77 
78  debug_file.close();
79 
80 }
81 
82 #endif
int getGatherProcID() const
Definition: StorageSite.h:83