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 | |
---|
29 | // ////////////////////////////// Déclarations ///////////////////////////// // |
---|
30 | |
---|
31 | namespace xmlioserver |
---|
32 | { |
---|
33 | /// \brief Espace de nommage pour les communications via la bibliothÚque MPI. |
---|
34 | namespace comm |
---|
35 | { |
---|
36 | typedef MPI_Fint MPI_F_Comm; /*!< \brief Identifiant de communicateur MPI (Fortran). */ |
---|
37 | typedef MPI_Fint MPI_F_Group; /*!< \brief Identifiant de groupe MPI (Fortran). */ |
---|
38 | typedef MPI_Fint MPI_F_Request; /*!< \brief Identifiant de requête MPI (Fortran). */ |
---|
39 | typedef MPI_Fint *MPI_F_Status; /*!< \brief Identifiant de statut MPI (Fortran). */ |
---|
40 | typedef MPI_Fint MPI_F_DataType; /*!< \brief Identifiant de type de données MPI (Fortran). */ |
---|
41 | |
---|
42 | /** |
---|
43 | * \class CMPIManager |
---|
44 | * \brief Surcouche interne de la biblià othÚque M(essage) P(assing) I(nterface). |
---|
45 | */ |
---|
46 | class CMPIManager |
---|
47 | { |
---|
48 | public : // Initialisation & Finalisation |
---|
49 | |
---|
50 | static void Initialise(int * argc, char *** argv); |
---|
51 | static void Finalize(void); |
---|
52 | |
---|
53 | public : // Communicateurs |
---|
54 | |
---|
55 | static int GetCommRank(MPI_Comm _comm = CMPIManager::GetCommWorld()); |
---|
56 | static int GetCommSize(MPI_Comm _comm = CMPIManager::GetCommWorld()); |
---|
57 | static MPI_Comm CreateComm(MPI_Group _group, MPI_Comm _pcomm = CMPIManager::GetCommWorld()); |
---|
58 | static MPI_Comm GetCommWorld(void); |
---|
59 | |
---|
60 | public : // Autre |
---|
61 | |
---|
62 | static void Barrier(MPI_Comm _comm = CMPIManager::GetCommWorld()); |
---|
63 | |
---|
64 | static bool DispatchClient(bool _is_server, |
---|
65 | MPI_Comm & _comm_client, |
---|
66 | MPI_Comm & _comm_client_server, |
---|
67 | MPI_Comm & _comm_server, |
---|
68 | MPI_Comm _comm_parent = CMPIManager::GetCommWorld()); |
---|
69 | |
---|
70 | public : // Groupes |
---|
71 | |
---|
72 | static MPI_Group GetGroupWorld(void); |
---|
73 | static MPI_Group CreateSubGroup(MPI_Group _pgroup, const std::vector<int> & _ranks); |
---|
74 | static MPI_Group CreateSubGroup(MPI_Group _pgroup, int _min_rank, int _max_rank, int _intval = 1); |
---|
75 | |
---|
76 | public : // Tests |
---|
77 | |
---|
78 | static bool IsMaster(MPI_Comm _comm = CMPIManager::GetCommWorld()); |
---|
79 | static bool IsRank(int _rank, MPI_Comm _comm = CMPIManager::GetCommWorld()); |
---|
80 | |
---|
81 | public : // Communication simple |
---|
82 | |
---|
83 | static void Send (MPI_Comm _comm, int _dest_rank, char * _data, |
---|
84 | std::size_t _size, MPI_Request & _request); |
---|
85 | static void Wait (MPI_Request & _request); |
---|
86 | static bool Test (MPI_Request & _request); |
---|
87 | |
---|
88 | static bool HasReceivedData(MPI_Comm _comm, int _src_rank); |
---|
89 | static std::size_t GetReceivedDataSize(MPI_Comm _comm, int _src_rank); |
---|
90 | static void Receive(MPI_Comm _comm, int _src_rank, char * _data); |
---|
91 | |
---|
92 | static void AllGather(int _indata, std::vector<int> & _outdata, |
---|
93 | MPI_Comm _comm = CMPIManager::GetCommWorld()); |
---|
94 | |
---|
95 | static void AllGather(const std::vector<int> & _indata, |
---|
96 | std::vector<int> & _outdata, |
---|
97 | MPI_Comm _comm = CMPIManager::GetCommWorld()); |
---|
98 | |
---|
99 | |
---|
100 | public : // Communication 'complexe' |
---|
101 | |
---|
102 | /*static void SendLinearBuffer(MPI_Comm _comm, int _dest_rank, CLinearBuffer & _lbuffer, MPI_Request & _request); |
---|
103 | static void ReceiveLinearBuffer(MPI_Comm _comm, int _src_rank, CLinearBuffer & _lbuffer); |
---|
104 | static boost::shared_ptr<CLinearBuffer> ReceiveLinearBuffer(MPI_Comm _comm, int _src_rank); |
---|
105 | static void ReceiveCircularBuffer(MPI_Comm _comm, int _src_rank, CCircularBuffer & _cbuffer);*/ |
---|
106 | |
---|
107 | public : // Mémoire (non fonctionnel ....) |
---|
108 | |
---|
109 | static void AllocMemory(void * _data, std::size_t _size); |
---|
110 | static void FreeMemory (void * _data); |
---|
111 | |
---|
112 | }; // class CMPIManager |
---|
113 | |
---|
114 | } // namespace comm |
---|
115 | } // namespace xmlioserver |
---|
116 | |
---|
117 | #endif //__MPI_INTERFACE_HPP__ |
---|