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

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

Seperating global index computation on client and server side

+) Create a class which do mapping in general manner, between client and server index global
+) Remove some redundant functions and variables
+) Add some comments to code

Test
+) On Curie. Only test_new_features.f90
+) Test passes and results are correct.
+) Need to change index from 1 to 0

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