source: XIOS/trunk/src/transformation/scalar_algorithm_transformation.cpp @ 976

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

Ticket 110: Implementing domain reduction to scalar

+) Add xml node for this new transformation
+) Add algorithm for this new transformation

Test
+) On Curie
+) Work

File size: 4.3 KB
Line 
1/*!
2   \file scalar_algorithm_transformation.hpp
3   \author Ha NGUYEN
4   \since 23 June 2016
5   \date 23 Oct 2016
6
7   \brief Interface for all scalar transformation algorithms.
8 */
9
10#include "scalar_algorithm_transformation.hpp"
11#include "context.hpp"
12#include "context_client.hpp"
13#include "client_client_dht_template.hpp"
14#include "domain.hpp"
15#include "axis.hpp"
16#include "scalar.hpp"
17
18namespace xios {
19
20CScalarAlgorithmTransformation::CScalarAlgorithmTransformation(CScalar* scalarDestination, CScalar* scalarSource)
21 : CGenericAlgorithmTransformation(),
22   scalarDest_(scalarDestination),
23   scalarSrc_(scalarSource), axisSrc_(0), domainSrc_(0)
24{
25}
26
27CScalarAlgorithmTransformation::CScalarAlgorithmTransformation(CScalar* scalarDestination, CAxis* axisSource)
28 : CGenericAlgorithmTransformation(),
29   scalarDest_(scalarDestination),
30   scalarSrc_(0), axisSrc_(axisSource), domainSrc_(0)
31{
32}
33
34CScalarAlgorithmTransformation::CScalarAlgorithmTransformation(CScalar* scalarDestination, CDomain* domainSource)
35 : CGenericAlgorithmTransformation(),
36   scalarDest_(scalarDestination),
37   scalarSrc_(0), axisSrc_(0), domainSrc_(domainSource)
38{
39}
40
41CScalarAlgorithmTransformation::~CScalarAlgorithmTransformation()
42{
43}
44
45void CScalarAlgorithmTransformation::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
46{
47}
48
49/*!
50  Compute global index of element source on different processes on knowing the global index source of transformation
51
52  \param [in] globalIndexElementSource global index source of transformation (represented in the transformation mapping)
53  \param [in] elementSourceType type of element source
54  \param [out] globalIndexElementSourceOnProc processes which contain the corresponding global index of scalar source
55*/
56void CScalarAlgorithmTransformation::computeExchangeGlobalIndex(const CArray<size_t,1>& globalIndexElementSource,
57                                                                int elementSourceType,
58                                                                CClientClientDHTInt::Index2VectorInfoTypeMap& globalIndexElementSourceOnProc)
59{
60  CContext* context = CContext::getCurrent();
61  CContextClient* client=context->client;
62  int clientRank = client->clientRank;
63  int clientSize = client->clientSize;
64
65  if (2 == elementSourceType) // Source is a domain
66  {
67    size_t globalIndex;
68    int nIndexSize = domainSrc_->i_index.numElements();
69    CArray<int,1>& iIndex = domainSrc_->i_index;
70    CArray<int,1>& jIndex = domainSrc_->j_index;
71    int niGlo = domainSrc_->ni_glo;
72
73    CClientClientDHTInt::Index2VectorInfoTypeMap globalIndex2ProcRank;
74    globalIndex2ProcRank.rehash(std::ceil(nIndexSize/globalIndex2ProcRank.max_load_factor()));
75    for (int idx = 0; idx < nIndexSize; ++idx)
76    {
77      globalIndex = jIndex(idx) * niGlo + iIndex(idx);
78      globalIndex2ProcRank[globalIndex].resize(1);
79      globalIndex2ProcRank[globalIndex][0] = clientRank;
80    }
81
82    CClientClientDHTInt dhtIndexProcRank(globalIndex2ProcRank, client->intraComm);
83    dhtIndexProcRank.computeIndexInfoMapping(globalIndexElementSource);
84    globalIndexElementSourceOnProc = dhtIndexProcRank.getInfoIndexMap();
85  }
86  else if (1 == elementSourceType) // Source is an axis
87  {
88    size_t globalIndex;
89    int nIndexSize = axisSrc_->index.numElements();
90    CClientClientDHTInt::Index2VectorInfoTypeMap globalIndex2ProcRank;
91    globalIndex2ProcRank.rehash(std::ceil(nIndexSize/globalIndex2ProcRank.max_load_factor()));
92    for (int idx = 0; idx < nIndexSize; ++idx)
93    {
94      globalIndex = axisSrc_->index(idx);
95      globalIndex2ProcRank[globalIndex].resize(1);
96      globalIndex2ProcRank[globalIndex][0] = clientRank;
97    }
98
99    CClientClientDHTInt dhtIndexProcRank(globalIndex2ProcRank, client->intraComm);
100    dhtIndexProcRank.computeIndexInfoMapping(globalIndexElementSource);
101    globalIndexElementSourceOnProc = dhtIndexProcRank.getInfoIndexMap();
102  }
103  else // scalar
104  {
105    size_t globalIndex = 0;   
106    CClientClientDHTInt::Index2VectorInfoTypeMap globalIndex2ProcRank;
107    globalIndex2ProcRank[globalIndex].resize(1);
108    globalIndex2ProcRank[globalIndex][0] = clientRank;
109
110    CClientClientDHTInt dhtIndexProcRank(globalIndex2ProcRank, client->intraComm);
111    dhtIndexProcRank.computeIndexInfoMapping(globalIndexElementSource);
112    globalIndexElementSourceOnProc = dhtIndexProcRank.getInfoIndexMap();
113  }
114}
115
116}
Note: See TracBrowser for help on using the repository browser.