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