mirror of
https://github.com/NGSolve/netgen.git
synced 2025-02-05 01:14:16 +05:00
check for valid communicator
This commit is contained in:
parent
a330ad3019
commit
b21dd4d978
@ -46,15 +46,16 @@ namespace ngcore
|
|||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
MPI_Comm comm;
|
MPI_Comm comm;
|
||||||
|
bool valid_comm;
|
||||||
int * refcount;
|
int * refcount;
|
||||||
int rank, size;
|
int rank, size;
|
||||||
public:
|
public:
|
||||||
NgMPI_Comm ()
|
NgMPI_Comm ()
|
||||||
: refcount(nullptr), rank(0), size(1)
|
: valid_comm(false), refcount(nullptr), rank(0), size(1)
|
||||||
{ ; }
|
{ ; }
|
||||||
|
|
||||||
NgMPI_Comm (MPI_Comm _comm, bool owns = false)
|
NgMPI_Comm (MPI_Comm _comm, bool owns = false)
|
||||||
: comm(_comm)
|
: comm(_comm), valid_comm(true)
|
||||||
{
|
{
|
||||||
if (!owns)
|
if (!owns)
|
||||||
refcount = nullptr;
|
refcount = nullptr;
|
||||||
@ -66,13 +67,15 @@ namespace ngcore
|
|||||||
}
|
}
|
||||||
|
|
||||||
NgMPI_Comm (const NgMPI_Comm & c)
|
NgMPI_Comm (const NgMPI_Comm & c)
|
||||||
: comm(c.comm), refcount(c.refcount), rank(c.rank), size(c.size)
|
: comm(c.comm), valid_comm(c.valid_comm), refcount(c.refcount),
|
||||||
|
rank(c.rank), size(c.size)
|
||||||
{
|
{
|
||||||
if (refcount) (*refcount)++;
|
if (refcount) (*refcount)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
NgMPI_Comm (NgMPI_Comm && c)
|
NgMPI_Comm (NgMPI_Comm && c)
|
||||||
: comm(c.comm), refcount(c.refcount), rank(c.rank), size(c.size)
|
: comm(c.comm), valid_comm(c.valid_comm), refcount(c.refcount),
|
||||||
|
rank(c.rank), size(c.size)
|
||||||
{
|
{
|
||||||
c.refcount = nullptr;
|
c.refcount = nullptr;
|
||||||
}
|
}
|
||||||
@ -93,14 +96,21 @@ namespace ngcore
|
|||||||
refcount = c.refcount;
|
refcount = c.refcount;
|
||||||
if (refcount) (*refcount)++;
|
if (refcount) (*refcount)++;
|
||||||
comm = c.comm;
|
comm = c.comm;
|
||||||
|
valid_comm = c.valid_comm;
|
||||||
size = c.size;
|
size = c.size;
|
||||||
rank = c.rank;
|
rank = c.rank;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class InvalidCommException : public Exception {
|
||||||
|
public:
|
||||||
|
InvalidCommException() : Exception("Do not have a valid communicator") { ; }
|
||||||
|
};
|
||||||
|
|
||||||
|
operator MPI_Comm() const {
|
||||||
operator MPI_Comm() const { return comm; }
|
if (!valid_comm) throw InvalidCommException();
|
||||||
|
return comm;
|
||||||
|
}
|
||||||
|
|
||||||
int Rank() const { return rank; }
|
int Rank() const { return rank; }
|
||||||
int Size() const { return size; }
|
int Size() const { return size; }
|
||||||
|
Loading…
Reference in New Issue
Block a user