Skip to content

Commit 6e21e9e

Browse files
committed
Pass the number of elements for mesh partitioning.
This is the first step to avoid constructing the entire mesh for partitioning.
1 parent 4c579b5 commit 6e21e9e

2 files changed

Lines changed: 38 additions & 35 deletions

File tree

Solver/src/libs/discretization/DGSEMClass.f90

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,9 @@ SUBROUTINE ConstructDGSem( self, meshFileName_, controlVariables, &
276276
end if
277277
!
278278
! Read the mesh by the root rank to perform the partitioning
279+
! (we skip this step if the mesh is partitioned with a space-filling curve: SFC_PARTITIONING)
279280
! ----------------------------------------------------------
280-
if ( MPI_Process % doMPIRootAction ) then
281+
if ( MPI_Process % doMPIRootAction) then ! .and. MPI_Partitioning /= SFC_PARTITIONING
281282
!
282283
! Construct the "full" mesh
283284
! -------------------------
@@ -301,13 +302,13 @@ SUBROUTINE ConstructDGSem( self, meshFileName_, controlVariables, &
301302
!
302303
! Perform the partitioning
303304
! ------------------------
304-
call PerformMeshPartitioning (self % mesh, MPI_Process % nProcs, mpi_allPartitions, useWeightsPartition, controlVariables)
305+
call PerformMeshPartitioning (self % mesh, self % mesh % no_of_elements, MPI_Process % nProcs, mpi_allPartitions, useWeightsPartition, controlVariables)
305306
!
306307
! Send the partitions
307308
! -------------------
308309
call SendPartitionsMPI( MeshFileType(self % mesh % meshFileName) == HOPRMESH )
309310
else
310-
call PerformMeshPartitioning (self % mesh, MPI_Process % nProcs, mpi_allPartitions, useWeightsPartition, controlVariables, &
311+
call PerformMeshPartitioning (self % mesh, self % mesh % no_of_elements, MPI_Process % nProcs, mpi_allPartitions, useWeightsPartition, controlVariables, &
311312
eID_Order=eID_Order, nElementLevel=nElementLevel)
312313
!
313314
! Send the partitions

Solver/src/libs/mesh/MeshPartitioning.f90

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ module MeshPartitioning
1010
public PerformMeshPartitioning
1111

1212
contains
13-
subroutine PerformMeshPartitioning(mesh, no_of_domains, partitions, useWeights, controlVariables, &
13+
subroutine PerformMeshPartitioning(mesh, no_of_elements, no_of_domains, partitions, useWeights, controlVariables, &
1414
eID_Order, nElementLevel)
1515
use FTValueDictionaryClass
1616
implicit none
1717
type(HexMesh), intent(in) :: mesh
18+
integer, intent(in) :: no_of_elements
1819
integer, intent(in) :: no_of_domains
1920
type(PartitionedMesh_t) :: partitions(no_of_domains)
2021
logical, intent(in) :: useWeights
@@ -27,7 +28,7 @@ subroutine PerformMeshPartitioning(mesh, no_of_domains, partitions, useWeights,
2728
! ---------------
2829
!
2930
integer :: fID, domain
30-
integer :: elementsDomain(mesh % no_of_elements)
31+
integer :: elementsDomain(no_of_elements)
3132
!
3233
! Initialize partitions
3334
! ---------------------
@@ -38,10 +39,10 @@ subroutine PerformMeshPartitioning(mesh, no_of_domains, partitions, useWeights,
3839
! Get each domain elements and nodes
3940
! ----------------------------------
4041
if (present(eID_Order)) then
41-
call GetElementsDomain(mesh, no_of_domains, elementsDomain, partitions, useWeights, controlVariables, &
42+
call GetElementsDomain(mesh, no_of_elements, no_of_domains, elementsDomain, partitions, useWeights, controlVariables, &
4243
eID_Order=eID_Order, nElementLevel=nElementLevel)
4344
else
44-
call GetElementsDomain(mesh, no_of_domains, elementsDomain, partitions, useWeights, controlVariables)
45+
call GetElementsDomain(mesh, no_of_elements, no_of_domains, elementsDomain, partitions, useWeights, controlVariables)
4546
end if
4647
!
4748
! Get the partition boundary faces
@@ -54,13 +55,14 @@ subroutine PerformMeshPartitioning(mesh, no_of_domains, partitions, useWeights,
5455
call WritePartitionsFile(mesh, elementsDomain)
5556
end subroutine PerformMeshPartitioning
5657

57-
subroutine GetElementsDomain(mesh, no_of_domains, elementsDomain, partitions, useWeights, controlVariables, &
58+
subroutine GetElementsDomain(mesh, no_of_elements, no_of_domains, elementsDomain, partitions, useWeights, controlVariables, &
5859
eID_Order, nElementLevel)
5960
use IntegerDataLinkedList
6061
use MPI_Process_Info
6162
use FTValueDictionaryClass
6263
implicit none
6364
type(HexMesh), intent(in) :: mesh
65+
integer, intent(in) :: no_of_elements
6466
integer, intent(in) :: no_of_domains
6567
integer, intent(out) :: elementsDomain(mesh % no_of_elements)
6668
type(PartitionedMesh_t), intent(inout) :: partitions(no_of_domains)
@@ -89,32 +91,32 @@ subroutine GetElementsDomain(mesh, no_of_domains, elementsDomain, partitions, us
8991
! Space-filling curve partitioning
9092
! --------------------------------
9193
case (SFC_PARTITIONING)
92-
if (present(eID_Order)) then
93-
call GetSFCElementsPartition(mesh, no_of_domains, mesh % no_of_elements, elementsDomain, useWeights=useWeights, &
94-
eID_Order=eID_Order, nElementLevel=nElementLevel)
95-
else
96-
allocate(eID(mesh % no_of_elements))
97-
eID = [(i, i=1, mesh % no_of_elements)]
98-
nEleLevel = mesh % no_of_elements
99-
call GetSFCElementsPartition(mesh, no_of_domains, mesh % no_of_elements, elementsDomain, useWeights=useWeights, &
100-
eID_Order=eID, nElementLevel=nEleLevel)
101-
deallocate(eID)
94+
if (present(eID_Order)) then
95+
call GetSFCElementsPartition(mesh, no_of_domains, no_of_elements, elementsDomain, useWeights=useWeights, &
96+
eID_Order=eID_Order, nElementLevel=nElementLevel)
97+
else
98+
allocate(eID(no_of_elements))
99+
eID = [(i, i=1, no_of_elements)]
100+
nEleLevel = no_of_elements
101+
call GetSFCElementsPartition(mesh, no_of_domains, no_of_elements, elementsDomain, useWeights=useWeights, &
102+
eID_Order=eID, nElementLevel=nEleLevel)
103+
deallocate(eID)
102104
end if
103105
!
104106
! METIS partitioning
105107
! ------------------
106108
case (METIS_PARTITIONING)
107-
if (present(eID_Order)) then
108-
call GetMETISElementsPartition(mesh, no_of_domains, elementsDomain, nodesDomain, useWeights, controlVariables, &
109-
size(nElementLevel), eID_Order, nElementLevel)
110-
else
111-
allocate(eID(mesh % no_of_elements))
112-
eID = [(i, i=1, mesh % no_of_elements)]
113-
nEleLevel = mesh % no_of_elements
114-
call GetMETISElementsPartition(mesh, no_of_domains, elementsDomain, nodesDomain, useWeights, controlVariables, &
115-
1, eID, nEleLevel)
116-
deallocate(eID)
117-
end if
109+
if (present(eID_Order)) then
110+
call GetMETISElementsPartition(mesh, no_of_domains, elementsDomain, nodesDomain, useWeights, controlVariables, &
111+
size(nElementLevel), eID_Order, nElementLevel)
112+
else
113+
allocate(eID(no_of_elements))
114+
eID = [(i, i=1, no_of_elements)]
115+
nEleLevel = no_of_elements
116+
call GetMETISElementsPartition(mesh, no_of_domains, elementsDomain, nodesDomain, useWeights, controlVariables, &
117+
1, eID, nEleLevel)
118+
deallocate(eID)
119+
end if
118120
end select
119121
!
120122
! ****************************************
@@ -384,13 +386,13 @@ end subroutine GetPartitionBoundaryFaces
384386
! --------------------------------
385387
! Space-filling curve partitioning
386388
! --------------------------------
387-
subroutine GetSFCElementsPartition(mesh, no_of_domains, nelem, elementsDomain, useWeights, eID_Order, nElementLevel)
389+
subroutine GetSFCElementsPartition(mesh, no_of_domains, no_of_elements, elementsDomain, useWeights, eID_Order, nElementLevel)
388390
implicit none
389391
!-arguments--------------------------------------------------
390392
type(HexMesh), intent(in) :: mesh
391393
integer, intent(in) :: no_of_domains
392-
integer, intent(in) :: nelem
393-
integer, intent(inout) :: elementsDomain(nelem)
394+
integer, intent(in) :: no_of_elements
395+
integer, intent(inout) :: elementsDomain(no_of_elements)
394396
logical, intent(in) :: useWeights
395397
integer, intent(in) :: eID_Order(:)
396398
integer, intent(in) :: nElementLevel(:)
@@ -407,8 +409,8 @@ subroutine GetSFCElementsPartition(mesh, no_of_domains, nelem, elementsDomain, u
407409
!------------------------------------------------------------
408410
nLevel = size(nElementLevel)
409411
if (useWeights) then
410-
allocate(weights(nelem))
411-
do ielem=1,nelem
412+
allocate(weights(no_of_elements))
413+
do ielem=1,no_of_elements
412414
weights(ielem) = product(mesh % elements(ielem) % Nxyz + 1)
413415
end do
414416
if (maxval(weights) .eq. minval(weights)) then
@@ -454,7 +456,7 @@ subroutine GetSFCElementsPartition(mesh, no_of_domains, nelem, elementsDomain, u
454456
do domain = 1, no_of_domains-1
455457
if (start_index(domain) .ge. start_index(domain+1)) start_index(domain+1) = start_index(domain) + 1
456458
dof_in_domain = sum(weights(start_index(domain):start_index(domain+1)))
457-
do ielem=1,nelem
459+
do ielem=1,no_of_elements
458460
if (dof_in_domain .lt. max_dof) then
459461
start_index(domain+1) = start_index(domain+1) + 1
460462
dof_in_domain = sum(weights(start_index(domain):start_index(domain+1)))

0 commit comments

Comments
 (0)