xref: /petsc/src/dm/partitioner/impls/gather/partgather.c (revision 4e8208cbcbc709572b8abe32f33c78b69c819375)
1 #include <petsc/private/partitionerimpl.h> /*I "petscpartitioner.h" I*/
2 
3 typedef struct {
4   PetscInt unused;
5 } PetscPartitioner_Gather;
6 
PetscPartitionerDestroy_Gather(PetscPartitioner part)7 static PetscErrorCode PetscPartitionerDestroy_Gather(PetscPartitioner part)
8 {
9   PetscFunctionBegin;
10   PetscCall(PetscFree(part->data));
11   PetscFunctionReturn(PETSC_SUCCESS);
12 }
13 
PetscPartitionerPartition_Gather(PetscPartitioner part,PetscInt nparts,PetscInt numVertices,PetscInt start[],PetscInt adjacency[],PetscSection vertSection,PetscSection edgeSection,PetscSection targetSection,PetscSection partSection,IS * partition)14 static PetscErrorCode PetscPartitionerPartition_Gather(PetscPartitioner part, PetscInt nparts, PetscInt numVertices, PetscInt start[], PetscInt adjacency[], PetscSection vertSection, PetscSection edgeSection, PetscSection targetSection, PetscSection partSection, IS *partition)
15 {
16   PetscInt np;
17 
18   PetscFunctionBegin;
19   PetscCall(ISCreateStride(PETSC_COMM_SELF, numVertices, 0, 1, partition));
20   PetscCall(PetscSectionSetDof(partSection, 0, numVertices));
21   for (np = 1; np < nparts; ++np) PetscCall(PetscSectionSetDof(partSection, np, 0));
22   PetscFunctionReturn(PETSC_SUCCESS);
23 }
24 
PetscPartitionerInitialize_Gather(PetscPartitioner part)25 static PetscErrorCode PetscPartitionerInitialize_Gather(PetscPartitioner part)
26 {
27   PetscFunctionBegin;
28   part->noGraph        = PETSC_TRUE;
29   part->ops->destroy   = PetscPartitionerDestroy_Gather;
30   part->ops->partition = PetscPartitionerPartition_Gather;
31   PetscFunctionReturn(PETSC_SUCCESS);
32 }
33 
34 /*MC
35   PETSCPARTITIONERGATHER = "gather" - A PetscPartitioner object
36 
37   Level: intermediate
38 
39 .seealso: `PetscPartitionerType`, `PetscPartitionerCreate()`, `PetscPartitionerSetType()`
40 M*/
41 
PetscPartitionerCreate_Gather(PetscPartitioner part)42 PETSC_EXTERN PetscErrorCode PetscPartitionerCreate_Gather(PetscPartitioner part)
43 {
44   PetscPartitioner_Gather *p;
45 
46   PetscFunctionBegin;
47   PetscValidHeaderSpecific(part, PETSCPARTITIONER_CLASSID, 1);
48   PetscCall(PetscNew(&p));
49   part->data = p;
50 
51   PetscCall(PetscPartitionerInitialize_Gather(part));
52   PetscFunctionReturn(PETSC_SUCCESS);
53 }
54