From faad040fb0013315aa1b99ea6eff1bdccbd72437 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Thu, 5 Jul 2012 11:05:33 +0000 Subject: [PATCH] parallel command processing --- libsrc/interface/nginterface.cpp | 37 +++++++++++++++++++++++--------- libsrc/meshing/meshclass.cpp | 8 +------ libsrc/meshing/parallelmesh.cpp | 13 +++++------ ng/ngpkg.cpp | 5 +++++ ng/parallelfunc.cpp | 17 ++++----------- ng/parallelfunc.hpp | 4 ++++ nglib/Makefile.am | 2 +- nglib/nglib.cpp | 10 ++------- 8 files changed, 51 insertions(+), 45 deletions(-) diff --git a/libsrc/interface/nginterface.cpp b/libsrc/interface/nginterface.cpp index 35e2fd87..9cca123d 100644 --- a/libsrc/interface/nginterface.cpp +++ b/libsrc/interface/nginterface.cpp @@ -232,19 +232,36 @@ void Ng_LoadMeshFromStream ( istream & input ) void Ng_LoadMesh (const char * filename) { - if ( (strlen (filename) > 4) && - strcmp (filename + (strlen (filename)-4), ".vol") != 0 ) + MPI_Comm_size(MPI_COMM_WORLD, &ntasks); + MPI_Comm_rank(MPI_COMM_WORLD, &id); + + if (id == 0) + { + if ( (strlen (filename) > 4) && + strcmp (filename + (strlen (filename)-4), ".vol") != 0 ) + { + mesh.Reset (new Mesh()); + ReadFile(*mesh,filename); + + //mesh->SetGlobalH (mparam.maxh); + //mesh->CalcLocalH(); + return; + } + + ifstream infile(filename); + Ng_LoadMeshFromStream(infile); + + if (ntasks > 1) + { + // MyMPI_SendCmd ("mesh"); + mesh -> Distribute(); + } + } + else { mesh.Reset (new Mesh()); - ReadFile(*mesh,filename); - - //mesh->SetGlobalH (mparam.maxh); - //mesh->CalcLocalH(); - return; + mesh->SendRecvMesh(); } - - ifstream infile(filename); - Ng_LoadMeshFromStream(infile); } void Ng_LoadMeshFromString (const char * mesh_as_string) diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index 801ddd5f..e6cab56e 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -1197,16 +1197,10 @@ namespace netgen topology -> Update(); clusters -> Update(); -#ifdef PARALLEL - if ( ntasks > 1 ) Distribute (); -#endif - + // Distribute(); SetNextMajorTimeStamp(); // PrintMemInfo (cout); - - - } diff --git a/libsrc/meshing/parallelmesh.cpp b/libsrc/meshing/parallelmesh.cpp index 52cfb35e..f0d5fba5 100644 --- a/libsrc/meshing/parallelmesh.cpp +++ b/libsrc/meshing/parallelmesh.cpp @@ -657,6 +657,9 @@ namespace netgen // call it only for the master ! void Mesh :: Distribute () { + MPI_Comm_size(MPI_COMM_WORLD, &ntasks); + MPI_Comm_rank(MPI_COMM_WORLD, &id); + if (id != 0 || ntasks == 1 ) return; #ifdef METIS @@ -666,17 +669,15 @@ namespace netgen (*this)[ei].SetPartition(ntasks * ei/GetNE() + 1); #endif + /* for (ElementIndex ei = 0; ei < GetNE(); ei++) *testout << "el(" << ei << ") is in part " << (*this)[ei].GetPartition() << endl; for (SurfaceElementIndex ei = 0; ei < GetNSE(); ei++) *testout << "sel(" << int(ei) << ") is in part " << (*this)[ei].GetPartition() << endl; - - // send partition - MyMPI_SendCmd ("mesh"); + */ + + // MyMPI_SendCmd ("mesh"); SendRecvMesh (); - - // paralleltop -> UpdateCoarseGrid(); - // paralleltop -> Print(); } diff --git a/ng/ngpkg.cpp b/ng/ngpkg.cpp index f7ac8e28..acc2a017 100644 --- a/ng/ngpkg.cpp +++ b/ng/ngpkg.cpp @@ -221,6 +221,11 @@ namespace netgen ifstream infile(filename.c_str()); mesh -> Load(infile); +#ifdef PARALLEL + MyMPI_SendCmd ("mesh"); + mesh -> Distribute(); +#endif + for (int i = 0; i < geometryregister.Size(); i++) { NetgenGeometry * hgeom = geometryregister[i]->LoadFromMeshFile (infile); diff --git a/ng/parallelfunc.cpp b/ng/parallelfunc.cpp index ee540a27..ecf775ff 100644 --- a/ng/parallelfunc.cpp +++ b/ng/parallelfunc.cpp @@ -2,9 +2,6 @@ #include "dlfcn.h" -#ifdef OCCGEOMETRY -#include -#endif // #include @@ -30,23 +27,16 @@ #endif - +/* #include #include - -// #include -// #include -// #include -// #include -// #include -// #include - +*/ #include // #include "parallel.hpp" -#include "parallelfunc.hpp" +// #include "parallelfunc.hpp" // extern "C" void NGS_ParallelRun (const string & message); @@ -72,6 +62,7 @@ namespace netgen { extern AutoPtr mesh; extern VisualSceneMesh vsmesh; extern Flags parameters; + extern DLL_HEADER MeshingParameters mparam; } using namespace netgen; diff --git a/ng/parallelfunc.hpp b/ng/parallelfunc.hpp index a405bfa9..c4971e1b 100644 --- a/ng/parallelfunc.hpp +++ b/ng/parallelfunc.hpp @@ -1,3 +1,7 @@ +das braucht keiner mehr + + + #ifndef FILE_PARALLELFUNC #define FILE_PARALLELFUNC diff --git a/nglib/Makefile.am b/nglib/Makefile.am index 2d7986e9..f6091ea8 100644 --- a/nglib/Makefile.am +++ b/nglib/Makefile.am @@ -5,7 +5,7 @@ dist_pkgdata_DATA = cube.surf AM_CPPFLAGS = -I$(top_srcdir)/libsrc/include $(MPI_INCLUDES) $(OCCFLAGS) lib_LTLIBRARIES = libnglib.la -libnglib_la_SOURCES = nglib.cpp +libnglib_la_SOURCES = nglib.cpp parallelfunc.cpp libnglib_la_LIBADD = \ $(top_builddir)/libsrc/interface/libinterface.la \ diff --git a/nglib/nglib.cpp b/nglib/nglib.cpp index 57a5c172..a5eaf0e4 100644 --- a/nglib/nglib.cpp +++ b/nglib/nglib.cpp @@ -31,20 +31,14 @@ namespace netgen { MeshingParameters & mp); } -namespace netgen -{ - int id, ntasks; -} -#ifdef PARALLEL +#ifdef PARALLELxxx #include namespace netgen { - // MPI_Group MPI_HIGHORDER_WORLD; - // MPI_Comm MPI_HIGHORDER_COMM; - MPI_Comm mesh_comm; + // MPI_Comm mesh_comm; } #endif