Skip to content

Commit

Permalink
Code uniformity changes (#200)
Browse files Browse the repository at this point in the history
* Cleanup for triplets/timers/loggins/errors

Credit to ChatGPT

* Copy/construct pattern for solver parameters and permutations

* Cleanup + Examples

* Linting

* Example fixes

* Variable fixes

* Remove unused variable

* Comment typo fix

credit chatgpt

* Fix interface issue

* Additional cleanup

* Remove timers

* Fix missing in/out intent

* Explicit copy routine for triplet lists

* Additional include

* Don't used fixed shape

* Split up the multiply

* Generic error should be public

* Cleaner implementation of dense conversion

* Spacing

* Cleanup the matrix reduction module

* More assorted cleanup

* More cleanup

* Spacing fixes

* Last set of spacing issues

* lint

* lint
  • Loading branch information
william-dawson authored Apr 25, 2023
1 parent dcf5254 commit b5fa45d
Show file tree
Hide file tree
Showing 131 changed files with 2,666 additions and 2,697 deletions.
14 changes: 8 additions & 6 deletions Examples/ComplexMatrix/main.f90
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ PROGRAM ComplexMatrix
& PrintMatrix, CopyMatrix, WriteMatrixToMatrixMarket
USE ProcessGridModule, ONLY : ConstructProcessGrid, DestructProcessGrid, &
& IsRoot
USE SolverParametersModule, ONLY : SolverParameters_t
USE SolverParametersModule, ONLY : SolverParameters_t, &
& ConstructSolverParameters, DestructSolverParameters
USE TripletListModule, ONLY : TripletList_r, DestructTripletList, &
& GetTripletAt, TripletList_c, ConstructTripletList, &
& AppendToTripletList, SymmetrizeTripletList
Expand All @@ -35,16 +36,16 @@ PROGRAM ComplexMatrix
!! Temporary Variables
CHARACTER(len=80) :: argument
CHARACTER(len=80) :: argument_value
INTEGER :: counter
INTEGER :: II
INTEGER :: provided, ierr

!! Setup MPI
CALL MPI_Init_thread(MPI_THREAD_SERIALIZED, provided, ierr)

!! Process The Input
DO counter=1,COMMAND_ARGUMENT_COUNT(),2
CALL GET_COMMAND_ARGUMENT(counter,argument)
CALL GET_COMMAND_ARGUMENT(counter+1,argument_value)
DO II = 1, COMMAND_ARGUMENT_COUNT(), 2
CALL GET_COMMAND_ARGUMENT(II, argument)
CALL GET_COMMAND_ARGUMENT(II + 1, argument_value)
SELECT CASE(argument)
CASE('--input_file')
input_file = argument_value
Expand Down Expand Up @@ -85,7 +86,7 @@ PROGRAM ComplexMatrix
CALL ScaleMatrix(GMat, 0.5_NTREAL)

!! Compute The Exponential
solver_parameters = SolverParameters_t(threshold_in=threshold)
CALL ConstructSolverParameters(solver_parameters, threshold_in=threshold)
CALL ComputeExponential(GMat, ExMat, solver_parameters)

!! Write To File
Expand All @@ -96,6 +97,7 @@ PROGRAM ComplexMatrix
CALL DestructMatrix(GMat)

!! Cleanup
CALL DestructSolverParameters(solver_parameters)
IF (IsRoot()) THEN
CALL DeactivateLogger
END IF
Expand Down
48 changes: 25 additions & 23 deletions Examples/GraphTheory/main.f90
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ PROGRAM GraphTheory
& ConstructEmptyMatrix, FillMatrixFromTripletList, DestructMatrix, &
& CopyMatrix, FillMatrixIdentity
USE PSMatrixAlgebraModule, ONLY: IncrementMatrix
USE SolverParametersModule, ONLY : SolverParameters_t
USE SolverParametersModule, ONLY : SolverParameters_t, &
& ConstructSolverParameters, DestructSolverParameters
USE TripletListModule, ONLY : TripletList_r, ConstructTripletList, &
& SetTripletAt, AppendToTripletList
USE TripletModule, ONLY : Triplet_r
Expand Down Expand Up @@ -42,17 +43,17 @@ PROGRAM GraphTheory
!! Temporary Values
CHARACTER(len=80) :: argument
CHARACTER(len=80) :: argument_value
INTEGER :: counter
INTEGER :: II

!! Setup MPI
CALL MPI_Init_thread(MPI_THREAD_SERIALIZED, provided, ierr)
CALL MPI_Comm_rank(MPI_COMM_WORLD, rank, ierr)
CALL MPI_Comm_size(MPI_COMM_WORLD, total_processors, ierr)

!! Process the input parameters.
DO counter=1,COMMAND_ARGUMENT_COUNT(),2
CALL GET_COMMAND_ARGUMENT(counter,argument)
CALL GET_COMMAND_ARGUMENT(counter+1,argument_value)
DO II = 1, COMMAND_ARGUMENT_COUNT(), 2
CALL GET_COMMAND_ARGUMENT(II, argument)
CALL GET_COMMAND_ARGUMENT(II + 1, argument_value)
SELECT CASE(argument)
CASE('--output_file')
output_file = argument_value
Expand Down Expand Up @@ -97,7 +98,7 @@ PROGRAM GraphTheory
CALL ExitSubLog

!! Set Up The Solver Parameters.
solver_parameters = SolverParameters_t( be_verbose_in=.TRUE., &
CALL ConstructSolverParameters(solver_parameters, be_verbose_in=.TRUE., &
& converge_diff_in=convergence_threshold, threshold_in=threshold)

CALL DivideUpWork
Expand All @@ -121,6 +122,7 @@ PROGRAM GraphTheory
IF (IsRoot()) THEN
CALL DeactivateLogger
END IF
CALL DestructSolverParameters(solver_parameters)
CALL DestructProcessGrid
CALL MPI_Finalize(ierr)
CONTAINS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Expand All @@ -132,8 +134,8 @@ SUBROUTINE DivideUpWork()
number_of_local_nodes = number_of_nodes - rank*number_of_local_nodes
END IF
ALLOCATE(local_nodes(number_of_local_nodes))
fillrow: DO counter=1,number_of_local_nodes
local_nodes(counter) = starting_node + (counter-1)
fillrow: DO II = 1, number_of_local_nodes
local_nodes(II) = starting_node + (II-1)
END DO fillrow
ending_node = local_nodes(number_of_local_nodes)
END SUBROUTINE DivideUpWork
Expand All @@ -142,48 +144,48 @@ SUBROUTINE FillMatrix
TYPE(TripletList_r) :: triplet_list
TYPE(Triplet_r) :: temp_triplet
INTEGER :: num_of_edges
INTEGER :: counter
INTEGER :: II
INTEGER, DIMENSION(:), ALLOCATABLE :: extra_scratch
REAL :: temporary
INTEGER :: extra_source_node, extra_destination_node

CALL ConstructTripletList(triplet_list)

!! First add the connection between each node and itself.
fill_diagonal: DO counter=1, number_of_local_nodes
temp_triplet%index_row = local_nodes(counter)
temp_triplet%index_column = local_nodes(counter)
fill_diagonal: DO II = 1, number_of_local_nodes
temp_triplet%index_row = local_nodes(II)
temp_triplet%index_column = local_nodes(II)
temp_triplet%point_value = 1
CALL AppendToTripletList(triplet_list,temp_triplet)
END DO fill_diagonal

!! Now connections between nearest neighbors.
fill_neighbor: DO counter=1, number_of_local_nodes
temp_triplet%index_row = local_nodes(counter)
fill_neighbor: DO II = 1, number_of_local_nodes
temp_triplet%index_row = local_nodes(II)
temp_triplet%point_value = 0.1
IF (local_nodes(counter) .EQ. 1) THEN
IF (local_nodes(II) .EQ. 1) THEN
!! Right value
temp_triplet%index_column = local_nodes(counter) + 1
temp_triplet%index_column = local_nodes(II) + 1
CALL AppendToTripletList(triplet_list,temp_triplet)
ELSE IF (local_nodes(counter) .EQ. number_of_nodes) THEN
ELSE IF (local_nodes(II) .EQ. number_of_nodes) THEN
!! Left value
temp_triplet%index_column = local_nodes(counter) - 1
temp_triplet%index_column = local_nodes(II) - 1
CALL AppendToTripletList(triplet_list,temp_triplet)
ELSE
!! Left value
temp_triplet%index_column = local_nodes(counter) - 1
temp_triplet%index_column = local_nodes(II) - 1
CALL AppendToTripletList(triplet_list,temp_triplet)
!! Right value
temp_triplet%index_column = local_nodes(counter) + 1
temp_triplet%index_column = local_nodes(II) + 1
CALL AppendToTripletList(triplet_list,temp_triplet)
END IF
END DO fill_neighbor

!! Finally the random extra connections.
ALLOCATE(extra_scratch(number_of_nodes))
extra_scratch = 0
counter = 1
DO WHILE(counter .LE. extra_connections)
II = 1
DO WHILE(II .LE. extra_connections)
CALL RANDOM_NUMBER(temporary)
extra_source_node = CEILING(temporary*number_of_nodes)
CALL RANDOM_NUMBER(temporary)
Expand All @@ -195,7 +197,7 @@ SUBROUTINE FillMatrix
& extra_source_node .NE. extra_destination_node .AND. &
& extra_source_node .NE. extra_destination_node - 1 .AND. &
& extra_source_node .NE. extra_destination_node + 1) THEN
counter = counter + 1
II = II + 1
extra_scratch(extra_source_node) = 1
extra_scratch(extra_destination_node) = 1

Expand Down
38 changes: 20 additions & 18 deletions Examples/HydrogenAtom/main.f90
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ PROGRAM HydrogenAtom
& ConstructEmptyMatrix, FillMatrixFromTripletList, CopyMatrix, &
& FillMatrixIdentity
USE PSMatrixAlgebraModule, ONLY : IncrementMatrix
USE SolverParametersModule, ONLY : SolverParameters_t
USE SolverParametersModule, ONLY : SolverParameters_t, &
& ConstructSolverParameters, DestructSolverParameters
USE SquareRootSolversModule, ONLY : InverseSquareRoot
USE TripletListModule, ONLY : TripletList_r, ConstructTripletList, &
& AppendToTripletList
Expand Down Expand Up @@ -46,17 +47,17 @@ PROGRAM HydrogenAtom
!! Temporary Variables
CHARACTER(len=80) :: argument
CHARACTER(len=80) :: argument_value
INTEGER :: counter
INTEGER :: II

!! Setup MPI
CALL MPI_Init_thread(MPI_THREAD_SERIALIZED, provided, ierr)
CALL MPI_Comm_rank(MPI_COMM_WORLD, rank, ierr)
CALL MPI_Comm_size(MPI_COMM_WORLD, total_processors, ierr)

!! Process the input parameters.
DO counter=1,COMMAND_ARGUMENT_COUNT(),2
CALL GET_COMMAND_ARGUMENT(counter,argument)
CALL GET_COMMAND_ARGUMENT(counter+1,argument_value)
DO II = 1, COMMAND_ARGUMENT_COUNT(), 2
CALL GET_COMMAND_ARGUMENT(II, argument)
CALL GET_COMMAND_ARGUMENT(II+1, argument_value)
SELECT CASE(argument)
CASE('--convergence_threshold')
READ(argument_value,*) convergence_threshold
Expand Down Expand Up @@ -95,7 +96,7 @@ PROGRAM HydrogenAtom
CALL ExitSubLog

!! Set Up The Solver Parameters.
solver_parameters = SolverParameters_t( be_verbose_in=.TRUE., &
CALL ConstructSolverParameters(solver_parameters, be_verbose_in=.TRUE., &
& converge_diff_in=convergence_threshold, threshold_in=threshold)

!! Divide The Work Amongst Processors.
Expand Down Expand Up @@ -131,6 +132,7 @@ PROGRAM HydrogenAtom
IF (IsRoot()) THEN
CALL DeactivateLogger
END IF
CALL DestructSolverParameters(solver_parameters)
CALL DestructProcessGrid
CALL MPI_Finalize(ierr)
CONTAINS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Expand All @@ -142,8 +144,8 @@ SUBROUTINE DivideUpWork()
local_grid_points = grid_points - rank*local_grid_points
END IF
ALLOCATE(local_rows(local_grid_points))
fillrow: DO counter=1,local_grid_points
local_rows(counter) = start_row + (counter-1)
fillrow: DO II = 1, local_grid_points
local_rows(II) = start_row + (II-1)
END DO fillrow
END SUBROUTINE DivideUpWork
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Expand All @@ -156,23 +158,23 @@ SUBROUTINE ConstructLinearSpace()

!! Fill in the x_values
local_x_start = x_start + (start_row-1) * grid_spacing
fill: DO counter=1,local_grid_points
x_values(counter) = local_x_start + (counter-1)*grid_spacing
fill: DO II = 1, local_grid_points
x_values(II) = local_x_start + (II-1)*grid_spacing
END DO fill
END SUBROUTINE ConstructLinearSpace
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
SUBROUTINE FillKineticEnergy()
!! Local Variables
TYPE(TripletList_r) :: triplet_list
INTEGER :: counter
INTEGER :: II
TYPE(Triplet_r) :: temp_value

CALL ConstructTripletList(triplet_list)

!! Fill The Triplet List.
fill: DO counter = 1, local_grid_points
fill: DO II = 1, local_grid_points
!! Stencil point 1.
temp_value%index_row = start_row + counter - 1
temp_value%index_row = start_row + II - 1
IF (temp_value%index_row .GT. 2) THEN
temp_value%index_column = temp_value%index_row - 2
temp_value%point_value = (-0.5)*(-1.0/(12.0*grid_spacing**2))
Expand Down Expand Up @@ -207,14 +209,14 @@ END SUBROUTINE FillKineticEnergy
SUBROUTINE FillPotentialEnergy()
!! Local Variables
TYPE(TripletList_r) :: triplet_list
INTEGER :: counter
INTEGER :: II
TYPE(Triplet_r) :: temp_value

CALL ConstructTripletList(triplet_list)
fill: DO counter = 1, local_grid_points
temp_value%index_row = start_row + counter - 1
temp_value%index_column = start_row + counter - 1
temp_value%point_value = -1.0/ABS(x_values(counter))
fill: DO II = 1, local_grid_points
temp_value%index_row = start_row + II - 1
temp_value%index_column = start_row + II - 1
temp_value%point_value = -1.0/ABS(x_values(II))
CALL AppendToTripletList(triplet_list, temp_value)
END DO fill
CALL FillMatrixFromTripletList(PotentialEnergy, triplet_list)
Expand Down
8 changes: 4 additions & 4 deletions Examples/MatrixMaps/main.f90
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ PROGRAM MatrixMapsProgram
!! Temporary Variables
CHARACTER(len=80) :: argument
CHARACTER(len=80) :: argument_value
INTEGER :: counter
INTEGER :: II
INTEGER :: provided, ierr
INTEGER :: rank

Expand All @@ -28,9 +28,9 @@ PROGRAM MatrixMapsProgram
CALL MPI_Comm_rank(MPI_COMM_WORLD,rank, ierr)

!! Process the input parameters.
DO counter=1,COMMAND_ARGUMENT_COUNT(),2
CALL GET_COMMAND_ARGUMENT(counter,argument)
CALL GET_COMMAND_ARGUMENT(counter+1,argument_value)
DO II = 1, COMMAND_ARGUMENT_COUNT(), 2
CALL GET_COMMAND_ARGUMENT(II, argument)
CALL GET_COMMAND_ARGUMENT(II+1, argument_value)
SELECT CASE(argument)
CASE('--input_matrix')
input_matrix = argument_value
Expand Down
14 changes: 8 additions & 6 deletions Examples/OverlapMatrix/main.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ PROGRAM OverlapExample
& DestructProcessGrid
USE PSMatrixModule, ONLY : Matrix_ps, ConstructEmptyMatrix, &
& WriteMatrixToMatrixMarket, FillMatrixFromTripletList, DestructMatrix
USE SolverParametersModule, ONLY : SolverParameters_t
USE SolverParametersModule, ONLY : SolverParameters_t, &
& ConstructSolverParameters, DestructSolverParameters
USE SquareRootSolversModule, ONLY : InverseSquareRoot
USE TimerModule, ONLY : RegisterTimer, StartTimer, StopTimer, PrintAllTimers
USE TripletListModule, ONLY : TripletList_r, ConstructTripletList, &
Expand Down Expand Up @@ -41,17 +42,17 @@ PROGRAM OverlapExample
CHARACTER(len=80) :: argument
CHARACTER(len=80) :: argument_value
INTEGER :: column_counter, row_counter
INTEGER :: counter
INTEGER :: ARGII
REAL(ntreal) :: integral_value

!! Setup MPI
CALL MPI_Init_thread(MPI_THREAD_SERIALIZED, provided, ierr)
CALL MPI_Comm_rank(MPI_COMM_WORLD,rank, ierr)

!! Process the input parameters.
DO counter=1,COMMAND_ARGUMENT_COUNT(),2
CALL GET_COMMAND_ARGUMENT(counter,argument)
CALL GET_COMMAND_ARGUMENT(counter+1,argument_value)
DO ARGII = 1, COMMAND_ARGUMENT_COUNT(), 2
CALL GET_COMMAND_ARGUMENT(ARGII, argument)
CALL GET_COMMAND_ARGUMENT(ARGII + 1, argument_value)
SELECT CASE(argument)
CASE('--basis_functions')
READ(argument_value,*) basis_functions
Expand Down Expand Up @@ -126,7 +127,7 @@ PROGRAM OverlapExample
!! Set Up The Solver Parameters.
CALL ConstructRandomPermutation(permutation, &
& Overlap%logical_matrix_dimension)
solver_parameters = SolverParameters_t(&
CALL ConstructSolverParameters(solver_parameters, &
& converge_diff_in=convergence_threshold, threshold_in=threshold, &
& BalancePermutation_in=permutation, be_verbose_in=.TRUE.)

Expand All @@ -144,6 +145,7 @@ PROGRAM OverlapExample
CALL DestructPermutation(permutation)
CALL DestructMatrix(Overlap)
CALL DestructMatrix(ISQOverlap)
CALL DestructSolverParameters(solver_parameters)

!! Cleanup
IF (IsRoot()) THEN
Expand Down
Loading

0 comments on commit b5fa45d

Please sign in to comment.