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
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;
76 // Primitive parsing of command-line options
77 string desc ("Available options of medpartitioner V1.0:\n"
78 "\t--help : produces this help message\n"
79 "\t--verbose : echoes arguments\n"
80 "\t--input-file=<string> : name of the input .med file or .xml master file\n"
81 "\t--output-file=<string> : name of the resulting file (without extension)\n"
82 "\t--ndomains=<number> : number of subdomains in the output file, default is 1\n"
83 #if defined(MED_ENABLE_METIS) && defined(MED_ENABLE_SCOTCH)
85 "\t--split-method=<string> : name of the splitting library (metis/scotch), default is metis\n"
87 // "\t--creates-boundary-faces : creates boundary faces mesh in the output files\n"
88 "\t--dump-cpu-memory : dumps passed CPU time and maximal increase of used memory\n"
93 for (int i = 1; i < argc; i++)
95 if (strlen(argv[i]) < 3)
97 cerr << "bad argument : "<< argv[i] << endl;
101 if (TestArg(argv[i],"--verbose",value))
103 MyGlobals::_Verbose=1;
104 if (value!="") MyGlobals::_Verbose = atoi(value.c_str());
106 else if (TestArg(argv[i],"--help",value)) help=1;
107 // else if (TestArg(argv[i],"--test",value)) test=1;
108 else if (TestArg(argv[i],"--input-file",value)) input=value;
109 else if (TestArg(argv[i],"--output-file",value)) output=value;
110 else if (TestArg(argv[i],"--split-method",value)) library=value;
111 else if (TestArg(argv[i],"--ndomains",value)) ndomains=atoi(value.c_str());
112 // else if (TestArg(argv[i],"--creates-boundary-faces",value)) MyGlobals::_Creates_Boundary_Faces=1;
113 else if (TestArg(argv[i],"--dump-cpu-memory",value)) mesure_memory=true;
116 cerr << "unknown argument : "<< argv[i] << endl;
121 MyGlobals::_Is0verbose=MyGlobals::_Verbose;
124 #if defined(MED_ENABLE_METIS) && !defined(MED_ENABLE_SCOTCH)
127 #if !defined(MED_ENABLE_METIS) && defined(MED_ENABLE_SCOTCH)
131 #if defined(MED_ENABLE_METIS) && defined(MED_ENABLE_SCOTCH)
132 if ((library!="metis") && (library!="scotch"))
134 cerr << "split-method only available : metis, scotch" << endl;
145 if (MyGlobals::_Is0verbose)
147 cout << "medpartitioner V1.0 :" << endl;
148 cout << " input-file = " << input << endl;
149 cout << " output-file = " << output << endl;
150 cout << " split-method = " << library << endl;
151 cout << " ndomains = " << ndomains << endl;
152 // cout << " creates_boundary_faces = " << MyGlobals::_Creates_Boundary_Faces << endl;
153 cout << " dump-cpu-memory = " << mesure_memory<< endl;
154 cout << " verbose = " << MyGlobals::_Verbose << endl;
156 //testing whether it is possible to write a file at the specified location
157 if (MyGlobals::_Rank==0)
159 string outputtest = output + ".testioms.";
160 ofstream testfile (outputtest.c_str());
163 cerr << "output-file directory does not exist or is in read-only access" << endl;
167 remove(outputtest.c_str());
170 // Beginning of the computation
172 // Loading the mesh collection
173 if (MyGlobals::_Is0verbose) cout << "Reading input files "<<endl;
177 /*MEDPARTITIONER::ParaDomainSelector parallelizer(mesure_memory);
178 MEDPARTITIONER::MeshCollection collection(input,parallelizer);
179 MEDPARTITIONER::ParallelTopology* aPT = (MEDPARTITIONER::ParallelTopology*) collection.getTopology();
180 aPT->setGlobalNumerotationDefault(collection.getParaDomainSelector());
181 //int nbfiles=MyGlobals::_fileMedNames->size(); //nb domains
182 //to have unique valid fields names/pointers/descriptions for partitionning
183 collection.prepareFieldDescriptions();
184 //int nbfields=collection.getFieldDescriptions().size(); //on all domains
185 //cout<<ReprVectorOfString(collection.getFieldDescriptions());
187 if (MyGlobals::_Is0verbose)
189 cout<<"fileNames :"<<endl
190 <<ReprVectorOfString(MyGlobals::_File_Names);
191 cout<<"fieldDescriptions :"<<endl
192 <<ReprFieldDescriptions(collection.getFieldDescriptions()," "); //cvwat07
193 cout<<"familyInfo :\n"
194 <<ReprMapOfStringInt(collection.getFamilyInfo())<<endl;
195 cout<<"groupInfo :\n"
196 <<ReprMapOfStringVectorOfString(collection.getGroupInfo())<<endl;
198 MEDPARTITIONER::ParaDomainSelector parallelizer(mesure_memory);
199 MEDPARTITIONER::MeshCollection collection(input,parallelizer);
200 MEDPARTITIONER::ParallelTopology* aPT = (MEDPARTITIONER::ParallelTopology*) collection.getTopology();
201 aPT->setGlobalNumerotationDefault(collection.getParaDomainSelector());
202 //to have unique valid fields names/pointers/descriptions for partitionning
203 collection.prepareFieldDescriptions();
205 //MEDPARTITIONER::MeshCollection collection(input);
207 //Creating the graph and partitioning it
208 if (MyGlobals::_Is0verbose) cout << "Computing partition with " << library << endl;
210 auto_ptr< MEDPARTITIONER::Topology > new_topo;
211 if (library == "metis")
212 new_topo.reset( collection.createPartition(ndomains,MEDPARTITIONER::Graph::METIS));
214 new_topo.reset( collection.createPartition(ndomains,MEDPARTITIONER::Graph::SCOTCH));
215 parallelizer.evaluateMemory();
217 //Creating a new mesh collection from the partitioning
218 if (MyGlobals::_Is0verbose) cout << "Creating new meshes"<< endl;
219 MEDPARTITIONER::MeshCollection new_collection(collection,new_topo.get(),split_family,empty_groups);
221 if (filter_face) new_collection.filterFaceOnCell();
223 //to get infos on all procs
226 vector<string> finalInformations;
227 vector<string> r1,r2;
228 //r1=AllgathervVectorOfString(MyGlobals::_General_Informations);
229 r1=MyGlobals::_General_Informations;
230 //if (MyGlobals::_Is0verbose>1000) cout << "generalInformations : \n"<<ReprVectorOfString(r1);
231 r2=SelectTagsInVectorOfString(r1,"ioldDomain=");
232 r2=SelectTagsInVectorOfString(r2,"meshName=");
233 if (r2.size()==(collection.getMesh()).size())
235 for (std::size_t i=0; i<r2.size(); i++)
236 r2[i]=EraseTagSerialized(r2[i],"ioldDomain=");
237 r2=DeleteDuplicatesInVectorOfString(r2);
240 string finalMesh="finalMeshName="+ExtractFromDescription(r2[0], "meshName=");
241 finalInformations.push_back(SerializeFromString(finalMesh));
244 if (finalInformations.size()==0)
246 if (MyGlobals::_Rank==0)
247 cerr<<"Problem on final meshName : set at 'Merge'"<<endl;
248 finalInformations.push_back(SerializeFromString("finalMeshName=Merge"));
251 //see field info nbComponents & componentInfo (if fields present)
252 r2=SelectTagsInVectorOfString(r1,"fieldName=");
253 r2=SelectTagsInVectorOfString(r2,"nbComponents=");
254 //may be yes? or not?
255 for (std::size_t i=0; i<r2.size(); i++)
256 r2[i]=EraseTagSerialized(r2[i],"ioldFieldDouble=");
257 r2=DeleteDuplicatesInVectorOfString(r2);
258 for (std::size_t i=0; i<r2.size(); i++)
259 finalInformations.push_back(r2[i]);
261 MyGlobals::_General_Informations=finalInformations;
262 if (MyGlobals::_Is0verbose)
263 cout << "generalInformations : \n"<<ReprVectorOfString(finalInformations);
265 //new_collection.setSubdomainBoundaryCreates(creates_boundary_faces);
266 if (MyGlobals::_Is0verbose) cout << "Writing "<<ndomains<<" output files "<<output<<"xx.med"<<" and "<<output<<".xml"<<endl;
267 new_collection.write(output);
269 /*if ( mesure_memory )
270 if ( parallelizer.isOnDifferentHosts() || MyGlobals::_Rank==0 )
272 cout << "Elapsed time = " << parallelizer.getPassedTime()
273 << ", max memory usage = " << parallelizer.evaluateMemory() << " KB"
277 if (MyGlobals::_Is0verbose>0) cout<<"OK END"<< endl;
280 catch(const char *mess)
286 catch(INTERP_KERNEL::Exception& e)
288 cerr<<"INTERP_KERNEL_Exception : "<<e.what()<<endl;
292 catch(std::exception& e)
294 cerr<<"std_Exception : "<<e.what()<<endl;
300 cerr<<"an unknown type exception error was occured"<<endl;