MPI-SCATCI  2.0
An MPI version of SCATCI
Utility_module.f90
Go to the documentation of this file.
1 ! Copyright 2019
2 !
3 ! For a comprehensive list of the developers that contributed to these codes
4 ! see the UK-AMOR website.
5 !
6 ! This file is part of UKRmol-in (UKRmol+ suite).
7 !
8 ! UKRmol-in is free software: you can redistribute it and/or modify
9 ! it under the terms of the GNU General Public License as published by
10 ! the Free Software Foundation, either version 3 of the License, or
11 ! (at your option) any later version.
12 !
13 ! UKRmol-in is distributed in the hope that it will be useful,
14 ! but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ! GNU General Public License for more details.
17 !
18 ! You should have received a copy of the GNU General Public License
19 ! along with UKRmol-in (in source/COPYING). Alternatively, you can also visit
20 ! <https://www.gnu.org/licenses/>.
21 
29 
30  use precisn, only: longint, wp
31  use mpi_gbl, only: mpi_mod_wtime
32 
33  implicit none
34 
37 
38 contains
39 
46  integer(longint) function compute_total_triangular (n)
47  integer, intent(in) :: n
48 
49  compute_total_triangular = n * (n + 1_longint) / 2
50 
51  end function compute_total_triangular
52 
53 
60  integer function compute_total_box (width, height)
61  integer, intent(in) :: width, height
62 
63  compute_total_box = width * height
64 
65  end function compute_total_box
66 
67 
72  subroutine box_index_to_ij (idx, height, i, j)
73  integer, intent(in) :: idx, height
74  integer, intent(out) :: i, j
75 
76  i = mod(idx - 1, height) + 1
77  j = (idx - 1) / height + 1
78 
79  end subroutine box_index_to_ij
80 
81 
86  subroutine triangular_index_to_ij (idx_f, N, row, column)
87  integer, intent(in) :: idx_f, n
88  integer, intent(out) :: row, column
89  integer :: idx, ii, k, jj
90 
91  idx = idx_f - 1
92  ii = n * (n + 1) / 2 - 1 - idx
93  k = int((sqrt(8.0_wp*real(ii,wp) + 1.0_wp) - 1.0_wp) / 2.0_wp, longint)
94  jj = ii - k * (k + 1) / 2
95 
96  row = n - 1 - k
97  column = n - 1 - jj
98 
99  end subroutine triangular_index_to_ij
100 
101 
109  integer function string_hash (str, table_size) result(h)
110  character(len=*), intent(in) :: str
111  integer, intent(in) :: table_size
112  integer :: i, chr, g, mask = int(z"1FFFFFF")
113 
114  h = 0
115  do i = 1, len_trim(str)
116  chr = ichar(str(i:i))
117  h = ishft(h, 4) + chr
118  g = ishft(h,-24)
119  h = iand(ieor(h,g), mask)
120  end do
121  h = 1 + modulo(h, table_size)
122 
123  end function string_hash
124 
125 
132  function get_real_time () result(t)
133  real(wp) :: t
134 
135  t = mpi_mod_wtime()
136 
137  end function get_real_time
138 
139 
144  function get_cpu_time () result(t)
145  real(wp) :: t
146 
147  call cpu_time(t)
148 
149  end function get_cpu_time
150 
151 end module utility_module
utility_module::box_index_to_ij
subroutine, public box_index_to_ij(idx, height, i, j)
Extract indices from rectangular multi-index.
Definition: Utility_module.f90:73
utility_module::compute_total_triangular
integer(longint) function, public compute_total_triangular(n)
Calculate triangular area.
Definition: Utility_module.f90:47
utility_module
Utility module.
Definition: Utility_module.f90:28
utility_module::get_real_time
real(wp) function, public get_real_time()
Get current (real) time.
Definition: Utility_module.f90:133
utility_module::string_hash
integer function, public string_hash(str, table_size)
Calculate a string hash.
Definition: Utility_module.f90:110
utility_module::compute_total_box
integer function, public compute_total_box(width, height)
Calculate rectangular product.
Definition: Utility_module.f90:61
utility_module::get_cpu_time
real(wp) function, public get_cpu_time()
Get current (CPU) time.
Definition: Utility_module.f90:145
utility_module::triangular_index_to_ij
subroutine, public triangular_index_to_ij(idx_f, N, row, column)
Extract indices from triangular multi-index.
Definition: Utility_module.f90:87