Skip to content

Commit

Permalink
Other places the pattern lurks
Browse files Browse the repository at this point in the history
  • Loading branch information
william-dawson committed Apr 7, 2023
1 parent 835d7b5 commit 768569a
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 240 deletions.
2 changes: 1 addition & 1 deletion Source/Fortran/CholeskySolversModule.F90
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ MODULE CholeskyModule
& DestructMatrix
USE SVectorModule, ONLY : DotSparseVectors
USE TripletListModule, ONLY : TripletList_r, AppendToTripletList, &
& DestructTripletList
& DestructTripletList, ConstructTripletList
USE TripletModule, ONLY : Triplet_r
USE NTMPIModule
IMPLICIT NONE
Expand Down
44 changes: 6 additions & 38 deletions Source/Fortran/DMatrixModule.F90
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ MODULE DMatrixModule
PUBLIC :: TransposeMatrix
PUBLIC :: EigenDecomposition
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
INTERFACE Matrix_ldr
MODULE PROCEDURE ConstructEmptyMatrix_ldr
END INTERFACE Matrix_ldr
INTERFACE Matrix_ldc
MODULE PROCEDURE ConstructEmptyMatrix_ldc
END INTERFACE Matrix_ldc
INTERFACE ConstructEmptyMatrix
MODULE PROCEDURE ConstructEmptyMatrixSup_ldr
MODULE PROCEDURE ConstructEmptyMatrixSup_ldc
Expand Down Expand Up @@ -108,21 +102,8 @@ PURE SUBROUTINE ConstructEmptyMatrixSup_ldr(this, rows, columns)
INTEGER, INTENT(IN) :: columns

CALL DestructMatrix(this)
this = ConstructEmptyMatrix_ldr(rows, columns)
END SUBROUTINE ConstructEmptyMatrixSup_ldr
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!> Construct an empty dense matrix with a set number of rows and columns
PURE FUNCTION ConstructEmptyMatrix_ldr(rows, columns) RESULT(this)
!> The matrix to construct.
TYPE(Matrix_ldr) :: this
!> Rows of the matrix
INTEGER, INTENT(IN) :: rows
!> Columns of the matrix.
INTEGER, INTENT(IN) :: columns

#include "dense_includes/ConstructEmptyMatrix.f90"

END FUNCTION ConstructEmptyMatrix_ldr
END SUBROUTINE ConstructEmptyMatrixSup_ldr
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!> A function that converts a sparse matrix to a dense matrix.
PURE SUBROUTINE ConstructMatrixDFromS_ldr(sparse_matrix, dense_matrix)
Expand Down Expand Up @@ -357,7 +338,7 @@ SUBROUTINE EigenDecomposition_ldr(MatA, MatV, MatW)
INTEGER :: INFO
INTEGER :: II

MatV = Matrix_ldr(MatA%rows,MatA%columns)
CALL ConstructEmptyMatrix(MatV, MatA%rows, MatA%columns)
MatV%DATA = MatA%DATA

N = SIZE(MatA%DATA,DIM=1)
Expand All @@ -382,7 +363,7 @@ SUBROUTINE EigenDecomposition_ldr(MatA, MatV, MatW)

!! Extract Eigenvalues
IF (PRESENT(MatW)) THEN
MatW = Matrix_ldr(MatA%rows, MatA%columns)
CALL ConstructEmptyMatrix(MatW, MatA%rows, MatA%columns)
MatW%DATA = 0
DO II = 1, N
MatW%DATA(II,II) = W(II)
Expand All @@ -405,21 +386,8 @@ PURE SUBROUTINE ConstructEmptyMatrixSup_ldc(this, rows, columns)
INTEGER, INTENT(IN) :: columns

CALL DestructMatrix(this)
this = ConstructEmptyMatrix_ldc(rows, columns)
END SUBROUTINE ConstructEmptyMatrixSup_ldc
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!> Construct an empty dense matrix with a set number of rows and columns
PURE FUNCTION ConstructEmptyMatrix_ldc(rows, columns) RESULT(this)
!> The matrix to construct.
TYPE(Matrix_ldc) :: this
!> Rows of the matrix
INTEGER, INTENT(IN) :: rows
!> Columns of the matrix.
INTEGER, INTENT(IN) :: columns

#include "dense_includes/ConstructEmptyMatrix.f90"

END FUNCTION ConstructEmptyMatrix_ldc
END SUBROUTINE ConstructEmptyMatrixSup_ldc
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!> A function that converts a sparse matrix to a dense matrix.
PURE SUBROUTINE ConstructMatrixDFromS_ldc(sparse_matrix, dense_matrix)
Expand Down Expand Up @@ -661,7 +629,7 @@ SUBROUTINE EigenDecomposition_ldc(MatA, MatV, MatW)
INTEGER, DIMENSION(1) :: IWORKTEMP
INTEGER :: II

MatV = Matrix_ldc(MatA%rows,MatA%columns)
CALL ConstructEmptyMatrix(MatV, MatA%rows, MatA%columns)
MatV%DATA = MatA%DATA

N = SIZE(MatA%DATA,DIM=1)
Expand All @@ -688,7 +656,7 @@ SUBROUTINE EigenDecomposition_ldc(MatA, MatV, MatW)

!! Extract Eigenvalues
IF (PRESENT(MatW)) THEN
MatW = Matrix_ldc(MatA%rows, MatA%columns)
CALL ConstructEmptyMatrix(MatW, MatA%rows, MatA%columns)
MatW%DATA = 0
DO II = 1, N
MatW%DATA(II,II) = W(II)
Expand Down
4 changes: 2 additions & 2 deletions Source/Fortran/EigenBoundsModule.F90
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ MODULE EigenBoundsModule
USE SolverParametersModule, ONLY : SolverParameters_t, PrintParameters, &
& DestructSolverParameters
USE TripletListModule, ONLY : TripletList_r, TripletList_c, &
& AppendToTripletList, DestructTripletList
& AppendToTripletList, DestructTripletList, ConstructTripletList
USE TripletModule, ONLY : Triplet_r
USE NTMPIModule
IMPLICIT NONE
Expand Down Expand Up @@ -92,7 +92,7 @@ SUBROUTINE PowerBounds(this, max_value, solver_parameters_in)
CALL ConstructEmptyMatrix(vector2, this)

!! Guess Vector
temp_list = TripletList_r()
CALL ConstructTripletList(temp_list)
IF (this%process_grid%global_rank .EQ. 0) THEN
temp_triplet%index_row = 1
temp_triplet%index_column = 1
Expand Down
36 changes: 0 additions & 36 deletions Source/Fortran/MatrixMemoryPoolModule.F90
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ MODULE MatrixMemoryPoolModule
PUBLIC :: CheckMemoryPoolValidity
PUBLIC :: SetPoolSparsity
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
INTERFACE MatrixMemoryPool_lr
MODULE PROCEDURE ConstructMatrixMemoryPool_lr
END INTERFACE MatrixMemoryPool_lr
INTERFACE MatrixMemoryPool_lc
MODULE PROCEDURE ConstructMatrixMemoryPool_lc
END INTERFACE MatrixMemoryPool_lc
INTERFACE ConstructMatrixMemoryPool
MODULE PROCEDURE ConstructMatrixMemoryPoolSub_lr
MODULE PROCEDURE ConstructMatrixMemoryPoolSub_lc
Expand Down Expand Up @@ -109,36 +103,6 @@ SUBROUTINE ConstructMatrixMemoryPoolSub_lc(this, columns, rows, sparsity_in)
#include "dense_includes/ConstructMatrixMemoryPool.f90"

END SUBROUTINE ConstructMatrixMemoryPoolSub_lc
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!> Construct Matrix Memory Pool object.
FUNCTION ConstructMatrixMemoryPool_lr(columns, rows, sparsity_in) RESULT(this)
!> The matrix to construct.
TYPE(MatrixMemoryPool_lr), TARGET :: this
!> Number of columns in the matrix.
INTEGER, INTENT(IN) :: columns
!> Number of rows in the matrix.
INTEGER, INTENT(IN) :: rows
!> Estimated sparsity (optional).
REAL(NTREAL), INTENT(IN), OPTIONAL :: sparsity_in

#include "dense_includes/ConstructMatrixMemoryPool.f90"

END FUNCTION ConstructMatrixMemoryPool_lr
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!> Construct Matrix Memory Pool object.
FUNCTION ConstructMatrixMemoryPool_lc(columns, rows, sparsity_in) RESULT(this)
!> The matrix to construct.
TYPE(MatrixMemoryPool_lc), TARGET :: this
!> Number of columns in the matrix.
INTEGER, INTENT(IN) :: columns
!> Number of rows in the matrix.
INTEGER, INTENT(IN) :: rows
!> Estimated sparsity (optional).
REAL(NTREAL), INTENT(IN), OPTIONAL :: sparsity_in

#include "dense_includes/ConstructMatrixMemoryPool.f90"

END FUNCTION ConstructMatrixMemoryPool_lc
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!> A destructor for a matrix memory pool
PURE SUBROUTINE DestructMatrixMemoryPool_lr(this)
Expand Down
12 changes: 7 additions & 5 deletions Source/Fortran/PMatrixMemoryPoolModule.F90
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ MODULE PMatrixMemoryPoolModule
TYPE(MatrixMemoryPool_lc), DIMENSION(:,:), ALLOCATABLE, PUBLIC :: grid_c
END TYPE MatrixMemoryPool_p
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
PUBLIC :: ConstructMatrixMemoryPool
PUBLIC :: DestructMatrixMemoryPool
PUBLIC :: CheckMemoryPoolValidity
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
INTERFACE MatrixMemoryPool_p
INTERFACE ConstructMatrixMemoryPool
MODULE PROCEDURE ConstructMatrixMemoryPool_p
END INTERFACE MatrixMemoryPool_p
END INTERFACE
INTERFACE DestructMatrixMemoryPool
MODULE PROCEDURE DestructMatrixMemoryPool_p
END INTERFACE DestructMatrixMemoryPool
Expand All @@ -30,12 +31,13 @@ MODULE PMatrixMemoryPoolModule
END INTERFACE CheckMemoryPoolValidity
CONTAINS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!> Construct Distributed Matrix Memory Pool object.
PURE FUNCTION ConstructMatrixMemoryPool_p(matrix) RESULT(this)
PURE SUBROUTINE ConstructMatrixMemoryPool_p(this, matrix)
!> A constructed Matrix Memory Pool object.
TYPE(MatrixMemoryPool_p) :: this
TYPE(MatrixMemoryPool_p), INTENT(INOUT) :: this
!> The associated distributed sparse matrix.
TYPE(Matrix_ps), INTENT(IN) :: matrix

CALL DestructMatrixMemoryPool(this)
!! Allocate
IF (matrix%is_complex) THEN
ALLOCATE(this%grid_c(matrix%process_grid%number_of_blocks_rows, &
Expand All @@ -44,7 +46,7 @@ PURE FUNCTION ConstructMatrixMemoryPool_p(matrix) RESULT(this)
ALLOCATE(this%grid_r(matrix%process_grid%number_of_blocks_rows, &
& matrix%process_grid%number_of_blocks_columns))
END IF
END FUNCTION ConstructMatrixMemoryPool_p
END SUBROUTINE ConstructMatrixMemoryPool_p
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!> Destruct a Distributed Matrix Memory Pool object.
PURE SUBROUTINE DestructMatrixMemoryPool_p(this)
Expand Down
13 changes: 7 additions & 6 deletions Source/Fortran/PSMatrixAlgebraModule.F90
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ MODULE PSMatrixAlgebraModule
& ReduceAndSumMatrixCleanup, TestReduceSizeRequest, &
& TestReduceInnerRequest, TestReduceDataRequest
USE PMatrixMemoryPoolModule, ONLY : MatrixMemoryPool_p, &
& CheckMemoryPoolValidity, DestructMatrixMemoryPool
& CheckMemoryPoolValidity, DestructMatrixMemoryPool, &
& ConstructMatrixMemoryPool
USE PSMatrixModule, ONLY : Matrix_ps, ConstructEmptyMatrix, CopyMatrix, &
& DestructMatrix, ConvertMatrixToComplex, ConjugateMatrix, &
& MergeMatrixLocalBlocks, IsIdentity
Expand Down Expand Up @@ -140,19 +141,19 @@ SUBROUTINE MatrixMultiply_ps(matA, matB ,matC, alpha_in, beta_in, &
IF (matA%is_complex) THEN
IF (.NOT. CheckMemoryPoolValidity(memory_pool_in, matA)) THEN
CALL DestructMatrixMemoryPool(memory_pool_in)
memory_pool_in = MatrixMemoryPool_p(matA)
CALL ConstructMatrixMemoryPool(memory_pool_in, matA)
END IF
ELSE
IF (.NOT. CheckMemoryPoolValidity(memory_pool_in, matB)) THEN
CALL DestructMatrixMemoryPool(memory_pool_in)
memory_pool_in = MatrixMemoryPool_p(matB)
CALL ConstructMatrixMemoryPool(memory_pool_in, matB)
END IF
END IF
ELSE
IF (matA%is_complex) THEN
memory_pool = MatrixMemoryPool_p(matA)
CALL ConstructMatrixMemoryPool(memory_pool, matA)
ELSE
memory_pool = MatrixMemoryPool_p(matB)
CALL ConstructMatrixMemoryPool(memory_pool, matB)
END IF
END IF

Expand Down Expand Up @@ -586,7 +587,7 @@ SUBROUTINE SimilarityTransform(A, P, PInv, ResMat, pool_in, threshold_in)
threshold = threshold_in
END IF
IF (.NOT. PRESENT(pool_in)) THEN
pool = MatrixMemoryPool_p(A)
CALL ConstructMatrixMemoryPool(pool, A)
END IF

!! Check if P is the identity matrix, if so we can exit early.
Expand Down
6 changes: 4 additions & 2 deletions Source/Fortran/PSMatrixModule.F90
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,15 @@ SUBROUTINE ConstructEmptyMatrix_ps(this, matrix_dim_, process_grid_in, &
IF (this%is_complex) THEN
ALLOCATE(this%local_data_c(this%process_grid%number_of_blocks_rows, &
& this%process_grid%number_of_blocks_columns))
zeromatrix_c = Matrix_lsc(this%local_rows, this%local_columns)
CALL ConstructEmptyMatrix(zeromatrix_c, this%local_rows, &
& this%local_columns)
CALL SplitMatrixToLocalBlocks(this, zeromatrix_c)
CALL DestructMatrix(zeromatrix_c)
ELSE
ALLOCATE(this%local_data_r(this%process_grid%number_of_blocks_rows, &
& this%process_grid%number_of_blocks_columns))
zeromatrix_r = Matrix_lsr(this%local_rows, this%local_columns)
CALL ConstructEmptyMatrix(zeromatrix_r, this%local_rows, &
& this%local_columns)
CALL SplitMatrixToLocalBlocks(this, zeromatrix_r)
CALL DestructMatrix(zeromatrix_r)
END IF
Expand Down
Loading

0 comments on commit 768569a

Please sign in to comment.