NgMPI_Communicator by reference, check for valid mpi-comm

This commit is contained in:
Joachim Schöberl 2020-08-02 09:25:23 +02:00
parent e4ef03caac
commit ba84439227
4 changed files with 16 additions and 4 deletions

View File

@ -89,6 +89,11 @@ namespace ngcore
MPI_Comm_free(&comm); MPI_Comm_free(&comm);
} }
bool ValidCommunicator() const
{
return valid_comm;
}
NgMPI_Comm & operator= (const NgMPI_Comm & c) NgMPI_Comm & operator= (const NgMPI_Comm & c)
{ {
if (refcount) if (refcount)

View File

@ -276,7 +276,7 @@ namespace netgen
void UpdateTopology (); void UpdateTopology ();
void DoArchive (Archive & archive); void DoArchive (Archive & archive);
NgMPI_Comm GetCommunicator() const; const NgMPI_Comm & GetCommunicator() const;
virtual ~Ngx_Mesh(); virtual ~Ngx_Mesh();

View File

@ -61,8 +61,12 @@ namespace netgen
SetGlobalMesh (mesh); SetGlobalMesh (mesh);
} }
NgMPI_Comm Ngx_Mesh :: GetCommunicator() const const NgMPI_Comm & Ngx_Mesh :: GetCommunicator() const
{ return Valid() ? mesh->GetCommunicator() : NgMPI_Comm{}; } {
// return Valid() ? mesh->GetCommunicator() : NgMPI_Comm{};
if (!Valid()) throw Exception("Ngx_mesh::GetCommunicator: don't have a valid mesh");
return mesh->GetCommunicator();
}
void Ngx_Mesh :: SaveMesh (ostream & ost) const void Ngx_Mesh :: SaveMesh (ostream & ost) const
{ {
@ -1297,6 +1301,9 @@ void Ngx_Mesh::SetSurfaceElementOrders (int enr, int ox, int oy)
std::tuple<int,int*> Ngx_Mesh :: GetDistantProcs (int nodetype, int locnum) const std::tuple<int,int*> Ngx_Mesh :: GetDistantProcs (int nodetype, int locnum) const
{ {
#ifdef PARALLEL #ifdef PARALLEL
if (mesh->GetCommunicator().Size() == 1)
return std::tuple<int,int*>(0,nullptr);
switch (nodetype) switch (nodetype)
{ {
case 0: case 0:

View File

@ -640,7 +640,7 @@ namespace netgen
int AddEdgeDescriptor(const EdgeDescriptor & fd) int AddEdgeDescriptor(const EdgeDescriptor & fd)
{ edgedecoding.Append(fd); return edgedecoding.Size() - 1; } { edgedecoding.Append(fd); return edgedecoding.Size() - 1; }
auto GetCommunicator() const { return this->comm; } auto & GetCommunicator() const { return this->comm; }
void SetCommunicator(NgMPI_Comm acomm); void SetCommunicator(NgMPI_Comm acomm);
/// ///