[569] | 1 | /*! |
---|
| 2 | \file client_server_mapping.hpp |
---|
| 3 | \author Ha NGUYEN |
---|
| 4 | \since 27 Feb 2015 |
---|
[829] | 5 | \date 16 Mars 2016 |
---|
[569] | 6 | |
---|
| 7 | \brief Mapping between index client and server. |
---|
| 8 | Clients pre-calculate all information of server distribution. |
---|
| 9 | */ |
---|
[568] | 10 | #include "client_server_mapping_distributed.hpp" |
---|
| 11 | #include <limits> |
---|
| 12 | #include <boost/functional/hash.hpp> |
---|
[584] | 13 | #include "utils.hpp" |
---|
[720] | 14 | #include "mpi_tag.hpp" |
---|
[906] | 15 | #include "context.hpp" |
---|
| 16 | #include "context_client.hpp" |
---|
[568] | 17 | |
---|
| 18 | namespace xios |
---|
| 19 | { |
---|
| 20 | |
---|
| 21 | CClientServerMappingDistributed::CClientServerMappingDistributed(const boost::unordered_map<size_t,int>& globalIndexOfServer, |
---|
[585] | 22 | const MPI_Comm& clientIntraComm, bool isDataDistributed) |
---|
[829] | 23 | : CClientServerMapping(), ccDHT_(0) |
---|
[568] | 24 | { |
---|
[721] | 25 | ccDHT_ = new CClientClientDHTInt(globalIndexOfServer, |
---|
[835] | 26 | clientIntraComm); |
---|
[568] | 27 | } |
---|
| 28 | |
---|
| 29 | CClientServerMappingDistributed::~CClientServerMappingDistributed() |
---|
| 30 | { |
---|
[720] | 31 | if (0 != ccDHT_) delete ccDHT_; |
---|
[569] | 32 | } |
---|
[568] | 33 | |
---|
[569] | 34 | /*! |
---|
| 35 | Compute mapping global index of server which client sends to. |
---|
| 36 | \param [in] globalIndexOnClient global index client has |
---|
| 37 | */ |
---|
[584] | 38 | void CClientServerMappingDistributed::computeServerIndexMapping(const CArray<size_t,1>& globalIndexOnClient) |
---|
[568] | 39 | { |
---|
[906] | 40 | CContext* context=CContext::getCurrent() ; |
---|
[1054] | 41 | // CContextClient* client=context->client ; |
---|
| 42 | // For now the assumption is that secondary server pools consist of the same number of procs. |
---|
| 43 | // CHANGE the line below if the assumption changes. |
---|
| 44 | CContextClient* client = (0 != context->clientPrimServer.size()) ? context->clientPrimServer[0] : context->client; |
---|
[906] | 45 | int nbServer=client->serverSize; |
---|
| 46 | |
---|
[721] | 47 | ccDHT_->computeIndexInfoMapping(globalIndexOnClient); |
---|
[860] | 48 | const CClientClientDHTInt::Index2VectorInfoTypeMap& infoIndexMap = (ccDHT_->getInfoIndexMap()); |
---|
| 49 | CClientClientDHTInt::Index2VectorInfoTypeMap::const_iterator itb = infoIndexMap.begin(), ite = infoIndexMap.end(), it; |
---|
[907] | 50 | std::vector<size_t> nbInfoIndex(std::max(ccDHT_->getNbClient(),nbServer),0); |
---|
[843] | 51 | |
---|
| 52 | for (it = itb; it != ite; ++it) |
---|
[568] | 53 | { |
---|
[860] | 54 | ++nbInfoIndex[it->second[0]]; |
---|
[568] | 55 | } |
---|
[843] | 56 | |
---|
| 57 | for (int idx = 0; idx < nbInfoIndex.size(); ++idx) |
---|
| 58 | { |
---|
| 59 | if (0 != nbInfoIndex[idx]) |
---|
| 60 | { |
---|
| 61 | indexGlobalOnServer_[idx].resize(nbInfoIndex[idx]); |
---|
| 62 | nbInfoIndex[idx] = 0; |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | for (it = itb; it != ite; ++it) |
---|
| 67 | { |
---|
[860] | 68 | indexGlobalOnServer_[it->second[0]][nbInfoIndex[it->second[0]]] = (it->first); |
---|
| 69 | ++nbInfoIndex[it->second[0]]; |
---|
[843] | 70 | } |
---|
[568] | 71 | } |
---|
| 72 | |
---|
| 73 | } |
---|