1 | /*! |
---|
2 | \file axis_algorithm_transformation.hpp |
---|
3 | \author Ha NGUYEN |
---|
4 | \since 14 May 2015 |
---|
5 | \date 29 June 2015 |
---|
6 | |
---|
7 | \brief Interface for all axis transformation algorithms. |
---|
8 | */ |
---|
9 | |
---|
10 | #include "axis_algorithm_transformation.hpp" |
---|
11 | #include "axis_algorithm_inverse.hpp" |
---|
12 | #include "axis_algorithm_zoom.hpp" |
---|
13 | #include "context.hpp" |
---|
14 | #include "context_client.hpp" |
---|
15 | #include "client_client_dht_template.hpp" |
---|
16 | #include "axis.hpp" |
---|
17 | |
---|
18 | namespace xios { |
---|
19 | |
---|
20 | CAxisAlgorithmTransformation::CAxisAlgorithmTransformation(CAxis* axisDestination, CAxis* axisSource) |
---|
21 | : CGenericAlgorithmTransformation(), axisDest_(axisDestination), axisSrc_(axisSource), domainSrc_(0),scalarSrc_(0) |
---|
22 | TRY |
---|
23 | { |
---|
24 | axisDestGlobalSize_ = axisDestination->n_glo.getValue(); |
---|
25 | int niDest = axisDestination->n.getValue(); |
---|
26 | int ibeginDest = axisDestination->begin.getValue(); |
---|
27 | |
---|
28 | for (int idx = 0; idx < niDest; ++idx) |
---|
29 | if ((axisDestination->mask)(idx)) axisDestGlobalIndex_.push_back(ibeginDest+idx); |
---|
30 | } |
---|
31 | CATCH |
---|
32 | |
---|
33 | CAxisAlgorithmTransformation::CAxisAlgorithmTransformation(CAxis* axisDestination, CDomain* domainSource) |
---|
34 | : CGenericAlgorithmTransformation(), axisDest_(axisDestination), axisSrc_(0), domainSrc_(domainSource),scalarSrc_(0) |
---|
35 | TRY |
---|
36 | { |
---|
37 | axisDestGlobalSize_ = axisDestination->n_glo.getValue(); |
---|
38 | int niDest = axisDestination->n.getValue(); |
---|
39 | int ibeginDest = axisDestination->begin.getValue(); |
---|
40 | |
---|
41 | for (int idx = 0; idx < niDest; ++idx) |
---|
42 | if ((axisDestination->mask)(idx)) axisDestGlobalIndex_.push_back(ibeginDest+idx); |
---|
43 | } |
---|
44 | CATCH |
---|
45 | |
---|
46 | CAxisAlgorithmTransformation::CAxisAlgorithmTransformation(CAxis* axisDestination, CScalar* scalarSource) |
---|
47 | : CGenericAlgorithmTransformation(), axisDest_(axisDestination), axisSrc_(0), domainSrc_(0), scalarSrc_(scalarSource) |
---|
48 | TRY |
---|
49 | { |
---|
50 | axisDestGlobalSize_ = axisDestination->n_glo.getValue(); |
---|
51 | int niDest = axisDestination->n.getValue(); |
---|
52 | int ibeginDest = axisDestination->begin.getValue(); |
---|
53 | |
---|
54 | for (int idx = 0; idx < niDest; ++idx) |
---|
55 | if ((axisDestination->mask)(idx)) axisDestGlobalIndex_.push_back(ibeginDest+idx); |
---|
56 | } |
---|
57 | CATCH |
---|
58 | |
---|
59 | CAxisAlgorithmTransformation::~CAxisAlgorithmTransformation() |
---|
60 | { |
---|
61 | } |
---|
62 | |
---|
63 | void CAxisAlgorithmTransformation::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) |
---|
64 | { |
---|
65 | } |
---|
66 | |
---|
67 | /*! |
---|
68 | Compute global index of axis on different processes |
---|
69 | \param [in] globalAxisIndex global index of axis source |
---|
70 | \param [out] globalAxisIndexOnProc processes which contain the corresponding global index of axis source |
---|
71 | */ |
---|
72 | void CAxisAlgorithmTransformation::computeExchangeGlobalIndex(const CArray<size_t,1>& globalAxisIndex, |
---|
73 | int elementType, |
---|
74 | CClientClientDHTInt::Index2VectorInfoTypeMap& globalAxisIndexOnProc) |
---|
75 | TRY |
---|
76 | { |
---|
77 | CContext* context = CContext::getCurrent(); |
---|
78 | CContextClient* client=context->client; |
---|
79 | int clientRank = client->clientRank; |
---|
80 | int clientSize = client->clientSize; |
---|
81 | |
---|
82 | size_t globalIndex; |
---|
83 | int nIndexSize = 0; |
---|
84 | CArray<bool,1>* ptLocalMask ; |
---|
85 | CArray<bool,1> scalarMask(1) ; |
---|
86 | scalarMask=true ; |
---|
87 | |
---|
88 | if (2 == elementType) |
---|
89 | { |
---|
90 | nIndexSize = domainSrc_->i_index.numElements(); |
---|
91 | ptLocalMask=&(domainSrc_->localMask) ; |
---|
92 | } |
---|
93 | else if (1 == elementType) |
---|
94 | { |
---|
95 | nIndexSize = axisSrc_->index.numElements(); |
---|
96 | ptLocalMask=&(axisSrc_->mask) ; |
---|
97 | } |
---|
98 | else |
---|
99 | { |
---|
100 | nIndexSize=1 ; // scalar |
---|
101 | ptLocalMask=&scalarMask ; |
---|
102 | } |
---|
103 | CArray<bool,1>& localMask=*ptLocalMask ; |
---|
104 | |
---|
105 | CClientClientDHTInt::Index2VectorInfoTypeMap globalIndex2ProcRank; |
---|
106 | globalIndex2ProcRank.rehash(std::ceil(nIndexSize/globalIndex2ProcRank.max_load_factor())); |
---|
107 | for (int idx = 0; idx < nIndexSize; ++idx) |
---|
108 | { |
---|
109 | if (localMask(idx)) |
---|
110 | { |
---|
111 | if (2 == elementType) // domain |
---|
112 | { |
---|
113 | globalIndex = domainSrc_->i_index(idx) + domainSrc_->j_index(idx) * domainSrc_->ni_glo; |
---|
114 | } |
---|
115 | else if (1 == elementType) // axis |
---|
116 | { |
---|
117 | globalIndex = axisSrc_->index(idx); |
---|
118 | } |
---|
119 | else // scalar |
---|
120 | { |
---|
121 | globalIndex = 0; |
---|
122 | } |
---|
123 | |
---|
124 | globalIndex2ProcRank[globalIndex].resize(1); |
---|
125 | globalIndex2ProcRank[globalIndex][0] = clientRank; |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | CClientClientDHTInt dhtIndexProcRank(globalIndex2ProcRank, client->intraComm); |
---|
130 | dhtIndexProcRank.computeIndexInfoMapping(globalAxisIndex); |
---|
131 | |
---|
132 | globalAxisIndexOnProc = dhtIndexProcRank.getInfoIndexMap(); |
---|
133 | } |
---|
134 | CATCH |
---|
135 | |
---|
136 | } |
---|