source: XMLIO_V2/dev/dev_rv/src/xmlio/manager/xios_manager.cpp @ 152

Last change on this file since 152 was 152, checked in by hozdoba, 13 years ago
File size: 8.9 KB
Line 
1#include "xios_manager.hpp"
2
3namespace xmlioserver
4{
5      /// ////////////////////// Définitions ////////////////////// ///
6      void CXIOSManager::Initialise(XIOSType type, int * argc, char *** argv)
7      {
8         CXIOSManager::Type = type;
9         if (type != CLIENT)
10         {
11            // Initialisation de la biliothÚque MPI si nécessaire
12            comm::CMPIManager::Initialise(argc, argv);
13            ExeName = StdString((*argv)[0]);
14            for (int i = 1; i < *argc; i++)
15               ExeOptions.push_back(StdString((*argv)[i]));
16         }
17      }
18
19      void CXIOSManager::Finalize(void)
20      {
21         if (CXIOSManager::Type != CLIENT)
22         {
23            // Finalisation de la biliothÚque MPI si nécessaire
24            comm::CMPIManager::Finalize();
25         }
26      }
27
28      ///-------------------------------------------------------------
29
30      StdString CXIOSManager::ExeName("unknown");
31      std::vector<StdString> CXIOSManager::ExeOptions;
32
33      CXIOSManager::XIOSType CXIOSManager::Type = CLIENT;
34
35      StdString     CXIOSManager::ClientName;
36      comm::MPIComm CXIOSManager::Comm_Client_Server;
37      comm::MPIComm CXIOSManager::Comm_Server;
38
39      xios_map<StdString, CXIOSManager::XIOSClient> CXIOSManager::Clients;
40
41      ///--------------------------------------------------------------
42
43      void CXIOSManager::RunClientServer(comm::MPIComm comm_client_server)
44      {
45         using namespace comm;
46         typedef std::pair<StdString, XIOSClient> StdPairStrClient;
47
48         MPIComm  world_comm  = CMPIManager::GetCommWorld();
49         MPIGroup world_group = CMPIManager::GetGroupWorld();
50
51         if (CMPIManager::IsMaster(comm_client_server))
52         {
53            std::cout << " *************************************** " << std::endl
54                      << " *     XmlIOServer (Client/Server)     * " << std::endl
55                      << " *************************************** " << std::endl;
56            std::cout << " > Nombre de processus : "
57                      << CMPIManager::GetCommSize(comm_client_server) << std::endl;
58            std::cout << " > Nombre de processus utilisés : "
59                      << (CXIOSManager::GetNbClient() + CXIOSManager::GetNbServer()) << std::endl;
60            std::cout << " > Nombre de clients : "
61                      << CXIOSManager::GetNbClient() << std::endl;
62            std::cout << " > Nombre de serveurs : "
63                      << CXIOSManager::GetNbServer() << std::endl;
64
65            xios_map<StdString, XIOSClient>::iterator
66               iit  = CXIOSManager::Clients.begin(),
67               eend = CXIOSManager::Clients.end();
68
69            for (;iit != eend; iit++)
70            {
71               const StdPairStrClient & elem = *iit;
72               std::cout << " - " << elem.first
73                         << " > nombre de clients : "             << elem.second.nbClient
74                         << " , nombre de clients par serveur : " << elem.second.nbClientPServer
75                         << " , nombre de serveurs : "            << elem.second.nbClient/elem.second.nbClientPServer
76                         << std::endl;
77            }
78
79            std::cout << " *************************************** " << std::endl;
80         }
81
82         comm::CMPIManager::Barrier();
83         StdSize start = 0, end   = 0;
84         
85         xios_map<StdString, XIOSClient>::iterator
86            iit  = CXIOSManager::Clients.begin(),
87            eend = CXIOSManager::Clients.end();
88
89         for (;iit != eend; iit++)
90         {
91            const StdPairStrClient & elem = *iit;
92            MPIComm comm_client = 0, comm_client_grp = 0; comm_client_server = 0;
93
94            int       currentRank     = CMPIManager::GetCommRank();
95            StdString clientName      = elem.first;
96            StdSize   nbClient        = elem.second.nbClient;
97            StdSize   nbClientPServer = elem.second.nbClientPServer;
98            StdSize   nbServer        = elem.second.nbClient/elem.second.nbClientPServer;
99            StdSize   totalproc       = nbClient + nbServer;
100
101            for (StdSize i = 0; i<nbServer; i++)
102            {
103               end = start + nbClientPServer;
104               // Pas encore implémenté (interface de gestion de groupe/communicateur buggée)
105               start = start + nbClientPServer + 1;
106            }
107         }
108      }
109
110      void CXIOSManager::RunClient(comm::MPIComm comm_client)
111      {
112         (CXIOSManager::Clients.begin()->second.entry)(comm_client, comm_client, comm_client);
113      }
114
115      //---------------------------------------------------------------
116
117      void CXIOSManager::AddClient(StdString clientName, StdSize nbClient, StdSize nbClientPServer,
118                                   void (*entry_point)(comm::MPIComm, comm::MPIComm, comm::MPIComm))
119      {
120         StdSize nbprocess  = comm::CMPIManager::GetCommSize(comm::CMPIManager::GetCommWorld());
121         StdSize nbprocess_used = CXIOSManager::GetNbClient() + CXIOSManager::GetNbServer();
122
123         if (nbClient < nbClientPServer)
124            ERROR("CXIOSManager::AddClient(clientName, nbClient, nbClientPServer, entry_point)",
125                  << "nbClient < nbClientPServer");
126         if ((nbClient % nbClientPServer) != 0)
127            ERROR("CXIOSManager::AddClient(clientName, nbClient, nbClientPServer, entry_point)",
128                  << " (nbClient % nbClientPServer) != 0 !");
129         if ((nbprocess-nbprocess_used) < (nbClient + nbClient/nbClientPServer))
130            ERROR("CXIOSManager::AddClient(clientName, nbClient, nbClientPServer, entry_point)",
131                  << " Pas assez de processus disponibles !");
132         if (CXIOSManager::Clients.find(clientName) != CXIOSManager::Clients.end())
133            ERROR("CXIOSManager::AddClient(clientName, nbClient, nbClientPServer, entry_point)",
134                  << " Un client portant le même nom existe déjà !");
135
136         XIOSClient client = {nbClient, nbClientPServer, entry_point };
137         CXIOSManager::Clients[clientName] = client;
138      }
139
140      //---------------------------------------------------------------
141
142      StdSize CXIOSManager::GetNbClient(void)
143      {
144         switch (CXIOSManager::Type)
145         {
146            case (CLIENT_SERVER):
147            {
148               StdSize retvalue = 0;
149               typedef std::pair<StdString, XIOSClient> StdPairStrClient;
150               xios_map<StdString, XIOSClient>::iterator
151                  iit  = CXIOSManager::Clients.begin(),
152                  eend = CXIOSManager::Clients.end();
153
154               for (;iit != eend; iit++)
155               {
156                  const StdPairStrClient & elem = *iit;
157                  retvalue += CXIOSManager::GetNbLocClient(elem.first);
158               }
159               
160               return (retvalue);
161            }
162            case (CLIENT):
163               return (comm::CMPIManager::GetCommSize(CXIOSManager::Comm_Server));
164            case (SERVER):
165               return (comm::CMPIManager::GetCommSize(CXIOSManager::Comm_Client_Server) - 1);
166            default:
167               return (0);
168         }
169      }
170
171      StdSize CXIOSManager::GetNbLocClient(const StdString & clientName)
172      {
173         switch (CXIOSManager::Type)
174         {
175            case (CLIENT_SERVER):
176               return (CXIOSManager::Clients[clientName].nbClient);
177            case (CLIENT):
178            case (SERVER):
179               return (CXIOSManager::GetNbClient());
180            default:
181               return (0);
182         }
183      }
184
185      StdSize CXIOSManager::GetNbServer(void)
186      {
187         switch (CXIOSManager::Type)
188         {
189            case (CLIENT_SERVER):
190            {
191               StdSize retvalue = 0;
192               typedef std::pair<StdString, XIOSClient> StdPairStrClient;             
193
194               xios_map<StdString, XIOSClient>::iterator
195                  iit  = CXIOSManager::Clients.begin(),
196                  eend = CXIOSManager::Clients.end();
197
198               for (;iit != eend; iit++)
199               {
200                  const StdPairStrClient & elem = *iit;
201                  retvalue += CXIOSManager::GetNbLocServer(elem.first);
202               }                 
203                 
204               return (retvalue);
205            }
206            case (CLIENT):
207               return (comm::CMPIManager::GetCommSize(CXIOSManager::Comm_Server));
208            case (SERVER):
209               return (1);
210            default:
211               return (0);
212         }
213      }
214
215      StdSize CXIOSManager::GetNbLocServer(const StdString & clientName)
216      {
217         switch (CXIOSManager::Type)
218         {
219            case (CLIENT_SERVER):
220               return (CXIOSManager::Clients[clientName].nbClient /
221                       CXIOSManager::Clients[clientName].nbClientPServer);
222            case (CLIENT):
223            case (SERVER):
224               return (CXIOSManager::GetNbServer());
225            default:
226               return (0);
227         }
228      }
229
230      ///--------------------------------------------------------------
231
232} // namespace xmlioserver
Note: See TracBrowser for help on using the repository browser.