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

Last change on this file since 1622 was 1622, checked in by oabramkina, 5 years ago

Exception handling on trunk.

To activate it, compilation flag -DXIOS_EXCEPTION should be added.

File size: 4.5 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)
59TRY
60{
61  CContext* context = CContext::getCurrent();
62  CContextClient* client=context->client;
63  int clientRank = client->clientRank;
64  int clientSize = client->clientSize;
65
66  if (2 == elementSourceType) // Source is a domain
67  {
68    size_t globalIndex;
69    int nIndexSize = domainSrc_->i_index.numElements();
70    CArray<int,1>& iIndex = domainSrc_->i_index;
71    CArray<int,1>& jIndex = domainSrc_->j_index;
72    int niGlo = domainSrc_->ni_glo;
73    CArray<bool,1>& localMask = domainSrc_ -> localMask ;
74    CClientClientDHTInt::Index2VectorInfoTypeMap globalIndex2ProcRank;
75    globalIndex2ProcRank.rehash(std::ceil(nIndexSize/globalIndex2ProcRank.max_load_factor()));
76    for (int idx = 0; idx < nIndexSize; ++idx)
77    {
78      if (localMask(idx))
79      {
80        globalIndex = jIndex(idx) * niGlo + iIndex(idx);
81        globalIndex2ProcRank[globalIndex].resize(1);
82        globalIndex2ProcRank[globalIndex][0] = clientRank;
83      }
84    }
85
86    CClientClientDHTInt dhtIndexProcRank(globalIndex2ProcRank, client->intraComm);
87    dhtIndexProcRank.computeIndexInfoMapping(globalIndexElementSource);
88    globalIndexElementSourceOnProc = dhtIndexProcRank.getInfoIndexMap();
89  }
90  else if (1 == elementSourceType) // Source is an axis
91  {
92    size_t globalIndex;
93    int nIndexSize = axisSrc_->index.numElements();
94    CClientClientDHTInt::Index2VectorInfoTypeMap globalIndex2ProcRank;
95    globalIndex2ProcRank.rehash(std::ceil(nIndexSize/globalIndex2ProcRank.max_load_factor()));
96    CArray<bool,1>& localMask = axisSrc_ -> mask ;
97   
98    for (int idx = 0; idx < nIndexSize; ++idx)
99    {
100      if (localMask(idx))
101      {
102        globalIndex = axisSrc_->index(idx);
103        globalIndex2ProcRank[globalIndex].resize(1);
104        globalIndex2ProcRank[globalIndex][0] = clientRank;
105      }
106    }
107
108    CClientClientDHTInt dhtIndexProcRank(globalIndex2ProcRank, client->intraComm);
109    dhtIndexProcRank.computeIndexInfoMapping(globalIndexElementSource);
110    globalIndexElementSourceOnProc = dhtIndexProcRank.getInfoIndexMap();
111  }
112  else // scalar
113  {
114    size_t globalIndex = 0;   
115    CClientClientDHTInt::Index2VectorInfoTypeMap globalIndex2ProcRank;
116    globalIndex2ProcRank[globalIndex].resize(1);
117    globalIndex2ProcRank[globalIndex][0] = clientRank;
118
119    CClientClientDHTInt dhtIndexProcRank(globalIndex2ProcRank, client->intraComm);
120    dhtIndexProcRank.computeIndexInfoMapping(globalIndexElementSource);
121    globalIndexElementSourceOnProc = dhtIndexProcRank.getInfoIndexMap();
122  }
123}
124CATCH
125}
Note: See TracBrowser for help on using the repository browser.