source: XIOS3/trunk/src/distribution/local_view.cpp @ 2385

Last change on this file since 2385 was 2385, checked in by jderouillat, 2 years ago

Move in a new method of CLocalView the management of a without redundancy full view connector (used in hash computation of elements)

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 3.5 KB
Line 
1#include "local_view.hpp"
2#include "element.hpp"
3#include "array_new.hpp"
4#include "remote_connector.hpp"
5#include "grid_transform_connector.hpp"
6
7namespace xios
8{
9  CLocalView::CLocalView(shared_ptr<CLocalElement> parent, CElementView::type type, const CArray<int,1>& indexView) 
10                        : CDistributedView( parent, type, {{  parent->localRank_,  indexView }} ),
11                          localRank_(parent->localRank_),
12                          globalIndex_(parent->globalIndex_), size_(CDistributedView::size_[parent->localRank_]),
13                          index_(CDistributedView::index_[parent->localRank_]), localSize_(CDistributedView::localSize_[parent->localRank_]) 
14  {
15
16  }
17
18  CLocalView::CLocalView(shared_ptr<CLocalElement> parent, CElementView::type type, const CArray<bool,1>& maskView) 
19                        : CDistributedView( parent, type, {{  parent->localRank_,  maskView }} ),
20                          localRank_(parent->localRank_),
21                          globalIndex_(parent->globalIndex_), size_(CDistributedView::size_[parent->localRank_]),
22                          index_(CDistributedView::index_[parent->localRank_]), localSize_(CDistributedView::localSize_[parent->localRank_]) 
23  {
24
25  }
26
27  void CLocalView::sendRemoteElement(shared_ptr<CRemoteConnector> connector, CContextClient* client, CEventClient& event, const CMessage& messageHeader)
28  {
29    int n = index_.numElements() ;
30    int nglo=globalIndex_.numElements() ;
31    CArray<size_t,1> ind(n) ;
32    for(int i=0; i<n;i++)
33    {
34      if (index_(i)>=0 && index_(i)<nglo) ind(i) = globalIndex_(index_(i)) ;
35      else ind(i)=index_(i) ;
36    }
37    CMessage message(messageHeader) ;
38    message<<globalSize_ ;
39    connector->transferToServer(ind, client, event, message) ;
40  }
41 
42  void CLocalView::createWithoutRedundancyFullViewConnector( int globalSize, MPI_Comm comm_file, shared_ptr<CGridTransformConnector>& gridTransformConnector, CArray<size_t,1>& globalIndex )
43  {
44    int comm_file_rank(0);
45    MPI_Comm_rank( comm_file, &comm_file_rank );
46    int comm_file_size(1);
47    MPI_Comm_size( comm_file, &comm_file_size );
48
49    vector<shared_ptr<CLocalView>> srcViews;
50    shared_ptr<CLocalView> srcView = shared_from_this();
51    srcViews.push_back( srcView );
52         
53    // Compute a without redundancy element FULL view to enable a consistent hash computation
54    vector<shared_ptr<CLocalView>> remoteViews;
55    shared_ptr<CLocalView> remoteView;
56    // define the remote view without redundancy (naive distribution of the remote view)
57    int localSize = globalSize/comm_file_size;
58    if ( (comm_file_rank==comm_file_size-1) && (localSize*comm_file_size != globalSize ) )
59      localSize += globalSize-localSize*comm_file_size;
60    globalIndex.resize( localSize );
61    CArray<int,1> index( localSize );
62    for (int iloc=0; iloc<localSize ; iloc++ )
63      {
64        globalIndex(iloc) = comm_file_rank*(globalSize/comm_file_size) + iloc;
65        index(iloc) = iloc;
66      }
67    shared_ptr<CLocalElement> localElement = make_shared<CLocalElement>(comm_file_rank, globalSize, globalIndex) ;
68    localElement->addView(CElementView::FULL, index) ;
69    remoteView = localElement->getView(CElementView::FULL) ;
70    remoteViews.push_back( remoteView );
71       
72    // Compute the connector between current and without redundancy FULL views
73    gridTransformConnector = make_shared<CGridTransformConnector>(srcViews, remoteViews, comm_file ) ;
74    gridTransformConnector->computeConnector(true) ; // eliminateRedondant = true
75
76  }
77
78}
Note: See TracBrowser for help on using the repository browser.