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

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

Doing some cleans and improving a little bit performance of creating local index on server

+) Add some comments, add some initialization
+) Change the way to calculate local index on server

Test
+) On Curie

File size: 3.2 KB
Line 
1#include "distribution_server.hpp"
2
3namespace xios {
4CDistributionServer::CDistributionServer(int rank, int dims, CArray<size_t,1>* globalIndex)
5  : CDistribution(rank, dims, globalIndex), nGlobal_(), nZoomSize_(), nZoomBegin_()
6{
7}
8
9CDistributionServer::CDistributionServer(int rank, const std::vector<int>& nZoomBegin,
10                                         const std::vector<int>& nZoomSize, const std::vector<int>& nGlobal)
11  : CDistribution(rank, nGlobal.size()), nGlobal_(nGlobal), nZoomSize_(nZoomSize), nZoomBegin_(nZoomBegin)
12{
13  createGlobalIndex();
14}
15
16CDistributionServer::~CDistributionServer()
17{
18}
19
20/*!
21  Create global index on server side
22  Like the similar function on client side, this function serves on creating global index
23for data written by the server. The global index is used to calculating local index of data
24written on each server
25*/
26void CDistributionServer::createGlobalIndex()
27{
28  size_t idx = 0, ssize = 1;
29  for (int i = 0; i < nZoomSize_.size(); ++i) ssize *= nZoomSize_[i];
30
31  this->globalIndex_ = new CArray<size_t,1>(ssize);
32  std::vector<int> idxLoop(this->getDims(),0);
33  std::vector<int> currentIndex(this->getDims());
34  int innerLoopSize = nZoomSize_[0];
35
36  while (idx<ssize)
37  {
38    for (int i = 0; i < this->dims_-1; ++i)
39    {
40      if (idxLoop[i] == nZoomSize_[i])
41      {
42        idxLoop[i] = 0;
43        ++idxLoop[i+1];
44      }
45    }
46
47    for (int i = 1; i < this->dims_; ++i)  currentIndex[i] = idxLoop[i] + nZoomBegin_[i];
48
49    size_t mulDim, globalIndex;
50    for (int i = 0; i < innerLoopSize; ++i)
51    {
52      mulDim = 1;
53      globalIndex = i + nZoomBegin_[0];
54
55      for (int k = 1; k < this->dims_; ++k)
56      {
57        mulDim *= nGlobal_[k-1];
58        globalIndex += (currentIndex[k])*mulDim;
59      }
60      (*this->globalIndex_)(idx) = globalIndex;
61      ++idx;
62    }
63    idxLoop[0] += innerLoopSize;
64  }
65}
66
67/*!
68  Compute local index for writing data on server
69  \param [in] globalIndex global index received from client
70  \return local index of written data
71*/
72CArray<size_t,1> CDistributionServer::computeLocalIndex(const CArray<size_t,1>& globalIndex)
73{
74  CArray<size_t,1>::const_iterator itBegin = (this->globalIndex_)->begin(),
75                                   itEnd   = (this->globalIndex_)->end(), it;
76
77  int ssize = globalIndex.numElements(), idx = 0;
78  CArray<size_t,1> localIndex(ssize);
79  it = itBegin;
80  for (int i = 0; i < ssize; ++i)
81  {
82    it = std::lower_bound(it, itEnd, globalIndex(i));
83    if (itEnd != it)
84    {
85      localIndex(idx) = std::distance(itBegin, it);
86      ++idx;
87    }
88  }
89
90  return localIndex;
91}
92
93/*!
94  Compute local index for writing data on server
95  \param [in] globalIndex Global index received from client
96*/
97void CDistributionServer::computeLocalIndex(CArray<size_t,1>& globalIndex)
98{
99  CArray<size_t,1>::const_iterator itBegin = (this->globalIndex_)->begin(),
100                                   itEnd   = (this->globalIndex_)->end(), it;
101
102  int ssize = globalIndex.numElements(), idx = 0;
103  CArray<size_t,1> localIndex(ssize);
104  it = itBegin;
105  for (int i = 0; i < ssize; ++i)
106  {
107    it = std::lower_bound(it, itEnd, globalIndex(i));
108    if (itEnd != it)
109    {
110      localIndex(idx) = std::distance(itBegin, it);
111      ++idx;
112    }
113  }
114
115  globalIndex = localIndex;
116}
117
118} // namespace xios
Note: See TracBrowser for help on using the repository browser.