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