source: XIOS/trunk/src/node/distribution_server.cpp @ 551

Last change on this file since 551 was 551, checked in by mhnguyen, 9 years ago

Redesigning grid structure

+) Add an intermediate class to calculate distribution on client and servers
+) Change all index of attributes to zero (0), instead of one(1)

Test
+) On Curie
+) Test new features passes but some data are still shifted

File size: 1.6 KB
Line 
1#include "distribution_server.hpp"
2
3namespace xios {
4CDistributionServer::CDistributionServer(int rank, int dims, int nServer, CArray<size_t,1>* globalIndex)
5  : CDistribution(rank, dims, globalIndex), nServer_(nServer), nGlobal_()
6{
7
8}
9
10CDistributionServer::CDistributionServer(int rank, int nServer, const std::vector<int>& nGlobal)
11  : CDistribution(rank, nGlobal.size()), nServer_(nServer)
12{
13  readDistributionInfo(nGlobal);
14  createGlobalIndex();
15}
16
17CDistributionServer::~CDistributionServer()
18{
19  if (0 != this->globalIndex_) delete globalIndex_;
20}
21
22void CDistributionServer::readDistributionInfo(const std::vector<int>& nGlobal)
23{
24  if (nGlobal.empty())
25  {
26    //! TODO: This error must be replaced a call to function processing scalar value
27    ERROR("CDistributionServer::readDistributionInfo(const std::vector<int>& nGlobal)",
28       << "At least one dimension must be defined for this field.");
29  }
30  nGlobal_ = nGlobal;
31  this->dims_ = nGlobal.size();
32}
33
34void CDistributionServer::createGlobalIndex()
35{
36  size_t globalIndexSize = 1;
37  for (int i = 0; i < nGlobal_.size(); ++i)
38    globalIndexSize *= nGlobal_[i];
39  size_t rangeSize    = globalIndexSize / nServer_;
40  size_t modulusSize = globalIndexSize % nServer_;
41
42  if ((this->rank_ == (nServer_-1)) && (0 != modulusSize))
43  {
44    this->globalIndex_ = new CArray<size_t,1>(modulusSize);
45    globalIndexSize = modulusSize;
46  }
47  else
48  {
49    this->globalIndex_ = new CArray<size_t,1>(rangeSize);
50    globalIndexSize = rangeSize;
51  }
52
53  size_t idxBegin = this->rank_ * rangeSize;
54  for (size_t i = 0; i < globalIndexSize;++i)
55    (*this->globalIndex_)(i) = i+idxBegin;
56}
57
58}
Note: See TracBrowser for help on using the repository browser.