source: XIOS/dev/branch_openmp/src/client_server_mapping.cpp @ 1220

Last change on this file since 1220 was 1220, checked in by yushan, 4 years ago

test_remap_omp tested on ADA except two fields

File size: 3.3 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_()
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 
67  for(int i=0; i<nbClient; i++)
68    printf("MPI_Allgather : recvCount[%d] = %d\n", i, recvCount[i]);
69
70  displ[0]=0 ;
71  for(int n=1;n<nbClient;n++) displ[n]=displ[n-1]+recvCount[n-1] ;
72  int recvSize=displ[nbClient-1]+recvCount[nbClient-1] ;
73  int* recvBuff=new int[recvSize] ;
74
75
76  MPI_Allgatherv(sendBuff,nbConnectedServer,MPI_INT,recvBuff,recvCount,displ,MPI_INT,clientIntraComm) ;
77
78  for(int i=0; i<recvSize; i++)
79    printf("MPI_Allgatherv : recvBuff[%d] = %d\n", i, recvBuff[i]);
80
81
82  for(int n=0;n<recvSize;n++) clientRes[recvBuff[n]]++ ;
83
84  for(int n=0;n<nbConnectedServer;n++)
85  {
86    connectedClients[connectedServer[n]] = clientRes[connectedServer[n]];
87  }
88
89  delete [] recvCount ;
90  delete [] displ ;
91  delete [] sendBuff ;
92  delete [] recvBuff ;
93
94  return connectedClients;
95}
96
97/*!
98  Return global index of data on each connected server.
99  On receiving data sent from client(s), each server with this global index, is able to
100know where the data should be written.
101  \return mapping of server rank and its global index.
102*/
103const CClientServerMapping::GlobalIndexMap& CClientServerMapping::getGlobalIndexOnServer() const
104{
105  return indexGlobalOnServer_;
106}
107
108} //namespace xios
Note: See TracBrowser for help on using the repository browser.