[624] | 1 | /*! |
---|
| 2 | \file axis_algorithm_transformation.hpp |
---|
| 3 | \author Ha NGUYEN |
---|
| 4 | \since 14 May 2015 |
---|
[630] | 5 | \date 29 June 2015 |
---|
[624] | 6 | |
---|
| 7 | \brief Interface for all axis transformation algorithms. |
---|
| 8 | */ |
---|
| 9 | |
---|
[620] | 10 | #include "axis_algorithm_transformation.hpp" |
---|
[624] | 11 | #include "axis_algorithm_inverse.hpp" |
---|
| 12 | #include "axis_algorithm_zoom.hpp" |
---|
[862] | 13 | #include "context.hpp" |
---|
| 14 | #include "context_client.hpp" |
---|
| 15 | #include "client_client_dht_template.hpp" |
---|
[867] | 16 | #include "axis.hpp" |
---|
[620] | 17 | |
---|
| 18 | namespace xios { |
---|
| 19 | |
---|
[622] | 20 | CAxisAlgorithmTransformation::CAxisAlgorithmTransformation(CAxis* axisDestination, CAxis* axisSource) |
---|
[1275] | 21 | : CGenericAlgorithmTransformation(), axisDest_(axisDestination), axisSrc_(axisSource), domainSrc_(0),scalarSrc_(0) |
---|
[1612] | 22 | TRY |
---|
[620] | 23 | { |
---|
[666] | 24 | axisDestGlobalSize_ = axisDestination->n_glo.getValue(); |
---|
| 25 | int niDest = axisDestination->n.getValue(); |
---|
| 26 | int ibeginDest = axisDestination->begin.getValue(); |
---|
[630] | 27 | |
---|
| 28 | for (int idx = 0; idx < niDest; ++idx) |
---|
| 29 | if ((axisDestination->mask)(idx)) axisDestGlobalIndex_.push_back(ibeginDest+idx); |
---|
[621] | 30 | } |
---|
[1612] | 31 | CATCH |
---|
[620] | 32 | |
---|
[895] | 33 | CAxisAlgorithmTransformation::CAxisAlgorithmTransformation(CAxis* axisDestination, CDomain* domainSource) |
---|
[1275] | 34 | : CGenericAlgorithmTransformation(), axisDest_(axisDestination), axisSrc_(0), domainSrc_(domainSource),scalarSrc_(0) |
---|
[1612] | 35 | TRY |
---|
[895] | 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 | } |
---|
[1612] | 44 | CATCH |
---|
[895] | 45 | |
---|
[1275] | 46 | CAxisAlgorithmTransformation::CAxisAlgorithmTransformation(CAxis* axisDestination, CScalar* scalarSource) |
---|
| 47 | : CGenericAlgorithmTransformation(), axisDest_(axisDestination), axisSrc_(0), domainSrc_(0), scalarSrc_(scalarSource) |
---|
[1612] | 48 | TRY |
---|
[1275] | 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 | } |
---|
[1612] | 57 | CATCH |
---|
| 58 | |
---|
[621] | 59 | CAxisAlgorithmTransformation::~CAxisAlgorithmTransformation() |
---|
| 60 | { |
---|
[620] | 61 | } |
---|
| 62 | |
---|
[867] | 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 | */ |
---|
[862] | 72 | void CAxisAlgorithmTransformation::computeExchangeGlobalIndex(const CArray<size_t,1>& globalAxisIndex, |
---|
[888] | 73 | int elementType, |
---|
[866] | 74 | CClientClientDHTInt::Index2VectorInfoTypeMap& globalAxisIndexOnProc) |
---|
[1612] | 75 | TRY |
---|
[862] | 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; |
---|
[895] | 83 | int nIndexSize = 0; |
---|
[1403] | 84 | CArray<bool,1>* ptLocalMask ; |
---|
| 85 | CArray<bool,1> scalarMask(1) ; |
---|
| 86 | scalarMask=true ; |
---|
[1275] | 87 | |
---|
[1403] | 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 | |
---|
[862] | 105 | CClientClientDHTInt::Index2VectorInfoTypeMap globalIndex2ProcRank; |
---|
| 106 | globalIndex2ProcRank.rehash(std::ceil(nIndexSize/globalIndex2ProcRank.max_load_factor())); |
---|
| 107 | for (int idx = 0; idx < nIndexSize; ++idx) |
---|
| 108 | { |
---|
[1403] | 109 | if (localMask(idx)) |
---|
[895] | 110 | { |
---|
[1403] | 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; |
---|
[895] | 126 | } |
---|
[862] | 127 | } |
---|
| 128 | |
---|
| 129 | CClientClientDHTInt dhtIndexProcRank(globalIndex2ProcRank, client->intraComm); |
---|
| 130 | dhtIndexProcRank.computeIndexInfoMapping(globalAxisIndex); |
---|
| 131 | |
---|
[866] | 132 | globalAxisIndexOnProc = dhtIndexProcRank.getInfoIndexMap(); |
---|
[862] | 133 | } |
---|
[1612] | 134 | CATCH |
---|
[862] | 135 | |
---|
[621] | 136 | } |
---|