integer redistkey, redistcomm, group, extra logical useflag data redistkey /MPI_KEYVAL_INVALID/ save redistkey if (redistkey .eq. MPI_KEYVAL_INVALID) then call mpi_keyval_create (MPI_NULL_FN, MPI_NULL_FN, redistkey, extra, ierr) end if call mpi_attr_get (comm, redistkey, redistcomm, useflag, ierr) if (.not.useflag) then call mpi_comm_dup (comm, redistcomm, ierr) call mpi_attr_put (comm, redistkey, redistcomm, ierr) end if