Skip to main content
`Ctrl`+`K`

# DMNetworkAddSubnetwork

Add a subnetwork

## Synopsis

    #include "petscdmnetwork.h"
    PetscErrorCode DMNetworkAddSubnetwork(DM dm, const char *name, PetscInt ne, PetscInt edgelist[], PetscInt *netnum)

Collective

## Input Parameters

- dm - the `DMNETWORK` object

- name - name of the subnetwork

- ne - number of local edges of this subnetwork

- edgelist - list of edges for this subnetwork, this is a one dimensional array with pairs of entries being the two vertices (in global numbering of the vertices) of each edge: [first vertex of first edge, second vertex of first edge, first vertex of second edge, second vertex of second edge, etc.]

## Output Parameter

- netnum - global index of the subnetwork

## Notes

There is no copy involved in this operation, only the pointer is referenced. The `edgelist` should not be destroyed before the call to `DMNetworkLayoutSetUp()`

A network can comprise of a single subnetwork OR multiple subnetworks. For a single subnetwork, the subnetwork can be read either in serial or parallel. For a multiple subnetworks, each subnetwork topology needs to be set on a unique MPI process and the communicator size needs to be at least equal to the number of subnetworks.

## Example usage

Consider the following networks:

1. A single subnetwork:

     network 0:
     rank[0]:
       v0 --> v2; v1 --> v2
     rank[1]:
       v3 --> v5; v4 --> v5

The resulting input network 0:

      rank[0]:
      ne = 2
      edgelist = [0 2 | 1 2]

      rank[1]:
      ne = 2
      edgelist = [3 5 | 4 5]

2. Two subnetworks:

     subnetwork 0:
     rank[0]:
       v0 --> v2; v2 --> v1; v1 --> v3;
     subnetwork 1:
     rank[1]:
       v0 --> v3; v3 --> v2; v2 --> v1;

The resulting input subnetwork 0:

      rank[0]:
      ne = 3
      edgelist = [0 2 | 2 1 | 1 3]

      rank[1]:
      ne = 0
      edgelist = NULL

subnetwork 1:

      rank[0]:
      ne = 0
      edgelist = NULL

      rank[1]:
      edgelist = [0 3 | 3 2 | 2 1]

## See Also

`DM`, `DMNETWORK`, `DMNetworkCreate()`, `DMNetworkSetNumSubnetworks()`

## Level

beginner

## Location

src/dm/impls/network/network.c

Index of all DMNetwork routines
Table of Contents for all manual pages
Index of all manual pages