You probably want to check out MPI_COMM_SPLIT_TYPE. It will allow you to split an existing communicator based on the split_type
you pass in as a parameter:
int MPI_Comm_split_type(MPI_Comm comm, int split_type, int key,
MPI_Info info, MPI_Comm *newcomm)
Right now, the only split_type is MPI_COMM_TYPE_SHARED
, defined in the standard as:
This type splits the communicator into subcommunicators, each of which
can create a shared memory region.
This is usually the same thing as what you're asking, but you'll have to double check that it's true on your machine.
The other thing you need to know is that this is a new function in MPI-3 so it might not be available in all implementations of MPI. I know that it's available for MPICH and it's derivatives. AFAIK, it's not available in the last release of Open MPI. So make sure you have a version of MPI that actually supports it.