# PetscSubcommCreate

Create a PetscSubcomm context.

### Synopsis

    #include "petsc.h"
    #include "petscsys.h"
    PetscErrorCode PETSCMAT_DLLEXPORT PetscSubcommCreate(MPI_Comm comm,PetscInt nsubcomm,PetscSubcomm *psubcomm)

Collective on MPI_Comm

### Input Parameter

| comm | - MPI communicator
| nsubcomm | - the number of subcommunicators to be created

### Output Parameter

psubcomm -location to store the PetscSubcomm context

### Notes

To avoid data scattering from subcomm back to original comm, we create subcommunicators by iteratively taking a process into a subcommunicator. Example: size=4, nsubcomm=(*psubcomm)->n=3

### comm=(*psubcomm)->parent

rank: [0] [1] [2] [3] color: 0 1 2 0

### subcomm=(*psubcomm)->comm

subrank: [0] [0] [0] [1]

### dupcomm=(*psubcomm)->dupparent

duprank: [0] [2] [3] [1]

Here, subcomm[color = 0] has subsize=2, owns process [0] and [3] subcomm[color = 1] has subsize=1, owns process [1] subcomm[color = 2] has subsize=1, owns process [2] dupcomm has same number of processes as comm, and its duprank maps

### processes in subcomm contiguously into a 1d array

duprank: [0] [1] [2] [3] rank: [0] [3] [1] [2] subcomm[0] subcomm[1] subcomm[2]

### Keywords

communicator, create

### See Also

PetscSubcommDestroy()

Level:advanced
Location:src/sys/objects/subcomm.c
Index of all Sys routines
Table of Contents for all manual pages
Index of all manual pages