1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef __MEDPARTITIONER_UTILS_HXX__
21 #define __MEDPARTITIONER_UTILS_HXX__
23 #include "MEDPARTITIONER.hxx"
25 #include "MEDCouplingUMesh.hxx"
31 //# define LOCALIZED(message) #message , __FILE__ , __FUNCTION__ , __LINE__
33 namespace MEDPARTITIONER
35 MEDPARTITIONER_EXPORT std::string Trim(const std::string& s,const std::string& drop);
36 MEDPARTITIONER_EXPORT std::string IntToStr(const int i);
37 MEDPARTITIONER_EXPORT std::string DoubleToStr(const double i);
38 MEDPARTITIONER_EXPORT int StrToInt(const std::string& s);
39 MEDPARTITIONER_EXPORT double StrToDouble(const std::string& s);
40 MEDPARTITIONER_EXPORT bool TestArg(const char *arg, const char *argExpected, std::string& argValue);
41 MEDPARTITIONER_EXPORT std::vector<int> CreateRandomSize(const int size);
42 MEDPARTITIONER_EXPORT void RandomizeAdj(int* xadj, int* adjncy, std::vector<int>& ran, std::vector<int>& vx, std::vector<int>& va);
43 MEDPARTITIONER_EXPORT void TestRandomize();
45 MEDPARTITIONER_EXPORT std::string ReprVectorOfString(const std::vector<std::string>& vec);
46 MEDPARTITIONER_EXPORT std::string ReprVectorOfString(const std::vector<std::string>& vec, const std::string separator);
47 MEDPARTITIONER_EXPORT std::string ReprMapOfStringInt(const std::map<std::string,int>& mymap);
48 MEDPARTITIONER_EXPORT std::string ReprMapOfStringVectorOfString(const std::map< std::string,std::vector<std::string> >& mymap);
49 MEDPARTITIONER_EXPORT std::string ReprFieldDescriptions(const std::vector<std::string>& vec,const std::string separator);
51 MEDPARTITIONER_EXPORT std::string SerializeFromString(const std::string& s);
52 MEDPARTITIONER_EXPORT std::string SerializeFromVectorOfString(const std::vector<std::string>& vec);
53 MEDPARTITIONER_EXPORT std::vector<std::string> DeserializeToVectorOfString(const std::string& str);
54 MEDPARTITIONER_EXPORT std::string EraseTagSerialized(const std::string& fromStr, const std::string& tag);
56 MEDPARTITIONER_EXPORT std::vector<std::string> VectorizeFromMapOfStringInt(const std::map<std::string,int>& mymap);
57 MEDPARTITIONER_EXPORT std::map<std::string,int> DevectorizeToMapOfStringInt(const std::vector<std::string>& vec);
59 MEDPARTITIONER_EXPORT std::vector<std::string> VectorizeFromMapOfStringVectorOfString(const std::map< std::string,std::vector<std::string> >& mymap);
60 MEDPARTITIONER_EXPORT std::map< std::string,std::vector<std::string> > DevectorizeToMapOfStringVectorOfString(const std::vector<std::string>& vec);
62 MEDPARTITIONER_EXPORT std::vector<std::string> SelectTagsInVectorOfString(const std::vector<std::string>& vec, const std::string tag);
63 MEDPARTITIONER_EXPORT std::vector<std::string> DeleteDuplicatesInVectorOfString(const std::vector<std::string>& vec);
64 MEDPARTITIONER_EXPORT std::map< std::string,std::vector<std::string> > DeleteDuplicatesInMapOfStringVectorOfString(const std::map< std::string,std::vector<std::string> >& mymap);
66 MEDPARTITIONER_EXPORT std::string Cle1ToStr(const std::string& s, const int inew);
67 MEDPARTITIONER_EXPORT void Cle1ToData(const std::string& cle, std::string& s, int& inew);
69 MEDPARTITIONER_EXPORT std::string Cle2ToStr(const std::string& s,const int inew,const int iold);
70 MEDPARTITIONER_EXPORT void Cle2ToData(const std::string& cle, std::string& s, int& inew, int& iold);
72 MEDPARTITIONER_EXPORT std::string ExtractFromDescription(const std::string& description,const std::string& tag);
73 MEDPARTITIONER_EXPORT void FieldDescriptionToData(const std::string& description,
74 int& idomain, std::string& fileName, std::string& meshName, std::string& fieldName,
75 int& typeField, int& DT, int& IT);
76 MEDPARTITIONER_EXPORT void FieldShortDescriptionToData(const std::string& description,
77 std::string& fieldName, int& typeField, int& entity, int& DT, int& IT);
79 ParaMEDMEM::DataArrayInt *CreateDataArrayIntFromVector(const std::vector<int>& v);
80 ParaMEDMEM::DataArrayInt *CreateDataArrayIntFromVector(const std::vector<int>& v, const int nbComponents);
81 ParaMEDMEM::DataArrayDouble *CreateDataArrayDoubleFromVector(const std::vector<double>& v);
83 ParaMEDMEM::MEDCouplingUMesh *CreateEmptyMEDCouplingUMesh();
85 std::vector<std::string> BrowseFieldDouble(const ParaMEDMEM::MEDCouplingFieldDouble* fd);
86 std::vector<std::string> BrowseAllFields(const std::string& myfile);
87 std::vector<std::string> BrowseAllFieldsOnMesh(const std::string& myfile, const std::string& mymesh, const int idomain);
88 std::vector<std::string> GetInfosOfField(const char *fileName, const char *meshName, const int idomain );
91 //not adviced, interblocking, use sendAndReceive
92 //void SendVectorOfString(const std::vector<std::string>& vec, const int target);
93 //std::vector<std::string> RecvVectorOfString(const int source);
94 //TODO void sendRecvVectorOfString(const std::vector<std::string>& vec, const int source, const int target);
95 MEDPARTITIONER_EXPORT std::vector<std::string> SendAndReceiveVectorOfString(const std::vector<std::string>& vec, const int source, const int target);
96 MEDPARTITIONER_EXPORT std::vector<std::string> AllgathervVectorOfString(const std::vector<std::string>& vec);
98 void SendDoubleVec(const std::vector<double>& vec, const int target);
99 std::vector<double> *RecvDoubleVec(const int source);
100 void RecvDoubleVec(std::vector<double>& vec, const int source);
102 void SendIntVec(const std::vector<int>& vec, const int target);
103 std::vector<int>* RecvIntVec(int source);
104 void RecvIntVec(std::vector<int>& vec, const int source);
106 void SendDataArrayInt(const ParaMEDMEM::DataArrayInt* da, const int target);
107 ParaMEDMEM::DataArrayInt *RecvDataArrayInt(const int source);
108 void SendDataArrayDouble(const ParaMEDMEM::DataArrayDouble* da, const int target);
109 ParaMEDMEM::DataArrayDouble *RecvDataArrayDouble(const int source);
111 void TestVectorOfStringMpi();
112 void TestMapOfStringIntMpi();
113 void TestMapOfStringVectorOfStringMpi();
114 void TestDataArrayMpi();
115 void TestPersistantMpi0To1(int taille, int nb);
116 void TestPersistantMpiRing(int taille, int nb);
117 void TestPersistantMpiRingOnCommSplit(int taille, int nb);
120 class MEDPARTITIONER_EXPORT MyGlobals
123 static int _Verbose; //0 to 1000 over 200 is debug
125 static int _World_Size;
126 static int _Randomize;
128 static int _Creates_Boundary_Faces;
129 static int _Is0verbose; //trace cout if rank 0 and verbose
130 static std::vector<std::string> _File_Names; //on [iold]
131 static std::vector<std::string> _Mesh_Names; //on [iold]
132 static std::vector<std::string> _Field_Descriptions;
133 /*! used for descriptions of components of fields for example...*/
134 static std::vector<std::string> _General_Informations;