Fix paralleltop. Clean up mesh loading.

This commit is contained in:
Lukas 2019-01-29 19:37:58 +01:00
parent c7fb6c7e4a
commit 012d27d41e
3 changed files with 29 additions and 46 deletions

View File

@ -249,29 +249,28 @@ namespace netgen
{
private:
shared_ptr<Mesh> mesh;
#ifdef PARALLEL
MPI_Comm comm;
#endif
public:
// Ngx_Mesh () { ; }
// Ngx_Mesh(class Mesh * amesh) : mesh(amesh) { ; }
Ngx_Mesh(shared_ptr<Mesh> amesh = NULL);
void LoadMesh (const string & filename);
void LoadMesh (istream & str);
/** reuse a netgen-mesh **/
Ngx_Mesh (shared_ptr<Mesh> amesh);
/** load a new mesh **/
Ngx_Mesh (string filename, MPI_Comm acomm = netgen::ng_comm);
void LoadMesh (const string & filename, MPI_Comm comm = netgen::ng_comm);
void LoadMesh (istream & str, MPI_Comm comm = netgen::ng_comm);
void SaveMesh (ostream & str) const;
void UpdateTopology ();
void DoArchive (Archive & archive);
#ifdef PARALLEL
MPI_Comm GetCommunicator() const;
void SetCommunicator(MPI_Comm acomm);
#endif
virtual ~Ngx_Mesh();
bool Valid () { return mesh != NULL; }
bool Valid () const { return mesh != NULL; }
int GetDimension() const;
int GetNLevels() const;

View File

@ -31,56 +31,39 @@ namespace netgen
return hmesh;
}
Ngx_Mesh :: Ngx_Mesh (shared_ptr<Mesh> amesh)
{
if (amesh) {
mesh = amesh;
comm = amesh->GetCommunicator();
}
else {
mesh = netgen::mesh;
comm = netgen::ng_comm;
}
}
#ifdef PARALLEL
void Ngx_Mesh :: SetCommunicator (MPI_Comm acomm)
{
if (Valid() && acomm!=mesh->GetCommunicator())
throw NgException("Redistribution of mesh not possible!");
this->comm = acomm;
}
MPI_Comm Ngx_Mesh :: GetCommunicator() const
{ return comm; }
#endif
Ngx_Mesh :: Ngx_Mesh (shared_ptr<Mesh> amesh)
{ mesh = amesh ? amesh : netgen::mesh; }
Ngx_Mesh :: Ngx_Mesh (string filename, MPI_Comm acomm)
{ LoadMesh(filename, acomm); }
Ngx_Mesh * LoadMesh (const string & filename)
Ngx_Mesh * LoadMesh (const string & filename, MPI_Comm comm = netgen::ng_comm)
{
netgen::mesh.reset();
Ng_LoadMesh (filename.c_str(), netgen::ng_comm);
Ng_LoadMesh (filename.c_str(), comm);
return new Ngx_Mesh (netgen::mesh);
}
void Ngx_Mesh :: LoadMesh (const string & filename)
void Ngx_Mesh :: LoadMesh (const string & filename, MPI_Comm comm)
{
netgen::mesh.reset();
Ng_LoadMesh (filename.c_str(), this->comm);
Ng_LoadMesh (filename.c_str(), comm);
// mesh = move(netgen::mesh);
mesh = netgen::mesh;
}
void Ngx_Mesh :: LoadMesh (istream & ist)
void Ngx_Mesh :: LoadMesh (istream & ist, MPI_Comm comm)
{
netgen::mesh = make_shared<Mesh>();
netgen::mesh->SetCommunicator(comm);
netgen::mesh -> Load (ist);
// mesh = move(netgen::mesh);
mesh = netgen::mesh;
SetGlobalMesh (mesh);
}
MPI_Comm Ngx_Mesh :: GetCommunicator() const
{ return Valid() ? mesh->GetCommunicator() : MPI_COMM_NULL; }
void Ngx_Mesh :: SaveMesh (ostream & ost) const
{
mesh -> Save (ost);

View File

@ -213,8 +213,9 @@ namespace netgen
// cout << "UpdateCoarseGrid" << endl;
// if (is_updated) return;
int id = MyMPI_GetId(mesh.GetCommunicator());
int ntasks = MyMPI_GetNTasks(mesh.GetCommunicator());
MPI_Comm comm = mesh.GetCommunicator();
int id = MyMPI_GetId(comm);
int ntasks = MyMPI_GetNTasks(comm);
cout << "Update CG, this = " << this << " , mesh: " << &mesh << endl;
@ -234,14 +235,14 @@ namespace netgen
// MPI_Barrier (MPI_COMM_WORLD);
MPI_Group MPI_GROUP_WORLD;
MPI_Group MPI_GROUP_comm;
MPI_Group MPI_LocalGroup;
MPI_Comm MPI_LocalComm;
int process_ranks[] = { 0 };
MPI_Comm_group (MPI_COMM_WORLD, &MPI_GROUP_WORLD);
MPI_Group_excl (MPI_GROUP_WORLD, 1, process_ranks, &MPI_LocalGroup);
MPI_Comm_create (MPI_COMM_WORLD, MPI_LocalGroup, &MPI_LocalComm);
MPI_Comm_group (comm, &MPI_GROUP_comm);
MPI_Group_excl (MPI_GROUP_comm, 1, process_ranks, &MPI_LocalGroup);
MPI_Comm_create (comm, MPI_LocalGroup, &MPI_LocalComm);
if (id == 0) return;