source: XIOS/trunk/src/client_server_mapping_distributed.cpp @ 1205

Last change on this file since 1205 was 907, checked in by mhnguyen, 8 years ago

Correcting a minor thing of previous commit

+) Make sure the number of index correct even number of server is larger than number of client

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