Salome HOME
Merge from V6_main 01/04/2013
[modules/med.git] / src / MEDSPLITTER / MEDSPLITTER_MeshSendReceive.hxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // File      : MEDSPLITTER_MeshSendReceive.hxx
20 // Created   : Tue Jun 30 19:14:51 2009
21 // Author    : Edward AGAPOV (eap)
22
23
24 #ifndef __MEDSPLITTER_MeshSendReceive_HXX__
25 #define __MEDSPLITTER_MeshSendReceive_HXX__
26
27 #include "MEDSPLITTER.hxx"
28
29 #ifdef HAVE_MPI2
30 #include <mpi.h>
31 #else
32 typedef int MPI_Request;
33 #endif
34
35 #include <vector>
36
37 namespace MEDMEM
38 {
39   class MESH;
40 }
41
42 namespace MEDSPLITTER
43 {
44   /*!
45    * \brief Sender-receiver of the mesh.
46    *
47    * We also send-receive
48    * 1) global node ids for the sake of fusing domain parts
49    * 2) global cell ids for the sake of detecting cell/cell joints using global graph
50    * 3) global face ids for the sake of not losing face sharing among domains
51    */
52   class MEDSPLITTER_EXPORT MeshSendReceive
53   {
54   public:
55
56     MeshSendReceive();
57     ~MeshSendReceive();
58
59     // Sends the mesh of idomain to irank processor asynchronously
60     // WARNING: do NOT delete the mesh until this->isSent()!
61     void send(int irank, int idomain, MEDMEM::MESH* mesh,
62               const std::vector<int>& cell_glob_nums,
63               const std::vector<int>& face_glob_nums,
64               const std::vector<int>& node_glob_nums);
65
66     // Receives the mesh of idomain from irank processor synchronously
67     MEDMEM::MESH* recv(int irank, int idomain,
68                        std::vector<int>& cell_glob_numbers,
69                        std::vector<int>& face_glob_numbers,
70                        std::vector<int>& node_glob_numbers);
71
72      //!< Returns the received or sent mesh. The user is resposible for freeing the received mesh.
73     MEDMEM::MESH* getMesh() { return _mesh; }
74
75     // Returns true if mesh is already sent
76     bool isSent();
77
78     // Frees buffers waiting until isSent()
79     void clear();
80
81   private:
82
83     std::vector< int > _int_buf;
84     std::vector< int > _node_glob_numbers, _cell_glob_numbers, _face_glob_numbers;
85     std::vector< char> _char_buf;
86
87     MEDMEM::MESH*      _mesh;
88
89     MPI_Request        _int_request, _coord_request, _char_request;
90     MPI_Request        _node_nums_request, _cell_nums_request, _face_nums_request;
91   };
92 }
93
94
95 #endif