/*! \file client_server_mapping.hpp \author Ha NGUYEN \since 04 Feb 2015 \date 09 Mars 2015 \brief Mapping between index client and server. */ #include "client_server_mapping.hpp" namespace xios { CClientServerMapping::CClientServerMapping() : indexGlobalOnServer_(), localIndexSend2Server_(), connectedClients_() { } CClientServerMapping::~CClientServerMapping() { } /*! Compute mapping global index of server which client sends to. \param [in] globalIndexOnClient global index on client \param [in] globalIndexServer global index of servers */ void CClientServerMapping::computeServerIndexMapping(const CArray& globalIndexOnClient, const std::vector* >& globalIndexServer) { defaultComputeServerIndexMapping(globalIndexOnClient, globalIndexServer); } /*! Compute index of data which are sent to server and index global on server side \param [in] globalIndexOnClient global index of data on client \param [in] globalIndexServer global index of server(s) \param [in] localIndexOnClient local index of data on client which are sent to server */ void CClientServerMapping::defaultComputeServerIndexMapping(const CArray& globalIndexOnClient, const std::vector* >& globalIndexServer, const CArray* localIndexOnClient) { int nServer = globalIndexServer.size(); std::vector::const_iterator> itBegin(nServer), itEnd(nServer), it(nServer); for (int i = 0; i < nServer; ++i) { itBegin[i] = it[i] = globalIndexServer[i]->begin(); itEnd[i] = globalIndexServer[i]->end(); } size_t ssize = globalIndexOnClient.numElements(); for (int i = 0; i < ssize; ++i) { for (int j = 0; j < nServer; ++j) { // Just temporarily, it's bad. if (std::binary_search(itBegin[j], itEnd[j], globalIndexOnClient(i))) { // Just try to calculate local index server on client side (indexGlobalOnServer_[j]).push_back((globalIndexOnClient)(i)); if (0 != localIndexOnClient) (localIndexSend2Server_[j]).push_back((*localIndexOnClient)(i)); else (localIndexSend2Server_[j]).push_back(i); continue; } } } } /*! Compute how many clients each server will receive data from On client can send data to several servers as well as one server can receive data originated from some clients. In order to write data correctly, each server must know from how many clients it receives data \param [in] nbServer number of servers \param [in] nClient number of clients \param [in] clientIntraComm MPI communication of clients \param [in] connectedServerRank Rank of servers connected to one client */ std::map CClientServerMapping::computeConnectedClients(int nbServer, int nbClient, MPI_Comm& clientIntraComm, const std::vector& connectedServerRank) { std::map connectedClients; // number of clients connected to a server std::vector::const_iterator itbVec, iteVec, it; itbVec = it = connectedServerRank.begin(); iteVec = connectedServerRank.end(); std::vector connectedServer; std::vector isConnected(nbServer,false); for (it = itbVec; it != iteVec; ++it) { for (int serverNum = 0; serverNum < nbServer; ++serverNum) if (*it == serverNum) isConnected[serverNum] = true; } for(int serverNum = 0; serverNum clientRes(0,nbServer); for(int n=0;n >& CClientServerMapping::getLocalIndexSendToServer() const { return localIndexSend2Server_; } /*! Return global index of data on each connected server. On receiving data sent from client(s), each server with this global index, is able to know where the data should be written. \return mapping of server rank and its global index. */ const std::map >& CClientServerMapping::getGlobalIndexOnServer() const { return indexGlobalOnServer_; } } //namespace xios