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 | class CMPIManager |
---|
43 | { |
---|
44 | public : // Initialisation & Finalisation |
---|
45 | |
---|
46 | static void Initialise(int * argc, char *** argv); |
---|
47 | static void Finalize(void); |
---|
48 | |
---|
49 | public : // Communicateurs |
---|
50 | |
---|
51 | static int GetCommRank(MPI_Comm comm = CMPIManager::GetCommWorld()); |
---|
52 | static int GetCommSize(MPI_Comm comm = CMPIManager::GetCommWorld()); |
---|
53 | static MPI_Comm CreateComm(MPI_Group group, MPI_Comm pcomm = CMPIManager::GetCommWorld()); |
---|
54 | static MPI_Comm GetCommWorld(void); |
---|
55 | |
---|
56 | public : // Autre |
---|
57 | |
---|
58 | static void Barrier(MPI_Comm comm = CMPIManager::GetCommWorld()); |
---|
59 | |
---|
60 | public : // Groupes |
---|
61 | |
---|
62 | static MPI_Group GetGroupWorld(void); |
---|
63 | static MPI_Group CreateSubGroup(MPI_Group pgroup, const std::vector<int> & ranks); |
---|
64 | static MPI_Group CreateSubGroup(MPI_Group pgroup, int min_rank, int max_rank, int intval = 1); |
---|
65 | |
---|
66 | public : // Tests |
---|
67 | |
---|
68 | static bool IsMaster(MPI_Comm comm = CMPIManager::GetCommWorld()); |
---|
69 | static bool IsRank(int rank, MPI_Comm comm = CMPIManager::GetCommWorld()); |
---|
70 | |
---|
71 | public : // Communication simple |
---|
72 | |
---|
73 | static void Send (MPI_Comm comm, int dest_rank, const char * data, |
---|
74 | std::size_t size, MPI_Request & request); |
---|
75 | static void Wait (MPI_Request & request); |
---|
76 | static bool Test (MPI_Request & request); |
---|
77 | |
---|
78 | static bool HasReceivedData(MPI_Comm comm, int src_rank); |
---|
79 | static std::size_t GetReceivedDataSize(MPI_Comm comm, int src_rank); |
---|
80 | static void Receive(MPI_Comm comm, int src_rank, char * data); |
---|
81 | |
---|
82 | public : // Communication 'complexe' |
---|
83 | |
---|
84 | // static void SendLinearBuffer(MPIComm comm, int dest_rank, CLinearBuffer & buff, MPIRequest & request); |
---|
85 | // static void ReceiveLinearBuffer(MPIComm comm, int src_rank, CLinearBuffer & buff); |
---|
86 | // static boost::shared_ptr<CLinearBuffer> ReceiveLinearBuffer(MPIComm comm, int src_rank); |
---|
87 | // static void ReceiveCircularBuffer(MPIComm comm, int src_rank, CCircularBuffer & buff); |
---|
88 | |
---|
89 | public : // Mémoire (non fonctionnel ....) |
---|
90 | |
---|
91 | static void AllocMemory(void * data, std::size_t size); |
---|
92 | static void FreeMemory (void * data); |
---|
93 | |
---|
94 | }; // class CMPIManager |
---|
95 | |
---|
96 | } // namespace comm |
---|
97 | } // namespace xmlioserver |
---|
98 | |
---|
99 | #endif //__MPI_INTERFACE_HPP__ |
---|