source: XIOS/trunk/src/transformation/generic_algorithm_transformation.cpp @ 829

Last change on this file since 829 was 829, checked in by mhnguyen, 5 years ago

Refactoring transformation code

+) On exchanging information during transformation, not only global index are sent but also local index
+) Correct a bug in distributed hash table (dht)
+) Add new type for dht
+) Clean up some redundant codes

Test
+) On Curie
+) Every test passes
+) Code runs faster in some cases (up to 30%)

File size: 5.9 KB
Line 
1/*!
2   \file generic_algorithm_transformation.hpp
3   \author Ha NGUYEN
4   \since 14 May 2015
5   \date 21 Mars 2016
6
7   \brief Interface for all transformation algorithms.
8 */
9#include "generic_algorithm_transformation.hpp"
10
11namespace xios {
12
13CGenericAlgorithmTransformation::CGenericAlgorithmTransformation()
14 : transformationMapping_(), transformationWeight_(), transformationPosition_(), idAuxInputs_()
15{
16}
17
18/*!
19  This function computes the global indexes of grid source, which the grid destination is in demand.
20  \param[in] elementPositionInGrid position of an element in a grid .E.g: if grid is composed of domain and axis (in order),
21                then position of axis in grid is 2 (since a domain is considered to contain 2 elements (axis)
22  \param[in] gridDestGlobalDim global size of each dimension of grid source (all dimension must have the same size except of the one on which transformation is performed)
23  \param[in] gridSrcGlobalDim dimension size of source grid (it should share the same size for all dimension, maybe except the domain on which transformation is performed)
24  \param[in] globalIndexGridDestSendToServer global index of grid destination on the current client to send to server
25  \param[in] localIndexGridSendToServer local index of grid destination on the current client to send to server
26  \param[in/out] globaIndexWeightFromDestToSource mapping between transformed global index of grid destination
27             and the weighted value as well as global index from grid index source
28*/
29void CGenericAlgorithmTransformation::computeGlobalSourceIndex(int elementPositionInGrid,
30                                                             const std::vector<int>& gridDestGlobalDim,
31                                                             const std::vector<int>& gridSrcGlobalDim,
32                                                             const std::vector<size_t>& globalIndexGridDestSendToServer,
33                                                             const std::vector<int>& localIndexGridSendToServer,
34                                                             DestinationIndexMap& globaIndexWeightFromDestToSource)
35{
36  bool isTransPosEmpty = transformationPosition_.empty();
37  boost::unordered_map<size_t,int> globalLocalIndexDestSendToServerMap;
38  size_t nbGlobalIndexDest = globalIndexGridDestSendToServer.size();
39  for (size_t idx = 0; idx < nbGlobalIndexDest; ++idx)
40  {
41    globalLocalIndexDestSendToServerMap[globalIndexGridDestSendToServer[idx]] = localIndexGridSendToServer[idx];
42  }
43
44  for (size_t idxTrans = 0; idxTrans < transformationMapping_.size(); ++idxTrans)
45  {
46    std::map<int, std::vector<int> >::const_iterator itbTransMap = transformationMapping_[idxTrans].begin(), itTransMap,
47                                                     iteTransMap = transformationMapping_[idxTrans].end();
48    std::map<int, std::vector<double> >::const_iterator itTransWeight = transformationWeight_[idxTrans].begin();
49
50    // If transformation position exists
51    std::map<int, std::vector<int> >::const_iterator itTransPos, iteTransPos;
52    if (!isTransPosEmpty)
53    {
54      itTransPos  = transformationPosition_[idxTrans].begin(),
55      iteTransPos = transformationPosition_[idxTrans].end();
56    }
57    std::vector<int> emptyTransPos;
58
59    std::vector<std::vector<size_t> > globalIndexSrcGrid;
60    std::vector<std::pair<size_t,int> > globalLocalIndexDest;
61    for (itTransMap = itbTransMap; itTransMap != iteTransMap; ++itTransMap, ++itTransWeight)
62    {
63      boost::unordered_map<size_t,int> globalLocalIndexDestMap;
64      if (!isTransPosEmpty)
65      {
66        this->computeGlobalGridIndexFromGlobalIndexElement(itTransMap->first,
67                                                           itTransMap->second,
68                                                           itTransPos->second,
69                                                           elementPositionInGrid,
70                                                           gridDestGlobalDim,
71                                                           gridSrcGlobalDim,
72                                                           globalLocalIndexDestSendToServerMap,
73                                                           globalLocalIndexDest,
74                                                           globalIndexSrcGrid);
75        ++itTransPos;
76      }
77      else
78      {
79        this->computeGlobalGridIndexFromGlobalIndexElement(itTransMap->first,
80                                                           itTransMap->second,
81                                                           emptyTransPos,
82                                                           elementPositionInGrid,
83                                                           gridDestGlobalDim,
84                                                           gridSrcGlobalDim,
85                                                           globalLocalIndexDestSendToServerMap,
86                                                           globalLocalIndexDest,
87                                                           globalIndexSrcGrid);
88      }
89      std::vector<std::pair<size_t,int> >::const_iterator it = globalLocalIndexDest.begin(), ite = globalLocalIndexDest.end();
90      const std::vector<double>& currentVecWeight = itTransWeight->second;
91
92      for (size_t idx = 0; it != ite; ++it, ++idx)
93      {
94        size_t srcGridSize = globalIndexSrcGrid[idx].size();
95        globaIndexWeightFromDestToSource[(it->first)].reserve(srcGridSize);
96        for (int i = 0; i < srcGridSize; ++i)
97        {
98          globaIndexWeightFromDestToSource[(it->first)].push_back(make_pair(it->second, make_pair(globalIndexSrcGrid[idx][i], currentVecWeight[i])));
99        }
100      }
101    }
102  }
103}
104
105void CGenericAlgorithmTransformation::computeIndexSourceMapping(const std::vector<CArray<double,1>* >& dataAuxInputs)
106{
107  computeIndexSourceMapping_(dataAuxInputs);
108}
109
110std::vector<StdString> CGenericAlgorithmTransformation::getIdAuxInputs()
111{
112  return idAuxInputs_;
113}
114
115}
Note: See TracBrowser for help on using the repository browser.