10.1.7.0.3 MPI::Comm::Clone()

The C++ language interface for MPI-/ includes a new function Clone(). MPI::Comm::Clone() is a pure virtual function. For the derived communicator classes, Clone() behaves like Dup() except that it returns a new object by reference. The Clone() functions are prototyped as follows:

Comm& Comm::Clone() const = 0



Intracomm& Intracomm::Clone() const



Intercomm& Intercomm::Clone() const



Cartcomm& Cartcomm::Clone() const



Graphcomm& Graphcomm::Clone() const



Rationale. Clone() provides the ``virtual dup'' functionality that is expected by C++ programmers and library writers. Since Clone() returns a new object by reference, users are responsible for eventually deleting the object. A new name is introduced rather than changing the functionality of Dup().(End of rationale.)

Advice to implementors. Within their class declarations, prototypes for Clone() and Dup() would look like the following:
namespace MPI {
  class Comm {
     virtual Comm& Clone() const = 0;
  };
  class Intracomm : public Comm {
     Intracomm Dup() const { ... };
     virtual Intracomm& Clone() const { ... };
  };
  class Intercomm : public Comm {
     Intercomm Dup() const { ... };
     virtual Intercomm& Clone() const { ... };
  };
  // Cartcomm and Graphcomm are similarly defined
};
Compilers that do not support the variable return type feature of virtual functions may return a reference to Comm. Users can cast to the appropriate type as necessary.(End of advice to implementors.)

MPI-Standard for MARMOT