10.1.5.0.2 Copy / Assignment

The copy constructor and assignment operator are prototyped as follows:

int MPI::<CLASS>(const MPI::<CLASS>& data)



int MPI::<CLASS>& MPI::<CLASS>::operator=(const MPI::<CLASS>& data)



In terms of copying and assignment, opaque MPI-/ user level objects behave like handles. Copy constructors perform handle-based (shallow) copies. MPI::Status objects are exceptions to this rule. These objects perform deep copies for assignment and copy construction.

Advice to implementors. Each MPI-/ user level object is likely to contain, by value or by reference, implementation-dependent state information. The assignment and copying of MPI-/ object handles may simply copy this value (or reference).(End of advice to implementors.)

Example 10..3   Example using assignment operator. In this example, MPI::Intracomm::Dup() is not called for foo_comm. The object foo_comm is simply an alias for MPI::COMM_WORLD. But bar_comm is created with a call to MPI::Intracomm::Dup() and is therefore a different communicator than foo_comm (and thus different from MPI::COMM_WORLD). baz_comm becomes an alias for bar_comm. If one of bar_comm or baz_comm is freed with MPI_COMM_FREE it will be set to MPI::COMM_NULL. The state of the other handle will be undefined -- it will be invalid, but not necessarily set to MPI::COMM_NULL.

  MPI::Intracomm foo_comm, bar_comm, baz_comm;

  foo_comm = MPI::COMM_WORLD;
  bar_comm = MPI::COMM_WORLD.Dup();
  baz_comm = bar_comm;

MPI-Standard for MARMOT