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