schorsch312
schorsch312

Reputation: 5698

Is MPI_COMM_WORLD not constant?

I read here, that

While MPI_Comm_split is the most common communicator creation function, there are many others. MPI_Comm_dup is the most basic and creates a duplicate of a communicator. It may seem odd that there would exist a function that only creates a copy, but this is very useful for applications which use libraries to perform specialized functions, such as mathematical libraries. In these kinds of applications, it’s important that user codes and library codes do not interfere with each other. To avoid this, the first thing every application should do is to create a duplicate of MPI_COMM_WORLD, which will avoid the problem of other libraries also using MPI_COMM_WORLD. The libraries themselves should also make duplicates of MPI_COMM_WORLD to avoid the same problem.

Can MPI_COMM_WORLD be changed after the start of the initialisation of MPI? Is MPI_COMM_WORLD not constant?

Upvotes: 2

Views: 289

Answers (1)

Gilles Gouaillardet
Gilles Gouaillardet

Reputation: 8395

The rationale for MPI_Comm_dup(MPI_COMM_WORLD, ...) is you do not want a message sent by the MPI app (in MPI_COMM_WORLD) is received by the library under the hood. Conversely, you do not want the MPI app to receive a message sent by the library.

A simple way of avoiding that is to use a dedicated communicator for the library, and duplicating MPI_COMM_WORLD is the simplest way to achieve that.

The answer to your question is MPI_COMM_WORLD cannot be changed after MPI_Init(). And more generally, communicators cannot be changed once created.

Upvotes: 2

Related Questions