]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/ParaMEDMEM/CommInterface.cxx
Salome HOME
MEDFileUMesh.LoadPartCoords + ParaDataArray implementation
[tools/medcoupling.git] / src / ParaMEDMEM / CommInterface.cxx
1 // Copyright (C) 2007-2020  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, or (at your option) any later version.
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
20 #include "CommInterface.hxx"
21
22 namespace MEDCoupling
23 {
24   MPI_Datatype ParaTraits<double>::MPIDataType = MPI_DOUBLE;
25
26   MPI_Datatype ParaTraits<Int32>::MPIDataType = MPI_INT;
27
28   MPI_Datatype ParaTraits<Int64>::MPIDataType = MPI_LONG;
29
30   /*! \anchor CommInterface-det
31      \class CommInterface
32
33     The class \a CommInterface is the gateway to the MPI library.
34     It is a wrapper around all MPI calls, thus trying to abstract the rest of the code from using the direct MPI API
35     (but this is not strictly respected overall in practice ...). It is used in all
36     the \ref parallel "DEC related classes".
37
38     It is typically instantiated after the MPI_Init() call in a program and is afterwards passed as a
39     parameter to the constructors of various \ref parallel "parallel objects" so that they access the
40     MPI library via this common interface.
41
42     As an example, the following code excerpt initializes a processor group made of the zero processor.
43
44     \verbatim
45     #include "CommInterface.hxx"
46     #include "ProcessorGroup.hxx"
47
48     int main(int argc, char** argv)
49     {
50     //initialization
51     MPI_Init(&argc, &argv);
52     MEDCoupling::CommInterface comm_interface;
53
54     //setting up a processor group with proc 0
55     set<int> procs;
56     procs.insert(0);
57     MEDCoupling::ProcessorGroup group(procs, comm_interface);
58
59     //cleanup
60     MPI_Finalize();
61     }
62     \endverbatim
63   */
64
65   void CommInterface::gatherArrays(MPI_Comm comm, int root, const DataArrayIdType *array, std::vector< MCAuto<DataArrayIdType> >& arraysOut) const
66   {
67     this->gatherArraysT2<mcIdType>(comm,root,array,arraysOut);
68   }
69
70   /*!
71    * Generalized AllGather collective communication.
72    * This method send input \a array to all procs.
73    */
74   void CommInterface::allGatherArrays(MPI_Comm comm, const DataArrayIdType *array, std::vector< MCAuto<DataArrayIdType> >& arraysOut) const
75   {
76     this->allGatherArraysT2<mcIdType>(comm,array,arraysOut);
77   }
78
79   /*!
80    * Generalized AllGather collective communication.
81    * This method send input \a array to all procs.
82    */
83   int CommInterface::allGatherArrays(MPI_Comm comm, const DataArrayIdType *array, std::unique_ptr<mcIdType[]>& result, std::unique_ptr<mcIdType[]>& resultIndex) const
84   {
85     return this->allGatherArraysT<mcIdType>(comm,array,result,resultIndex);
86   }
87
88   void CommInterface::allToAllArrays(MPI_Comm comm, const std::vector< MCAuto<DataArrayDouble> >& arrays, std::vector< MCAuto<DataArrayDouble> >& arraysOut) const
89   {
90     this->allToAllArraysT<double>(comm,arrays,arraysOut);
91   }
92
93   void CommInterface::allToAllArrays(MPI_Comm comm, const std::vector< MCAuto<DataArrayDouble> >& arrays, MCAuto<DataArrayDouble>& arraysOut) const
94   {
95     std::unique_ptr<mcIdType[]> notUsed1;
96     mcIdType notUsed2;
97     this->allToAllArraysT2<double>(comm,arrays,arraysOut,notUsed1,notUsed2);
98   }
99
100   /*!
101   * Generalized AllToAll collective communication.
102   */
103   void CommInterface::allToAllArrays(MPI_Comm comm, const std::vector< MCAuto<DataArrayIdType> >& arrays, std::vector< MCAuto<DataArrayIdType> >& arraysOut) const
104   {
105     this->allToAllArraysT<mcIdType>(comm,arrays,arraysOut);
106   }
107
108 }