Skip to content

Commit

Permalink
80 Column Limit Enforcement (#152)
Browse files Browse the repository at this point in the history
* 80 Column Limit Enforcement

* Fix ci for awk

* No clang format installed.

* Still something missing...

* More narrowing

* Linting only on mac.

* Homebrew install emacs
  • Loading branch information
william-dawson authored May 27, 2020
1 parent 9fb50d7 commit 14402bb
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
debug: 0
noalligather: 0
mpich: 0
lint: 1
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
Expand Down Expand Up @@ -81,5 +82,6 @@ jobs:
env:
TESTEXAMPLES: ${{ matrix.testexamples }}
- name: lint
if: ${{ matrix.lint }}
run: |
bash UnitTests/lint.sh
3 changes: 2 additions & 1 deletion Examples/HydrogenAtom/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ We need to solve the following equation:
The kinetic energy operator is based on a 5 point stencil central difference
formula. See the following link:
http://www.holoborodko.com/pavel/numerical-methods/numerical-derivative/central-differences/
http://www.holoborodko.com/pavel/numerical-methods/numerical-derivative/
central-differences/

The potential energy operator is diagonal in real space.

Expand Down
15 changes: 8 additions & 7 deletions Examples/OverlapMatrix/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,18 @@ Next we need to divide up the matrix. First, we compute how many matrix rows
and columns are stored locally. This is just the total matrix size divided
by the number of process rows/columns.

Second, we compute the starting and ending rows/columns. In the ProcessGridModule,
there are global variables "my_row" and "my_column" which gives the xy coordinates
of a given process. This information can be used to compute the starting row
and column, and then we just add to those values the number of local rows/columns.
Second, we compute the starting and ending rows/columns. In the
ProcessGridModule, there are global variables "my_row" and "my_column" which
gives the xy coordinates of a given process. This information can be used to
compute the starting row and column, and then we just add to those values the
number of local rows/columns.

## Compute The Local Matrix Elements

Now that we know the local rows and columns of the matrix, we can compute
the local matrix elements. We do that by looping over the local rows and columns,
and calling the "ComputeIntegral" function. This ComputeIntegral function is of
course just a dummy function.
the local matrix elements. We do that by looping over the local rows and
columns, and calling the "ComputeIntegral" function. This ComputeIntegral
function is of course just a dummy function.

Since we don't know a priori which integrals can be neglected, what we do is
compute each one, and then test if the value is bigger than some threshold.
Expand Down
3 changes: 2 additions & 1 deletion Source/Fortran/PSMatrixModule.F90
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ RECURSIVE SUBROUTINE ConstructMatrixFromMatrixMarket_ps(this, file_name, &
local_file_handler = 16
OPEN(local_file_handler, file=file_name, iostat=ierr, status="old")
IF (ierr .NE. 0) THEN
CALL SetGenericError(err, TRIM(file_name)//" doesn't exist", .TRUE.)
CALL SetGenericError(err, TRIM(file_name)//" doesn't exist", &
& .TRUE.)
END IF
!! Parse the header.
READ(local_file_handler,fmt='(A)') input_buffer
Expand Down
3 changes: 2 additions & 1 deletion Source/Fortran/ProcessGridModule.F90
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ SUBROUTINE ConstructNewProcessGrid_full(grid, world_comm_, process_rows_, &
!! Grid ID
CALL MPI_COMM_RANK(grid%global_comm,grid%global_rank,ierr)
grid%my_slice = grid%global_rank/grid%slice_size
grid%my_row = MOD(grid%global_rank, grid%slice_size)/grid%num_process_columns
grid%my_row = MOD(grid%global_rank, grid%slice_size)/ &
& grid%num_process_columns
grid%my_column = MOD(grid%global_rank, grid%num_process_columns)

!! Grid Communicators
Expand Down
3 changes: 2 additions & 1 deletion Source/Fortran/TrigonometrySolversModule.F90
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ SUBROUTINE ScaleSquareTrigonometry(InputMat, OutputMat, solver_parameters_in)
CALL WriteHeader("Trigonometry Solver")
CALL EnterSubLog
CALL WriteElement(key="Method", VALUE="Chebyshev")
CALL WriteCitation("serbin1980algorithm higham2003computing yau1993reducing")
CALL WriteCitation("serbin1980algorithm higham2003computing&
& yau1993reducing")
CALL PrintParameters(solver_parameters)
END IF

Expand Down
18 changes: 9 additions & 9 deletions Source/Fortran/sparse_includes/IncrementMatrix.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
!! Counter Variables
INTEGER :: outer_counter
INTEGER :: elements_per_inner_a, elements_per_inner_b
INTEGER :: inner_a, inner_b
INTEGER :: total_counter_a, total_counter_b, total_counter_c
!! Temporary Variables
INTEGER :: indices_added_into_c
Expand Down Expand Up @@ -39,21 +39,21 @@
total_counter_c = 1
DO outer_counter = 1, matA%columns
!! Inner counters
elements_per_inner_a = matA%outer_index(outer_counter+1) - &
inner_a = matA%outer_index(outer_counter+1) - &
& matA%outer_index(outer_counter)
elements_per_inner_b = matB%outer_index(outer_counter+1) - &
inner_b = matB%outer_index(outer_counter+1) - &
& matB%outer_index(outer_counter)
CALL AddSparseVectors(&
matA%inner_index(total_counter_a:total_counter_a+elements_per_inner_a-1),&
matA%values(total_counter_a:total_counter_a+elements_per_inner_a-1),&
matB%inner_index(total_counter_b:total_counter_b+elements_per_inner_b-1),&
matB%values(total_counter_b:total_counter_b+elements_per_inner_b-1),&
matA%inner_index(total_counter_a:total_counter_a+inner_a-1),&
matA%values(total_counter_a:total_counter_a+inner_a-1),&
matB%inner_index(total_counter_b:total_counter_b+inner_b-1),&
matB%values(total_counter_b:total_counter_b+inner_b-1),&
matC%inner_index(total_counter_c:),matC%values(total_counter_c:),&
indices_added_into_c, alpha, threshold)
matC%outer_index(outer_counter+1) = matC%outer_index(outer_counter)+&
& indices_added_into_c
total_counter_a = total_counter_a + elements_per_inner_a
total_counter_b = total_counter_b + elements_per_inner_b
total_counter_a = total_counter_a + inner_a
total_counter_b = total_counter_b + inner_b
total_counter_c = total_counter_c + indices_added_into_c
END DO

Expand Down
24 changes: 13 additions & 11 deletions Source/Fortran/sparse_includes/PairwiseMultiplyMatrix.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
!! Counter Variables
INTEGER :: outer_counter
INTEGER :: elements_per_inner_a, elements_per_inner_b
INTEGER :: inner_a, inner_b
INTEGER :: total_counter_a, total_counter_b, total_counter_c
!! Temporary Variables
INTEGER :: indices_added_into_c
Expand All @@ -18,21 +18,22 @@
total_counter_c = 1
DO outer_counter = 1, matA%columns
!! Inner counters
elements_per_inner_a = matA%outer_index(outer_counter+1) - &
inner_a = matA%outer_index(outer_counter+1) - &
& matA%outer_index(outer_counter)
elements_per_inner_b = matB%outer_index(outer_counter+1) - &
inner_b = matB%outer_index(outer_counter+1) - &
& matB%outer_index(outer_counter)
CALL PairwiseMultiplyVectors(&
matA%inner_index(total_counter_a:total_counter_a+elements_per_inner_a-1),&
matA%values(total_counter_a:total_counter_a+elements_per_inner_a-1),&
matB%inner_index(total_counter_b:total_counter_b+elements_per_inner_b-1),&
matB%values(total_counter_b:total_counter_b+elements_per_inner_b-1),&
TempMat%inner_index(total_counter_c:),TempMat%values(total_counter_c:),&
matA%inner_index(total_counter_a:total_counter_a+inner_a-1),&
matA%values(total_counter_a:total_counter_a+inner_a-1),&
matB%inner_index(total_counter_b:total_counter_b+inner_b-1),&
matB%values(total_counter_b:total_counter_b+inner_b-1),&
TempMat%inner_index(total_counter_c:),&
TempMat%values(total_counter_c:),&
indices_added_into_c)
TempMat%outer_index(outer_counter+1) = TempMat%outer_index(outer_counter)+&
& indices_added_into_c
total_counter_a = total_counter_a + elements_per_inner_a
total_counter_b = total_counter_b + elements_per_inner_b
total_counter_a = total_counter_a + inner_a
total_counter_b = total_counter_b + inner_b
total_counter_c = total_counter_c + indices_added_into_c
END DO

Expand All @@ -42,6 +43,7 @@
matC%outer_index = TempMat%outer_index
ALLOCATE(matC%inner_index(TempMat%outer_index(TempMat%columns+1)))
ALLOCATE(matC%values(TempMat%outer_index(TempMat%columns+1)))
matC%inner_index = TempMat%inner_index(:TempMat%outer_index(TempMat%columns+1))
matC%inner_index = TempMat%inner_index(&
& :TempMat%outer_index(TempMat%columns+1))
matC%values = TempMat%values(:TempMat%outer_index(TempMat%columns+1))
CALL DestructMatrix(TempMat)
8 changes: 4 additions & 4 deletions Source/Fortran/triplet_includes/SortTripletList.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
INTEGER, DIMENSION(:), ALLOCATABLE :: inserted_per_row
!! Counters and temporary variables
INTEGER :: counter
INTEGER :: temp_index
INTEGER :: idx
INTEGER :: alloc_stat
INTEGER :: list_length

Expand Down Expand Up @@ -43,10 +43,10 @@
& values_per_row(counter-1)
END DO
DO counter = 1, input_list%CurrentSize
temp_index = input_list%DATA(counter)%index_column
sorted_list%DATA(offset_array(temp_index)+inserted_per_row(temp_index))=&
idx = input_list%DATA(counter)%index_column
sorted_list%DATA(offset_array(idx)+inserted_per_row(idx))=&
& input_list%DATA(counter)
inserted_per_row(temp_index) = inserted_per_row(temp_index) + 1
inserted_per_row(idx) = inserted_per_row(idx) + 1
END DO

!! Finish with bubble sort
Expand Down
6 changes: 4 additions & 2 deletions Source/Wrapper/PSMatrixModule_wrp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ END SUBROUTINE GetMatrixTripletList_psc_wrp
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!> Extract an arbitrary block of a matrix into a triplet list.
SUBROUTINE GetMatrixBlock_psr_wrp(ih_this, ih_triplet_list, start_row, &
& end_row, start_column, end_column) BIND(c,NAME="GetMatrixBlock_psr_wrp")
& end_row, start_column, end_column) &
& BIND(c,NAME="GetMatrixBlock_psr_wrp")
INTEGER(KIND=c_int), INTENT(IN) :: ih_this(SIZE_wrp)
INTEGER(KIND=c_int), INTENT(INOUT) :: ih_triplet_list(SIZE_wrp)
INTEGER(KIND=c_int), INTENT(IN) :: start_row, end_row
Expand All @@ -346,7 +347,8 @@ END SUBROUTINE GetMatrixBlock_psr_wrp
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!> Extract an arbitrary block of a matrix into a triplet list.
SUBROUTINE GetMatrixBlock_psc_wrp(ih_this, ih_triplet_list, start_row, &
& end_row, start_column, end_column) BIND(c,NAME="GetMatrixBlock_psc_wrp")
& end_row, start_column, end_column) &
& BIND(c,NAME="GetMatrixBlock_psc_wrp")
INTEGER(KIND=c_int), INTENT(IN) :: ih_this(SIZE_wrp)
INTEGER(KIND=c_int), INTENT(INOUT) :: ih_triplet_list(SIZE_wrp)
INTEGER(KIND=c_int), INTENT(IN) :: start_row, end_row
Expand Down
2 changes: 1 addition & 1 deletion Source/Wrapper/TripletListModule_wrp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ MODULE TripletListModule_wrp
PUBLIC :: GetTripletAt_r_wrp
PUBLIC :: SortTripletList_r_wrp
PUBLIC :: GetTripletListSize_r_wrp
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
PUBLIC :: ConstructTripletList_c_wrp
PUBLIC :: DestructTripletList_c_wrp
PUBLIC :: ResizeTripletList_c_wrp
Expand Down
4 changes: 4 additions & 0 deletions UnitTests/before_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ if [[ "$TESTOS" == "LINUX" ]]; then
sudo apt-get update
sudo apt-get install gfortran
sudo apt-get install libblas-dev liblapack-dev
sudo apt-get install gawk
sudo apt-get install clang-format
sudo apt-get install emacs
if [[ "$MPICH" == "1" ]]; then
sudo apt-get install mpich libmpich-dev
else
Expand All @@ -18,6 +21,7 @@ if [[ "$TESTOS" == "OSX" ]]; then
brew install cmake
brew install swig
brew install clang-format
brew install emacs
sudo pip2 install numpy --upgrade --no-cache-dir
sudo pip2 install scipy --upgrade --no-cache-dir
sudo pip2 install mpi4py --upgrade --no-cache-dir
Expand Down
9 changes: 8 additions & 1 deletion UnitTests/lint.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
set -e

# Python
flake8 UnitTests
flake8 Examples
Expand All @@ -16,6 +18,11 @@ for f in $(find . -type f -name "*.*90"); do
--eval="(f90-indent-subprogram)" -f save-buffer 2>/dev/null
done

# 80 Column Limit
for f in $(find -L Source Targets UnitTests); do
awk 'NF > 80 {print FILENAME ; print "Line " NR ; print ; stat = 1} \
END {exit stat}' FS= $f 2>/dev/null
done

# If git returns any changes, we know there is a problem.
set -e
git --no-pager diff --exit-code

0 comments on commit 14402bb

Please sign in to comment.