Skip to content

Commit

Permalink
Merge pull request #103 from N-Medvedev/under_development
Browse files Browse the repository at this point in the history
OpenMP calls defined by preprocessor
  • Loading branch information
N-Medvedev authored Apr 25, 2024
2 parents 5051303 + 91e4b1f commit 0ad35b0
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 9 deletions.
13 changes: 10 additions & 3 deletions Source_files/Algebra_tools.f90
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
MODULE Algebra_tools
use Universal_constants

USE OMP_LIB, only : OMP_GET_THREAD_NUM
! For OpenMP external library
#ifdef OMP_inside
USE OMP_LIB, only : OMP_GET_THREAD_NUM
#endif

implicit none
PRIVATE
Expand Down Expand Up @@ -1100,7 +1103,9 @@ subroutine c8_diagonalize(M, Ev, Error_descript, print_Ei, check_M) ! double pre
M = M_work ! save processed matrix back into the output matrix
!!$OMP END WORKSHARE

print*, OMP_GET_THREAD_NUM(), 'Before check_M'
#ifdef OMP_inside
!print*, OMP_GET_THREAD_NUM(), 'Before check_M'
#endif

if (present(check_M)) then
if (check_M) then
Expand All @@ -1109,7 +1114,9 @@ subroutine c8_diagonalize(M, Ev, Error_descript, print_Ei, check_M) ! double pre
endif
endif

print*, OMP_GET_THREAD_NUM(), 'After check_M'
#ifdef OMP_inside
!print*, OMP_GET_THREAD_NUM(), 'After check_M'
#endif

! Clean up temporary arrays:
deallocate(M_save, M_work)
Expand Down
15 changes: 14 additions & 1 deletion Source_files/Optical_parameters.f90
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ MODULE Optical_parameters
use MC_cross_sections, only : Mean_free_path, velosity_from_kinetic_energy
use Nonadiabatic, only : get_Mij2, get_nonadiabatic_Pij

USE OMP_LIB, only : OMP_GET_THREAD_NUM
#ifdef OMP_inside
USE OMP_LIB, only : OMP_GET_THREAD_NUM
#endif

implicit none
PRIVATE
Expand Down Expand Up @@ -240,8 +242,13 @@ subroutine get_Kubo_Greenwood_all_complex(numpar, matter, Scell, NSC, all_w, Err

! k-points:
call k_point_choice(schem, ix, iy, iz, ixm, iym, izm, kx, ky, kz, numpar%k_grid) ! module "TB"

#ifdef OMP_inside
if (numpar%verbose) write(*,'(a,i4,a,i6,i3,i3,i3,f9.4,f9.4,f9.4,a)') 'Thread #', OMP_GET_THREAD_NUM(), &
' point #', Ngp, ix, iy, iz, kx, ky, kz, ' Kubo-Greenwood'
#else
if (numpar%verbose) write(*,'(a,i7,i3,i3,i3,f9.4,f9.4,f9.4,a)') ' point #', Ngp, ix, iy, iz, kx, ky, kz, ' Kubo-Greenwood'
#endif

! Get the effective momentum and kinetic-energy-related operators:
ASSOCIATE (ARRAY => Scell(NSC)%TB_Hamil(:,:))
Expand Down Expand Up @@ -1077,8 +1084,14 @@ subroutine get_Graf_Vogl_all_complex(numpar, Scell, NSC, all_w, Err) ! From Ref

! k-points:
call k_point_choice(schem, ix, iy, iz, ixm, iym, izm, kx, ky, kz, numpar%k_grid) ! module "TB"

#ifdef OMP_inside
if (numpar%verbose) write(*,'(a,i4,a,i7,i3,i3,i3,f9.4,f9.4,f9.4,a)') 'Thread #', OMP_GET_THREAD_NUM(), &
' point #', Ngp, ix, iy, iz, kx, ky, kz, ' Graf-Vogl'
#else
if (numpar%verbose) write(*,'(a,i7,i3,i3,i3,f9.4,f9.4,f9.4,a)') ' point #', Ngp, ix, iy, iz, kx, ky, kz, ' Graf-Vogl'
#endif


! Get the effective momentum and kinetic-energy-related operators:
ASSOCIATE (ARRAY => Scell(NSC)%TB_Hamil(:,:))
Expand Down
30 changes: 28 additions & 2 deletions Source_files/TB.f90
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ MODULE TB
use Exponential_wall, only : get_Exp_wall_s, d_Exp_wall_pot_s, d_Exp_wall_Pressure_s, &
get_short_range_rep_s, d_Short_range_pot_s, d_Short_range_Pressure_s

USE OMP_LIB, only : OMP_GET_THREAD_NUM

#ifdef OMP_inside
USE OMP_LIB, only : OMP_GET_THREAD_NUM
#endif

implicit none
PRIVATE
Expand Down Expand Up @@ -2606,7 +2607,11 @@ subroutine diagonalize_complex8_Hamiltonian(CHij, Ei, CSij, CHij_orth, CWF_orth)
integer :: Nsiz, j
character(200) :: Error_descript

#ifdef OMP_inside
print*, OMP_GET_THREAD_NUM(), 'diagonalize_complex8_Hamiltonian start'
#else
print*, 'diagonalize_complex8_Hamiltonian start'
#endif

Error_descript = '' ! to start with, no error
Nsiz = size(CHij,1)
Expand All @@ -2618,7 +2623,11 @@ subroutine diagonalize_complex8_Hamiltonian(CHij, Ei, CSij, CHij_orth, CWF_orth)

ORTH: if (.not.present(CSij)) then ! orthogonal:

#ifdef OMP_inside
print*, OMP_GET_THREAD_NUM(), 'diagonalize_complex8_Hamiltonian orthogonal'
#else
print*, 'diagonalize_complex8_Hamiltonian orthogonal'
#endif

! Direct diagonalization:
call sym_diagonalize(CHij, Ei, Error_descript) ! modeule "Algebra_tools"
Expand All @@ -2627,12 +2636,20 @@ subroutine diagonalize_complex8_Hamiltonian(CHij, Ei, CSij, CHij_orth, CWF_orth)
! 1) Orthogonalize the Hamiltonian using Loewdin procidure:
! according to [Szabo "Modern Quantum Chemistry" 1986, pp. 142-144]:

#ifdef OMP_inside
print*, OMP_GET_THREAD_NUM(), 'diagonalize_complex8_Hamiltonian nonorthogonal'
#else
print*, 'diagonalize_complex8_Hamiltonian nonorthogonal'
#endif

CHij_use = CHij
call Loewdin_Orthogonalization_c8(Nsiz, CSij, CHij_use) ! module "TB_NRL"

#ifdef OMP_inside
print*, OMP_GET_THREAD_NUM(), 'Loewdin_Orthogonalization_c8 done'
#else
print*, 'Loewdin_Orthogonalization_c8 done'
#endif

if (present(CHij_orth)) then ! Save orthogonalized Hamiltonian (for optical coefficients below)
CHij_orth = CHij_use
Expand All @@ -2650,15 +2667,24 @@ subroutine diagonalize_complex8_Hamiltonian(CHij, Ei, CSij, CHij_orth, CWF_orth)
CWF_orth = CHij_use
endif


#ifdef OMP_inside
print*, OMP_GET_THREAD_NUM(), 'sym_diagonalize done'
#else
print*, 'sym_diagonalize done'
#endif

! 3) Convert the eigenvectors back into the non-orthogonal basis:
!call mkl_matrix_mult('N', 'N', CSij, CHij_use, CHij) ! module "Algebra_tools"
allocate( CHij_temp(Nsiz,Nsiz), source = dcmplx( real(CHij), aimag(CHij)) )
call mkl_matrix_mult_c8('N', 'N', CSij, CHij_use, CHij_temp) ! module "Algebra_tools"
CHij = cmplx( real(CHij_temp), aimag(CHij_temp) ) ! convert to cmplx (important for unix-based compileres)

#ifdef OMP_inside
print*, OMP_GET_THREAD_NUM(), 'mkl_matrix_mult done'
#else
print*, 'mkl_matrix_mult done'
#endif
endif ORTH
end subroutine diagonalize_complex8_Hamiltonian

Expand Down
10 changes: 8 additions & 2 deletions Source_files/TB_NRL.f90
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ MODULE TB_NRL
use Atomic_tools, only : get_near_neighbours, get_number_of_image_cells, distance_to_given_cell, shortest_distance, Reciproc_rel_to_abs
use Electron_tools, only : find_band_gap

USE OMP_LIB, only : OMP_GET_THREAD_NUM
#ifdef OMP_inside
USE OMP_LIB, only : OMP_GET_THREAD_NUM
#endif

implicit none
PRIVATE
Expand Down Expand Up @@ -1139,7 +1141,11 @@ subroutine Loewdin_Orthogonalization_c8(Nsiz, Sij, Hij, Err) ! below
if (allocated(s_mat)) deallocate(s_mat)
if (allocated(Ev)) deallocate(Ev)

print*, OMP_GET_THREAD_NUM(), 'Loewdin_Orthogonalization_c8 done'
#ifdef OMP_inside
print*, OMP_GET_THREAD_NUM(), 'Loewdin_Orthogonalization_c8 done'
#else
print*, 'Loewdin_Orthogonalization_c8 done'
#endif
end subroutine Loewdin_Orthogonalization_c8


Expand Down
9 changes: 8 additions & 1 deletion Source_files/TB_complex.f90
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ MODULE TB_complex
use Electron_tools, only : get_DOS_sort
use Little_subroutines, only : Find_in_array_monoton, linear_interpolation

USE OMP_LIB, only : OMP_GET_THREAD_NUM
#ifdef OMP_inside
USE OMP_LIB, only : OMP_GET_THREAD_NUM
#endif

implicit none
PRIVATE
Expand Down Expand Up @@ -120,8 +122,13 @@ subroutine use_complex_Hamiltonian(numpar, matter, Scell, NSC, Err) ! From Ref.
!-------------------------------
! k-points:
call k_point_choice(schem, ix, iy, iz, ixm, iym, izm, kx, ky, kz, numpar%k_grid) ! module "TB"

#ifdef OMP_inside
if (numpar%verbose) write(*,'(a,i4,a,i6,i3,i3,i3,f9.4,f9.4,f9.4,a)') 'Thread #', OMP_GET_THREAD_NUM(), &
' point #', Ngp, ix, iy, iz, kx, ky, kz, ' k-points'
#else
if (numpar%verbose) write(*,'(a,i7,i3,i3,i3,f9.4,f9.4,f9.4,a)') ' point #', Ngp, ix, iy, iz, kx, ky, kz, ' k-points'
#endif

!-------------------------------
! Get the parameters of the complex Hamiltonian:
Expand Down

0 comments on commit 0ad35b0

Please sign in to comment.