[mpich-discuss] MPI_Init and MPI_COMM_WORLD

Raffenetti, Ken raffenet at anl.gov
Wed Apr 13 13:10:17 CDT 2022


According to the standard, MPI_COMM_WORLD is a named constant handle which does not change value between MPI_INIT and MPI_FINALIZE. Therefore, I believe your example is OK from the standard perspective. In MPICH, MPI_COMM_WORLD is an integer constant defined at compile-time. I believe in Open MPI the value is defined at link-time, which should still meet the requirements of your example.


On 4/13/22, 12:29 PM, "Palmer, Bruce J via discuss" <discuss at mpich.org> wrote:


    Does MPI_COMM_WORLD exist in any sense before MPI_Init is called? In particular, does this code violate the standard?

    InitializeMyApp(MPI_Comm comm, int argc, char **argv)
      int initialized;
      if (!initialized) MPI_Init(&argc, &argv);
      /* call some function that uses comm */

    int main(int argc, char **argv)
      MPI_Comm comm = MPI_COMM_WORLD;
      InitializeMyApp(comm, argc, argv);

    My instinct is that this is wrong, but I would like to be sure before I complain about it. It appears to work with some existing implementations, but it looks sketchy to me.


More information about the discuss mailing list