source: XIOS/trunk/src/client_server_mapping.cpp @ 832

Last change on this file since 832 was 832, checked in by mhnguyen, 5 years ago

Weight computation of dynamic transformation is done only one for each time stamp

+) Each weight computation of dynamic transformation attached to timestamp
+) Remove some redundant codes

Test
+) On Curie
+) All tests pass

File size: 3.1 KB
Line 
1/*!
2   \file client_server_mapping.hpp
3   \author Ha NGUYEN
4   \since 04 Feb 2015
5   \date 09 Mars 2015
6
7   \brief Mapping between index client and server.
8 */
9#include "client_server_mapping.hpp"
10
11namespace xios {
12
13CClientServerMapping::CClientServerMapping()
14  : indexGlobalOnServer_(), connectedClients_() //, localIndexSend2Server_()
15{
16}
17
18CClientServerMapping::~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
25some 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*/
31std::map<int,int> CClientServerMapping::computeConnectedClients(int nbServer, int nbClient,
32                                                                MPI_Comm& clientIntraComm,
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
64  MPI_Allgather(&nbConnectedServer,1,MPI_INT,recvCount,1,MPI_INT,clientIntraComm) ;
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
72  MPI_Allgatherv(sendBuff,nbConnectedServer,MPI_INT,recvBuff,recvCount,displ,MPI_INT,clientIntraComm) ;
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
91know where the data should be written.
92  \return mapping of server rank and its global index.
93*/
94const CClientServerMapping::GlobalIndexMap& CClientServerMapping::getGlobalIndexOnServer() const
95{
96  return indexGlobalOnServer_;
97}
98
99} //namespace xios
Note: See TracBrowser for help on using the repository browser.