[553] | 1 | /*! |
---|
| 2 | \file client_server_mapping.hpp |
---|
| 3 | \author Ha NGUYEN |
---|
| 4 | \since 04 Feb 2015 |
---|
[569] | 5 | \date 09 Mars 2015 |
---|
[553] | 6 | |
---|
| 7 | \brief Mapping between index client and server. |
---|
| 8 | */ |
---|
| 9 | #include "client_server_mapping.hpp" |
---|
| 10 | |
---|
| 11 | namespace xios { |
---|
| 12 | |
---|
| 13 | CClientServerMapping::CClientServerMapping() |
---|
[843] | 14 | : indexGlobalOnServer_() |
---|
[553] | 15 | { |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | CClientServerMapping::~CClientServerMapping() |
---|
| 19 | { |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | /*! |
---|
| 23 | Compute how many clients each server will receive data from |
---|
| 24 | On client can send data to several servers as well as one server can receive data originated from |
---|
| 25 | some clients. In order to write data correctly, each server must know from how many clients it receives data |
---|
| 26 | \param [in] nbServer number of servers |
---|
| 27 | \param [in] nClient number of clients |
---|
| 28 | \param [in] clientIntraComm MPI communication of clients |
---|
| 29 | \param [in] connectedServerRank Rank of servers connected to one client |
---|
| 30 | */ |
---|
| 31 | std::map<int,int> CClientServerMapping::computeConnectedClients(int nbServer, int nbClient, |
---|
[1639] | 32 | MPI_Comm& clientIntraComm, |
---|
[553] | 33 | const std::vector<int>& connectedServerRank) |
---|
| 34 | { |
---|
| 35 | std::map<int, int> connectedClients; // number of clients connected to a server |
---|
| 36 | |
---|
| 37 | std::vector<int>::const_iterator itbVec, iteVec, it; |
---|
| 38 | itbVec = it = connectedServerRank.begin(); |
---|
| 39 | iteVec = connectedServerRank.end(); |
---|
| 40 | |
---|
| 41 | std::vector<int> connectedServer; |
---|
| 42 | std::vector<bool> isConnected(nbServer,false); |
---|
| 43 | |
---|
| 44 | for (it = itbVec; it != iteVec; ++it) |
---|
| 45 | { |
---|
| 46 | for (int serverNum = 0; serverNum < nbServer; ++serverNum) |
---|
| 47 | if (*it == serverNum) isConnected[serverNum] = true; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | for(int serverNum = 0; serverNum<nbServer; ++serverNum) |
---|
| 51 | if (isConnected[serverNum]) |
---|
| 52 | connectedServer.push_back(serverNum); |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | int nbConnectedServer=connectedServer.size(); |
---|
| 56 | int* recvCount=new int[nbClient]; |
---|
| 57 | int* displ=new int[nbClient]; |
---|
| 58 | int* sendBuff=new int[nbConnectedServer]; |
---|
| 59 | valarray<int> clientRes(0,nbServer); |
---|
| 60 | |
---|
| 61 | for(int n=0;n<nbConnectedServer;n++) sendBuff[n]=connectedServer[n] ; |
---|
| 62 | |
---|
| 63 | // get connected server for everybody |
---|
[1639] | 64 | MPI_Allgather(&nbConnectedServer,1,MPI_INT,recvCount,1,MPI_INT,clientIntraComm) ; |
---|
[553] | 65 | |
---|
| 66 | displ[0]=0 ; |
---|
| 67 | for(int n=1;n<nbClient;n++) displ[n]=displ[n-1]+recvCount[n-1] ; |
---|
| 68 | int recvSize=displ[nbClient-1]+recvCount[nbClient-1] ; |
---|
| 69 | int* recvBuff=new int[recvSize] ; |
---|
| 70 | |
---|
| 71 | |
---|
[1639] | 72 | MPI_Allgatherv(sendBuff,nbConnectedServer,MPI_INT,recvBuff,recvCount,displ,MPI_INT,clientIntraComm) ; |
---|
[553] | 73 | for(int n=0;n<recvSize;n++) clientRes[recvBuff[n]]++ ; |
---|
| 74 | |
---|
| 75 | for(int n=0;n<nbConnectedServer;n++) |
---|
| 76 | { |
---|
| 77 | connectedClients[connectedServer[n]] = clientRes[connectedServer[n]]; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | delete [] recvCount ; |
---|
| 81 | delete [] displ ; |
---|
| 82 | delete [] sendBuff ; |
---|
| 83 | delete [] recvBuff ; |
---|
| 84 | |
---|
| 85 | return connectedClients; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | /*! |
---|
| 89 | Return global index of data on each connected server. |
---|
| 90 | On receiving data sent from client(s), each server with this global index, is able to |
---|
| 91 | know where the data should be written. |
---|
| 92 | \return mapping of server rank and its global index. |
---|
| 93 | */ |
---|
[829] | 94 | const CClientServerMapping::GlobalIndexMap& CClientServerMapping::getGlobalIndexOnServer() const |
---|
[553] | 95 | { |
---|
| 96 | return indexGlobalOnServer_; |
---|
| 97 | } |
---|
| 98 | |
---|
[1025] | 99 | CClientServerMapping::GlobalIndexMap& CClientServerMapping::getGlobalIndexOnServer() |
---|
| 100 | { |
---|
| 101 | return indexGlobalOnServer_; |
---|
| 102 | } |
---|
| 103 | |
---|
[553] | 104 | } //namespace xios |
---|