[888] | 1 | /*! |
---|
| 2 | \file scalar_algorithm_transformation.hpp |
---|
| 3 | \author Ha NGUYEN |
---|
| 4 | \since 23 June 2016 |
---|
[976] | 5 | \date 23 Oct 2016 |
---|
[888] | 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 | |
---|
| 18 | namespace xios { |
---|
| 19 | |
---|
| 20 | CScalarAlgorithmTransformation::CScalarAlgorithmTransformation(CScalar* scalarDestination, CScalar* scalarSource) |
---|
| 21 | : CGenericAlgorithmTransformation(), |
---|
| 22 | scalarDest_(scalarDestination), |
---|
| 23 | scalarSrc_(scalarSource), axisSrc_(0), domainSrc_(0) |
---|
| 24 | { |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | CScalarAlgorithmTransformation::CScalarAlgorithmTransformation(CScalar* scalarDestination, CAxis* axisSource) |
---|
| 28 | : CGenericAlgorithmTransformation(), |
---|
| 29 | scalarDest_(scalarDestination), |
---|
| 30 | scalarSrc_(0), axisSrc_(axisSource), domainSrc_(0) |
---|
| 31 | { |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | CScalarAlgorithmTransformation::CScalarAlgorithmTransformation(CScalar* scalarDestination, CDomain* domainSource) |
---|
| 35 | : CGenericAlgorithmTransformation(), |
---|
| 36 | scalarDest_(scalarDestination), |
---|
| 37 | scalarSrc_(0), axisSrc_(0), domainSrc_(domainSource) |
---|
| 38 | { |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | CScalarAlgorithmTransformation::~CScalarAlgorithmTransformation() |
---|
| 42 | { |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | void CScalarAlgorithmTransformation::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) |
---|
| 46 | { |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | /*! |
---|
[976] | 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 |
---|
[888] | 55 | */ |
---|
[976] | 56 | void CScalarAlgorithmTransformation::computeExchangeGlobalIndex(const CArray<size_t,1>& globalIndexElementSource, |
---|
| 57 | int elementSourceType, |
---|
| 58 | CClientClientDHTInt::Index2VectorInfoTypeMap& globalIndexElementSourceOnProc) |
---|
[1622] | 59 | TRY |
---|
[888] | 60 | { |
---|
| 61 | CContext* context = CContext::getCurrent(); |
---|
| 62 | CContextClient* client=context->client; |
---|
| 63 | int clientRank = client->clientRank; |
---|
| 64 | int clientSize = client->clientSize; |
---|
| 65 | |
---|
[976] | 66 | if (2 == elementSourceType) // Source is a domain |
---|
[888] | 67 | { |
---|
| 68 | size_t globalIndex; |
---|
[976] | 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; |
---|
[1403] | 73 | CArray<bool,1>& localMask = domainSrc_ -> localMask ; |
---|
[976] | 74 | CClientClientDHTInt::Index2VectorInfoTypeMap globalIndex2ProcRank; |
---|
| 75 | globalIndex2ProcRank.rehash(std::ceil(nIndexSize/globalIndex2ProcRank.max_load_factor())); |
---|
| 76 | for (int idx = 0; idx < nIndexSize; ++idx) |
---|
| 77 | { |
---|
[1403] | 78 | if (localMask(idx)) |
---|
| 79 | { |
---|
| 80 | globalIndex = jIndex(idx) * niGlo + iIndex(idx); |
---|
| 81 | globalIndex2ProcRank[globalIndex].resize(1); |
---|
| 82 | globalIndex2ProcRank[globalIndex][0] = clientRank; |
---|
| 83 | } |
---|
[976] | 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; |
---|
[888] | 93 | int nIndexSize = axisSrc_->index.numElements(); |
---|
| 94 | CClientClientDHTInt::Index2VectorInfoTypeMap globalIndex2ProcRank; |
---|
| 95 | globalIndex2ProcRank.rehash(std::ceil(nIndexSize/globalIndex2ProcRank.max_load_factor())); |
---|
[1403] | 96 | CArray<bool,1>& localMask = axisSrc_ -> mask ; |
---|
| 97 | |
---|
[888] | 98 | for (int idx = 0; idx < nIndexSize; ++idx) |
---|
| 99 | { |
---|
[1403] | 100 | if (localMask(idx)) |
---|
| 101 | { |
---|
| 102 | globalIndex = axisSrc_->index(idx); |
---|
| 103 | globalIndex2ProcRank[globalIndex].resize(1); |
---|
| 104 | globalIndex2ProcRank[globalIndex][0] = clientRank; |
---|
| 105 | } |
---|
[888] | 106 | } |
---|
| 107 | |
---|
| 108 | CClientClientDHTInt dhtIndexProcRank(globalIndex2ProcRank, client->intraComm); |
---|
[976] | 109 | dhtIndexProcRank.computeIndexInfoMapping(globalIndexElementSource); |
---|
| 110 | globalIndexElementSourceOnProc = dhtIndexProcRank.getInfoIndexMap(); |
---|
[888] | 111 | } |
---|
[976] | 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 | } |
---|
[888] | 123 | } |
---|
[1622] | 124 | CATCH |
---|
[888] | 125 | } |
---|