Skip to content

Commit

Permalink
Added benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
cnegre committed Sep 15, 2021
1 parent eab14aa commit fc3cc68
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ if(PROGRESS_EXAMPLES)
add_subdirectory(examples)
endif()

set(PROGRESS_BENCHMARKS FALSE
CACHE BOOL "Whether to build example programs.")

if(PROGRESS_BENCHMARKS)
message(STATUS "Setting up to build example programs")
add_subdirectory(benchmarks)
endif()

if(OPENMP_FOUND)
message(STATUS "Additional Fortran compiler link flags: '${OpenMP_Fortran_FLAGS}'")
endif()
Expand Down
30 changes: 30 additions & 0 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${CMAKE_BINARY_DIR}/src)
include_directories(${PROJECT_SOURCE_DIR}/tests/src)
include_directories(${BML_INCLUDEDIR})

function(progress_benchmark mybenchmark path_to_benchmark)
add_executable(${mybenchmark} ${path_to_benchmark})
target_link_libraries(${mybenchmark} PUBLIC
progress
${LINK_LIBRARIES})
set_target_properties(${mybenchmark}
PROPERTIES
LINK_FLAGS "--coverage")
if(OPENMP_FOUND)
set_target_properties(${mybenchmark}
PROPERTIES
COMPILE_FLAGS ${OpenMP_Fortran_FLAGS}
LINK_FLAGS ${OpenMP_Fortran_FLAGS})
endif()
if(MPI_Fortran_FOUND AND MPI_Fortran_COMPILE_FLAGS)
set_target_properties(${mybenchmark}
PROPERTIES
COMPILE_FLAGS ${MPI_Fortran_COMPILE_FLAGS}
LINK_FLAGS ${MPI_Fortran_LINK_FLAGS})
endif()
endfunction(progress_benchmark)

progress_benchmark(dmconstruction dmconstruction/dmconstruction.F90)

SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
98 changes: 98 additions & 0 deletions benchmarks/dmconstruction/dmconstruction.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
!> High-level program to construct a model Hamiltonian
!!
program hmodel

!BML lib.
use bml

!PROGRESS lib modes
use prg_modelham_mod
use prg_system_mod
use prg_densitymatrix_mod
use prg_dos_mod
use prg_sp2_mod
use prg_timer_mod
use prg_extras_mod

implicit none
integer, parameter :: dp = kind(1.0d0)
integer :: norbs,seed
integer :: verbose
character(20) :: filename
type(bml_matrix_t) :: ham_bml,rho_bml,rhos_bml,evects_bml,aux_bml
type(mham_type) :: mham
type(system_type) :: sys
real(dp) :: threshold, bndfil
real(dp), allocatable :: trace(:)
real(dp), allocatable :: eigenvalues(:)
real(dp) :: ef,sparsity,dec,mlsi

!Parsing input file.
call getarg(1,filename)
call prg_parse_mham(mham,trim(adjustl(filename))) !Reads the input for modelham

!Number of orbitals/matrix size
norbs=mham%norbs

!Allocating bml matrices
call bml_zero_matrix(mham%bml_type,bml_element_real,dp,norbs,norbs,ham_bml)
call bml_zero_matrix(mham%bml_type,bml_element_real,dp,norbs,norbs,rho_bml)
call bml_zero_matrix(mham%bml_type,bml_element_real,dp,norbs,norbs,evects_bml)
call bml_zero_matrix(mham%bml_type,bml_element_real,dp,norbs,norbs,rhos_bml)
call bml_zero_matrix(mham%bml_type,bml_element_real,dp,norbs,norbs,aux_bml)

seed = 1000 !Seed to reproduce the Hamiltonian build
verbose = 1 !Verbosity level
threshold = 1.0d-5 !Threshold value for the matrices through the whole code
bndfil = 0.5d0 !Fraction of orbitals that will be filled

allocate(eigenvalues(norbs))

!Constructing the Hamiltonian
call prg_twolevel_model(mham%ea, mham%eb, mham%dab, mham%daiaj, mham%dbibj, &
&mham%dec, mham%rcoeff, mham%reshuffle, mham%seed, ham_bml, verbose)
call bml_threshold(ham_bml, threshold)
call bml_print_matrix("ham_bml",ham_bml,0,10,0,10)

sparsity = bml_get_sparsity(ham_bml, 1.0D-5)
write(*,*)"Sparsity Ham=",sparsity

!Computing the density matrix with diagonalization
mlsi = mls()
call prg_build_density_T0(ham_bml, rho_bml, threshold, bndfil, eigenvalues)
write(*,*)"Time_for_prg_build_density_T0",mls()-mlsi

sparsity = bml_get_sparsity(rho_bml, 1.0D-5)
write(*,*)"Sparsity Rho=",sparsity

!Getting the fermi level
ef = (eigenvalues(int(norbs/2)+1) + eigenvalues(int(norbs/2)))/2
eigenvalues = eigenvalues - ef

!Writting the total DOS
call prg_write_tdos(eigenvalues, 0.05d0, 10000, -20.0d0, 20.0d0, "tdos.dat")

!Solving for Rho using SP2
mlsi = mls()
call prg_sp2_alg1(ham_bml,rhos_bml,threshold,bndfil,15,100 &
,"Rel",1.0D-10,20)
write(*,*)"Time_for_prg_sp2_alg1",mls()-mlsi
call bml_print_matrix("rho_bml",rho_bml,0,10,0,10)
call bml_print_matrix("rhos_bml",rhos_bml,0,10,0,10)

call bml_copy(rhos_bml,aux_bml)
call bml_add(aux_bml,rho_bml,1.0d0,-1.0d0,threshold)
write(*,*)"|DM_sp2-DM_diag|",bml_fnorm(aux_bml)

call bml_multiply(rhos_bml, rhos_bml, aux_bml, 0.5_dp, 0.0_dp, threshold)
call bml_print_matrix("rhos_bml^2",aux_bml,0,10,0,10)
call bml_add(aux_bml,rhos_bml,1.0d0,-1.0d0,threshold)
write(*,*)"|DM_sp2-DM_sp2^2|",bml_fnorm(aux_bml)

call bml_multiply(ham_bml,rhos_bml,aux_bml,1.0_dp,0.0_dp,threshold)
call bml_multiply(rhos_bml,ham_bml,aux_bml,1.0_dp,-1.0_dp,threshold)
write(*,*)"|DM_sp2*H-H*DM_sp2|",bml_fnorm(aux_bml)

call bml_write_matrix(ham_bml, "hamiltonian.mtx")

end program hmodel
12 changes: 12 additions & 0 deletions benchmarks/dmconstruction/input.in.metal
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
MHAM{
NOrbs= size
BMLType= format
EpsilonA= -0.0
EpsilonB= -0.0
DeltaAB= -0.0
DeltaAiAj= -1.0
DeltaBiBj= -1.0
Decay= -0.01
Seed= 100
Reshuffle= F
}
15 changes: 15 additions & 0 deletions benchmarks/dmconstruction/input.in.semicond
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
MHAM{
NOrbs= size
BMLType= format
EpsilonA= -0.0
EpsilonB= -0.0
DeltaAB= -2.0
DeltaAiAj= -0.0
DeltaBiBj= -1.0
Decay= -1000.0
RCoeff= 0.0
Seed= 100
Reshuffle= F
}


15 changes: 15 additions & 0 deletions benchmarks/dmconstruction/input.in.softmatt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
MHAM{
NOrbs= 1000
BMLType= Ellpack
EpsilonA= -10.0
EpsilonB= -0.0
DeltaAB= -1.0
DeltaAiAj= -0.0
DeltaBiBj= -1.0
Decay= -1.0
RCoeff= 1.0
Seed= 100
Reshuffle= F
}


31 changes: 31 additions & 0 deletions benchmarks/dmconstruction/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

#source vars !Sourcing environmental variables

export OMP_NUM_THREADS=12
run=../../build/dmconstruction

device="myCPU" #Architecture name
alg="sp2_alg1" #Name of the algorithm
tag="prg_sp2_alg1" #Tag for naming output files

for format in Ellpack CSR Ellblock Dense
do
for system in softmatt semicond metal
do
fileout="times_${system}_${alg}_${device}_${format}.dat"
rm $fileout
#for i in 1000 2000 4000 6000 8000 10000 12000 14000 16000 18000 20000
for i in 100 200 400
do
echo "Format, System, Size:" $format"," $system"," $i
sed 's/NOrbs=.*/NOrbs= '$i'/g' input.in.$system > tmp
sed 's/BMLType=.*/BMLType= '$format'/g' tmp > input.in
#jsrun -n1 -a1 -g1 -c21 -bpacked:21 ./main input.in > out$i$device$alg$format$system
$run input.in > out$i$device$alg$format$system
time=`grep $tag out$i$device$alg$format$system | awk 'NF>1{print $NF}'`
echo $i $time >> $fileout
done
done
done

0 comments on commit fc3cc68

Please sign in to comment.