source: XMLIO_V2/dev/dev_rv/src/xmlio/manager/mpi_manager.hpp @ 267

Last change on this file since 267 was 267, checked in by hozdoba, 13 years ago
File size: 8.0 KB
Line 
1/* ************************************************************************** *
2 *      Copyright © IPSL/LSCE, XMLIOServer, Avril 2010 - Octobre 2011         *
3 * ************************************************************************** */
4
5#ifndef __MPI_INTERFACE_HPP__
6#define __MPI_INTERFACE_HPP__
7
8/**
9 * \file    mpi_interface.hpp
10 * \brief   Gestion des communications MPI via une surcouche interne (entête).
11 * \author  Hervé Ozdoba
12 * \version 0.4
13 * \date    28 Juin 2011
14 */
15
16#ifndef __XIOS_NO_EXTERN
17
18// M(essage) P(assing) I(nterface) headers
19#include <mpi.h>
20
21// C++ standard headers
22#include <vector>
23
24#endif //__XIOS_NO_EXTERN
25
26// XMLIOServer headers
27#include "xmlioserver_spl.hpp"
28#include "buffer.hpp"
29#include "circular_buffer.hpp"
30#include "linear_buffer.hpp"
31
32// ////////////////////////////// Déclarations ///////////////////////////// //
33
34namespace xmlioserver
35{
36   /// \brief Espace de nommage pour les communications via la bibliothÚque MPI.
37   namespace comm
38   {
39      typedef MPI_Fint     MPIComm; /*!< \brief Identifiant de communicateur MPI (Fortran).   */
40      typedef MPI_Fint    MPIGroup; /*!< \brief Identifiant de groupe MPI (Fortran).          */
41      typedef MPI_Fint  MPIRequest; /*!< \brief Identifiant de requête MPI (Fortran).         */
42      typedef MPI_Fint  *MPIStatus; /*!< \brief Identifiant de statut MPI (Fortran).          */
43      typedef MPI_Fint MPIDataType; /*!< \brief Identifiant de type de données MPI (Fortran). */
44     
45      /**
46       * \class CMPIManager
47       * \brief Surcouche interne de la bibliàothÚque M(essage) P(assing) I(nterface).
48       */
49      class CMPIManager
50      {
51         public : // Initialisation & Finalisation
52         
53            static void Initialise(int * argc, char *** argv);
54            static void Finalize(void);
55
56         public : // Communicateurs
57         
58         
59            static inline int GetCommRank(MPIComm _comm)           
60            { return (CMPIManager::GetCommRank(MPI_Comm_f2c(_comm))); }   
61                   
62            static inline int GetCommSize(MPIComm _comm)           
63            { return (CMPIManager::GetCommSize(MPI_Comm_f2c(_comm))); }
64           
65            static inline MPIComm GetCommWorld(void)           
66            { return (MPI_Comm_c2f(MPI_COMM_WORLD)); }
67           
68            static inline MPIComm CreateComm(MPI_Group _group, MPIComm _pcomm = CMPIManager::GetCommWorld())
69            { return (MPI_Comm_c2f(CMPIManager::CreateComm( _group, MPI_Comm_f2c(_pcomm)))); }     
70           
71            static int GetCommRank(MPI_Comm _comm = MPI_COMM_WORLD);
72            static int GetCommSize(MPI_Comm _comm = MPI_COMM_WORLD);       
73           
74            static MPI_Comm CreateComm(MPI_Group _group, MPI_Comm _pcomm);
75
76         public : // Autre
77         
78            static void Barrier(MPI_Comm _comm = MPI_COMM_WORLD);
79           
80            static inline bool DispatchClient(bool       _is_server,
81                                              MPIComm & _comm_client,
82                                              MPIComm & _comm_client_server,
83                                              MPIComm & _comm_server,
84                                              MPIComm   _comm_parent =  CMPIManager::GetCommWorld())
85            {
86               MPI_Comm comm_client        = MPI_Comm_f2c(_comm_client);
87               MPI_Comm comm_client_server = MPI_Comm_f2c(_comm_client_server);
88               MPI_Comm comm_server        = MPI_Comm_f2c(_comm_server);
89               MPI_Comm comm_parent        = MPI_Comm_f2c(_comm_parent);
90               bool ret = CMPIManager::DispatchClient(_is_server, comm_client, comm_client_server, comm_server, comm_parent);
91               _comm_client        = MPI_Comm_c2f(comm_client);
92               _comm_client_server = MPI_Comm_c2f(comm_client_server);
93               _comm_server        = MPI_Comm_c2f(comm_server); 
94               return (ret);                         
95            }
96                                     
97           
98            static bool DispatchClient(bool       _is_server,
99                                       MPI_Comm & _comm_client,
100                                       MPI_Comm & _comm_client_server,
101                                       MPI_Comm & _comm_server,
102                                       MPI_Comm   _comm_parent = MPI_COMM_WORLD);
103
104         public : // Groupes
105         
106            static MPI_Group GetGroupWorld(void);
107            static MPI_Group CreateSubGroup(MPI_Group _pgroup, const std::vector<int> & _ranks);
108            static MPI_Group CreateSubGroup(MPI_Group _pgroup, int _min_rank, int _max_rank, int _intval = 1);
109
110         public : // Tests
111         
112            static inline bool IsMaster(MPIComm _comm)
113            { return (CMPIManager::IsMaster(MPI_Comm_f2c(_comm))); }
114           
115            static inline bool IsRank(int _rank, MPIComm _comm)
116            { return (CMPIManager::IsRank(_rank, MPI_Comm_f2c(_comm))); }
117         
118            static bool IsMaster(MPI_Comm _comm = MPI_COMM_WORLD);
119            static bool IsRank(int _rank, MPI_Comm _comm = MPI_COMM_WORLD);
120
121         public : // Communication simple
122         
123            static void Send (MPI_Comm _comm, int _dest_rank, char * _data,
124                              std::size_t _size, MPI_Request & _request);
125            static void Wait (MPI_Request & _request);
126            static bool Test (MPI_Request & _request);
127
128
129            static inline bool HasReceivedData(MPIComm _comm, int _src_rank)
130            { return (CMPIManager::HasReceivedData(MPI_Comm_f2c(_comm), _src_rank));  }
131           
132            static inline std::size_t GetReceivedDataSize(MPIComm _comm, int _src_rank)
133            { return (CMPIManager::GetReceivedDataSize(MPI_Comm_f2c(_comm), _src_rank)); }
134           
135           
136           
137            static bool HasReceivedData(MPI_Comm _comm, int _src_rank);
138           
139            static std::size_t GetReceivedDataSize(MPI_Comm _comm, int _src_rank);
140            static void Receive(MPI_Comm _comm, int _src_rank, char * _data);
141           
142            static void AllGather(int _indata, std::vector<int> & _outdata,
143                                  MPI_Comm _comm = MPI_COMM_WORLD);
144
145            static void AllGather(const std::vector<int> & _indata,
146                                        std::vector<int> & _outdata,
147                                  MPI_Comm _comm = MPI_COMM_WORLD);
148
149
150         public : // Communication 'complexe'
151         
152            static inline void SendLinearBuffer(MPIComm _comm, int _dest_rank, CLinearBuffer & _lbuffer, MPI_Request & _request)
153            { CMPIManager::SendLinearBuffer(MPI_Comm_f2c(_comm), _dest_rank, _lbuffer, _request); }
154           
155            static inline void ReceiveLinearBuffer(MPIComm _comm, int _src_rank, CLinearBuffer & _lbuffer)
156            { CMPIManager::ReceiveLinearBuffer(MPI_Comm_f2c(_comm), _src_rank, _lbuffer); }
157           
158            static inline boost::shared_ptr<CLinearBuffer> ReceiveLinearBuffer(MPIComm _comm, int _src_rank)
159            { return (CMPIManager::ReceiveLinearBuffer(MPI_Comm_f2c(_comm), _src_rank)); }
160           
161            static inline void ReceiveCircularBuffer(MPIComm _comm, int _src_rank, CCircularBuffer & _cbuffer)
162            { CMPIManager::ReceiveCircularBuffer(MPI_Comm_f2c(_comm), _src_rank, _cbuffer); }
163           
164         
165            static void SendLinearBuffer(MPI_Comm _comm, int _dest_rank, CLinearBuffer & _lbuffer, MPI_Request & _request);
166            static void ReceiveLinearBuffer(MPI_Comm _comm, int _src_rank, CLinearBuffer & _lbuffer);
167            static boost::shared_ptr<CLinearBuffer> ReceiveLinearBuffer(MPI_Comm _comm, int _src_rank);
168            static void ReceiveCircularBuffer(MPI_Comm _comm, int _src_rank, CCircularBuffer & _cbuffer);
169           
170           
171
172         public : // Mémoire (non fonctionnel ....)
173         
174            static void AllocMemory(void * _data, std::size_t _size);
175            static void FreeMemory (void * _data);
176         
177      }; // class CMPIManager
178     
179
180     
181   } // namespace comm
182} // namespace xmlioserver
183
184#endif //__MPI_INTERFACE_HPP__
Note: See TracBrowser for help on using the repository browser.