1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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
23 medpartitioner --input-file=blade.med --output-file=ttmp1_ --ndomains=2 --dump-cpu-memory --verbose=$verb
24 medpartitioner --input-file=medpartitioner_blade.xml --output-file=ttmp1_ --ndomains=2 --dump-cpu-memory --verbose=$verb
25 medpartitioner --input-file=ttmp1_.xml --output-file=tttmp1_ --ndomains=4 --dump-cpu-memory --verbose=$verb
29 #include "MEDPARTITIONER_Graph.hxx"
30 #include "MEDPARTITIONER_Topology.hxx"
31 #include "MEDPARTITIONER_ParaDomainSelector.hxx"
32 #include "MEDPARTITIONER_MeshCollection.hxx"
33 #include "MEDPARTITIONER_Utils.hxx"
36 #include "MEDPARTITIONER_MeshCollection.hxx"
37 #include "MEDPARTITIONER_ParallelTopology.hxx"
38 #include "MEDPARTITIONER_ParaDomainSelector.hxx"
39 #include "MEDPARTITIONER_Utils.hxx"
48 using namespace MEDPARTITIONER;
50 int main(int argc, char** argv)
52 #if !defined(MED_ENABLE_METIS) && !defined(MED_ENABLE_SCOTCH)
53 std::cout << "Sorry, no one split method is available. Please, compile with METIS or SCOTCH." << std::endl;
58 // by parsing the command line
60 bool split_family=false;
61 bool empty_groups=false;
62 bool mesure_memory=false;
63 bool filter_face=true;
68 string library="metis"; //default
73 MyGlobals::_World_Size=1;
75 MyGlobals::_Creates_Boundary_Faces=0;
77 // Primitive parsing of command-line options
78 string desc ("Available options of medpartitioner V1.0:\n"
79 "\t--help : produces this help message\n"
80 "\t--verbose : echoes arguments\n"
81 "\t--input-file=<string> : name of the input .med file or .xml master file\n"
82 "\t--output-file=<string> : name of the resulting file (without extension)\n"
83 "\t--ndomains=<number> : number of subdomains in the output file, default is 1\n"
84 #if defined(MED_ENABLE_METIS) && defined(MED_ENABLE_SCOTCH)
86 "\t--split-method=<string> : name of the splitting library (metis/scotch), default is metis\n"
88 "\t--creates-boundary-faces : creates boundary faces mesh in the output files\n"
89 "\t--dump-cpu-memory : dumps passed CPU time and maximal increase of used memory\n"
94 for (int i = 1; i < argc; i++)
96 if (strlen(argv[i]) < 3)
98 cerr << "bad argument : "<< argv[i] << endl;
102 if (TestArg(argv[i],"--verbose",value))
104 MyGlobals::_Verbose=1;
105 if (value!="") MyGlobals::_Verbose = atoi(value.c_str());
107 else if (TestArg(argv[i],"--help",value)) help=1;
108 // else if (TestArg(argv[i],"--test",value)) test=1;
109 else if (TestArg(argv[i],"--input-file",value)) input=value;
110 else if (TestArg(argv[i],"--output-file",value)) output=value;
111 else if (TestArg(argv[i],"--split-method",value)) library=value;
112 else if (TestArg(argv[i],"--ndomains",value)) ndomains=atoi(value.c_str());
113 else if (TestArg(argv[i],"--creates-boundary-faces",value)) MyGlobals::_Creates_Boundary_Faces=1;
114 else if (TestArg(argv[i],"--dump-cpu-memory",value)) mesure_memory=true;
117 cerr << "unknown argument : "<< argv[i] << endl;
122 MyGlobals::_Is0verbose=MyGlobals::_Verbose;
125 #if defined(MED_ENABLE_METIS) && !defined(MED_ENABLE_SCOTCH)
128 #if !defined(MED_ENABLE_METIS) && defined(MED_ENABLE_SCOTCH)
132 #if defined(MED_ENABLE_METIS) && defined(MED_ENABLE_SCOTCH)
133 if ((library!="metis") && (library!="scotch"))
135 cerr << "split-method only available : metis, scotch" << endl;
146 if (MyGlobals::_Is0verbose)
148 cout << "medpartitioner V1.0 :" << endl;
149 cout << " input-file = " << input << endl;
150 cout << " output-file = " << output << endl;
151 cout << " split-method = " << library << endl;
152 cout << " ndomains = " << ndomains << endl;
153 cout << " creates_boundary_faces = " << MyGlobals::_Creates_Boundary_Faces << endl;
154 cout << " dump-cpu-memory = " << mesure_memory<< endl;
155 cout << " verbose = " << MyGlobals::_Verbose << endl;
157 //testing whether it is possible to write a file at the specified location
158 if (MyGlobals::_Rank==0)
160 string outputtest = output + ".testioms.";
161 ofstream testfile (outputtest.c_str());
164 cerr << "output-file directory does not exist or is in read-only access" << endl;
168 remove(outputtest.c_str());
171 // Beginning of the computation
173 // Loading the mesh collection
174 if (MyGlobals::_Is0verbose) cout << "Reading input files "<<endl;
178 /*MEDPARTITIONER::ParaDomainSelector parallelizer(mesure_memory);
179 MEDPARTITIONER::MeshCollection collection(input,parallelizer);
180 MEDPARTITIONER::ParallelTopology* aPT = (MEDPARTITIONER::ParallelTopology*) collection.getTopology();
181 aPT->setGlobalNumerotationDefault(collection.getParaDomainSelector());
182 //int nbfiles=MyGlobals::_fileMedNames->size(); //nb domains
183 //to have unique valid fields names/pointers/descriptions for partitionning
184 collection.prepareFieldDescriptions();
185 //int nbfields=collection.getFieldDescriptions().size(); //on all domains
186 //cout<<ReprVectorOfString(collection.getFieldDescriptions());
188 if (MyGlobals::_Is0verbose)
190 cout<<"fileNames :"<<endl
191 <<ReprVectorOfString(MyGlobals::_File_Names);
192 cout<<"fieldDescriptions :"<<endl
193 <<ReprFieldDescriptions(collection.getFieldDescriptions()," "); //cvwat07
194 cout<<"familyInfo :\n"
195 <<ReprMapOfStringInt(collection.getFamilyInfo())<<endl;
196 cout<<"groupInfo :\n"
197 <<ReprMapOfStringVectorOfString(collection.getGroupInfo())<<endl;
199 MEDPARTITIONER::ParaDomainSelector parallelizer(mesure_memory);
200 MEDPARTITIONER::MeshCollection collection(input,parallelizer);
201 MEDPARTITIONER::ParallelTopology* aPT = (MEDPARTITIONER::ParallelTopology*) collection.getTopology();
202 aPT->setGlobalNumerotationDefault(collection.getParaDomainSelector());
203 //to have unique valid fields names/pointers/descriptions for partitionning
204 collection.prepareFieldDescriptions();
206 //MEDPARTITIONER::MeshCollection collection(input);
208 //Creating the graph and partitioning it
209 if (MyGlobals::_Is0verbose) cout << "Computing partition with " << library << endl;
211 auto_ptr< MEDPARTITIONER::Topology > new_topo;
212 if (library == "metis")
213 new_topo.reset( collection.createPartition(ndomains,MEDPARTITIONER::Graph::METIS));
215 new_topo.reset( collection.createPartition(ndomains,MEDPARTITIONER::Graph::SCOTCH));
216 parallelizer.evaluateMemory();
218 //Creating a new mesh collection from the partitioning
219 if (MyGlobals::_Is0verbose) cout << "Creating new meshes"<< endl;
220 MEDPARTITIONER::MeshCollection new_collection(collection,new_topo.get(),split_family,empty_groups);
222 if (filter_face) new_collection.filterFaceOnCell();
224 //to get infos on all procs
227 vector<string> finalInformations;
228 vector<string> r1,r2;
229 //r1=AllgathervVectorOfString(MyGlobals::_General_Informations);
230 r1=MyGlobals::_General_Informations;
231 //if (MyGlobals::_Is0verbose>1000) cout << "generalInformations : \n"<<ReprVectorOfString(r1);
232 r2=SelectTagsInVectorOfString(r1,"ioldDomain=");
233 r2=SelectTagsInVectorOfString(r2,"meshName=");
234 if (r2.size()==(collection.getMesh()).size())
236 for (std::size_t i=0; i<r2.size(); i++)
237 r2[i]=EraseTagSerialized(r2[i],"ioldDomain=");
238 r2=DeleteDuplicatesInVectorOfString(r2);
241 string finalMesh="finalMeshName="+ExtractFromDescription(r2[0], "meshName=");
242 finalInformations.push_back(SerializeFromString(finalMesh));
245 if (finalInformations.size()==0)
247 if (MyGlobals::_Rank==0)
248 cerr<<"Problem on final meshName : set at 'Merge'"<<endl;
249 finalInformations.push_back(SerializeFromString("finalMeshName=Merge"));
252 //see field info nbComponents & componentInfo (if fields present)
253 r2=SelectTagsInVectorOfString(r1,"fieldName=");
254 r2=SelectTagsInVectorOfString(r2,"nbComponents=");
255 //may be yes? or not?
256 for (std::size_t i=0; i<r2.size(); i++)
257 r2[i]=EraseTagSerialized(r2[i],"ioldFieldDouble=");
258 r2=DeleteDuplicatesInVectorOfString(r2);
259 for (std::size_t i=0; i<r2.size(); i++)
260 finalInformations.push_back(r2[i]);
262 MyGlobals::_General_Informations=finalInformations;
263 if (MyGlobals::_Is0verbose)
264 cout << "generalInformations : \n"<<ReprVectorOfString(finalInformations);
266 //new_collection.setSubdomainBoundaryCreates(creates_boundary_faces);
267 if (MyGlobals::_Is0verbose) cout << "Writing "<<ndomains<<" output files "<<output<<"xx.med"<<" and "<<output<<".xml"<<endl;
268 new_collection.write(output);
270 /*if ( mesure_memory )
271 if ( parallelizer.isOnDifferentHosts() || MyGlobals::_Rank==0 )
273 cout << "Elapsed time = " << parallelizer.getPassedTime()
274 << ", max memory usage = " << parallelizer.evaluateMemory() << " KB"
278 if (MyGlobals::_Is0verbose>0) cout<<"OK END"<< endl;
281 catch(const char *mess)
287 catch(INTERP_KERNEL::Exception& e)
289 cerr<<"INTERP_KERNEL_Exception : "<<e.what()<<endl;
293 catch(std::exception& e)
295 cerr<<"std_Exception : "<<e.what()<<endl;
301 cerr<<"an unknown type exception error was occured"<<endl;