Octopus
global.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
21module global_oct_m
23 use kind_oct_m
24 use loct_oct_m
25 use mpi_oct_m
27#ifdef HAVE_OPENMP
28 use omp_lib
29#endif
30
31 implicit none
32
33 private
34
35 ! ---------------------------------------------------------
37 public :: &
38 conf_t, &
40 global_end, &
42 assert_die, &
44 operator(+), &
45 bitand, &
46 i4, i8, r4, r8, &
47 i4_to_i8, &
49 ! Make these kind variables from kind_oct_m public here so that they are
50 ! available basically everywhere in the code. They still need to be in a
51 ! separate module because they are also needed in hardware_oct_m and some
52 ! other low-level modules.
53
54
55 integer, public, parameter :: MAX_PATH_LEN=512
56 integer, public, parameter :: MAX_OUTPUT_TYPES=43
57
58 type conf_t
59 ! Components are public by default
60 logical :: devel_version
61 logical :: report_memory
62 character(len=256) :: share
63 character(len=256) :: git_commit
64 character(len=50) :: config_time
65 character(len=20) :: version
66 character(len=256) :: cc
67 character(len=256) :: cflags
68 character(len=256) :: cxx
69 character(len=256) :: cxxflags
70 character(len=256) :: fc
71 character(len=256) :: fcflags
72 integer :: target_states_block_size
73 end type conf_t
74
75 type(conf_t), public :: conf
76
77 float, public, parameter :: r_small = cnst(1e-8)
78
80 float, public, parameter :: r_min_atom_dist = cnst(1e-3)
81
83 float, public, parameter :: m_pi = cnst(3.1415926535897932384626433832795029)
84 float, public, parameter :: m_e = cnst(2.7182818284590452353602874713526625)
85 float, public, parameter :: m_zero = cnst(0.0)
86 float, public, parameter :: m_one = cnst(1.0)
87 float, public, parameter :: m_two = cnst(2.0)
88 float, public, parameter :: m_three = cnst(3.0)
89 float, public, parameter :: m_four = cnst(4.0)
90 float, public, parameter :: m_five = cnst(5.0)
91 float, public, parameter :: m_half = cnst(0.5)
92 float, public, parameter :: m_third = m_one/m_three
93 float, public, parameter :: m_twothird = m_two/m_three
94 float, public, parameter :: m_fourth = m_one/m_four
95 cmplx, public, parameter :: m_z0 = (cnst(0.0), cnst(0.0))
96 cmplx, public, parameter :: m_z1 = (cnst(1.0), cnst(0.0))
97 cmplx, public, parameter :: m_z2 = (cnst(2.0), cnst(0.0))
98 cmplx, public, parameter :: m_z2i = (cnst(0.0), cnst(2.0))
99 cmplx, public, parameter :: m_zi = (cnst(0.0), cnst(1.0))
100
101 float, public, parameter :: m_epsilon = epsilon(m_one)
102 float, public, parameter :: m_tiny = tiny(m_one)
103 float, public, parameter :: m_huge = huge(m_one)
104 float, public, parameter :: m_min_exp_arg = cnst(-650)
105 float, public, parameter :: m_max_exp_arg = cnst(700)
107
109 float, public, parameter :: p_a_b = cnst(0.52917720859)
110 float, public, parameter :: p_ang = m_one / p_a_b
111 float, public, parameter :: p_ry = cnst(13.60569193)
112 float, public, parameter :: p_ev = m_one / p_ry
113 float, public, parameter :: p_kb = cnst(8.617343e-5)/(m_two*p_ry)
114 float, public, parameter :: p_c = cnst(137.035999679)
115 float, public, parameter :: p_g = cnst(2.0023193043768)
116 float, public, parameter :: p_proton_charge = cnst(-1.0)
117 float, public, parameter :: p_ep = m_one/(m_four*m_pi)
118 float, public, parameter :: p_mu = m_four*m_pi/(p_c**2)
119
121 integer, public :: stderr, stdin, stdout
122
124 integer, public :: s_epoch_sec, s_epoch_usec
125
127 character(len=80), public :: sub_stack(50)
128 float, public :: time_stack(50)
129 integer, public :: no_sub_stack = 0
130
132 logical, public :: in_profiling_mode = .false.
133
134 integer, public :: global_alloc_err
135 integer(i8), public :: global_sizeof
136 character(len=100), public :: global_alloc_errmsg
137
138 ! The code directories should be defined here, and not hard coded in the Fortran files.
139 character(len=*), public, parameter :: GS_DIR = "gs/"
140 character(len=*), public, parameter :: td_dir = "td/"
141 character(len=*), public, parameter :: static_dir = "static/"
142 character(len=*), public, parameter :: em_resp_dir = "em_resp/"
143 character(len=*), public, parameter :: EM_RESP_FD_DIR = "em_resp_fd/"
144 character(len=*), public, parameter :: KDOTP_DIR = "kdotp/"
145 character(len=*), public, parameter :: vib_modes_dir = "vib_modes/"
146 character(len=*), public, parameter :: vdw_dir = "vdw/"
147 character(len=*), public, parameter :: casida_dir = "casida/"
148 character(len=*), public, parameter :: oct_dir = "opt-control/"
149 character(len=*), public, parameter :: pcm_dir = "pcm/"
150 character(len=*), public, parameter :: partition_dir = "partition/"
152 ! End of declaration of public objects.
153 ! ---------------------------------------------------------
158 end interface optional_default
159
162 interface
163 subroutine assert_die(s, f, l)
164 implicit none
165 character(len=*), intent(in) :: s, f
166 integer, intent(in) :: l
167 end subroutine assert_die
168 end interface
170 interface operator (+)
171 module procedure cat
172 end interface operator (+)
174 interface bitand
175 module procedure bitand48
176 module procedure bitand84
177 module procedure bitand88
178 module procedure bitand44
179 end interface bitand
181 interface i4_to_i8
182 module procedure i4_to_i8_0, i4_to_i8_1
183 end interface i4_to_i8
185 interface i8_to_i4
186 module procedure i8_to_i4_0, i8_to_i4_1
187 end interface i8_to_i4
189contains
191 ! ---------------------------------------------------------
192 subroutine global_init(is_serial)
193 logical, optional, intent(in) :: is_serial
195 character(len=256) :: share
197 ! initialize mpi
198 call mpi_mod_init(optional_default(is_serial, .false.))
200 ! Get epoch time at node startup, just after the barrier to synchronize nodes first.
201 call loct_gettimeofday(s_epoch_sec, s_epoch_usec)
204
205 ! Get the environment variable OCTOPUS_SHARE that overrides SHARE_DIR/share/octopus.
206 call loct_getenv("OCTOPUS_SHARE", share)
207
208 if (share /= "") then
209 conf%share = trim(share)
210 else
211 conf%share = share_dir
212 end if
213 conf%git_commit = git_commit
214 conf%config_time = build_time
215 conf%version = package_version
216 conf%cc = cc
217 ! split to have all flags in case they don`t fit in one line
218 conf%cflags = &
219 cflags //&
220 cflags_extra
221 conf%cxx = cxx
222 conf%cxxflags = &
223 cxxflags //&
224 cxxflags_extra
225 conf%fc = fc
226 conf%fcflags = &
227 fcflags //&
228 fcflags_extra
230 ! initialize info for the input variables
231 call varinfo_init(trim(conf%share)//'/varinfo')
233 conf%target_states_block_size = -1
235 end subroutine global_init
236
237
238 ! ---------------------------------------------------------
239 subroutine global_end()
241 call hardware_end()
242 call mpi_mod_end()
243 call varinfo_end()
244
245 end subroutine global_end
246
247 !----------------------------------------------------------
249 float pure function doptional_default(opt, def) result(val)
250 float, optional, intent(in) :: opt
251 float, intent(in) :: def
252
253 val = def
254 if (present(opt)) val = opt
255 end function doptional_default
256
257 !----------------------------------------------------------
258
259 cmplx pure function zoptional_default(opt, def) result(val)
260 cmplx, optional, intent(in) :: opt
261 cmplx, intent(in) :: def
262
263 val = def
264 if (present(opt)) val = opt
265 end function zoptional_default
267 !----------------------------------------------------------
268
269 integer pure function ioptional_default(opt, def) result(val)
270 integer, optional, intent(in) :: opt
271 integer, intent(in) :: def
272
273 val = def
274 if (present(opt)) val = opt
275 end function ioptional_default
276
277 !----------------------------------------------------------
278
279 integer(i8) pure function loptional_default(opt, def) result(val)
280 integer(i8), optional, intent(in) :: opt
281 integer(i8), intent(in) :: def
282
283 val = def
284 if (present(opt)) val = opt
285 end function loptional_default
286
287 !----------------------------------------------------------
288
289 logical pure function looptional_default(opt, def) result(val)
290 logical, optional, intent(in) :: opt
291 logical, intent(in) :: def
292
293 val = def
294 if (present(opt)) val = opt
295 end function looptional_default
296
297 !----------------------------------------------------------
298
299 character(len=80) pure function soptional_default(opt, def) result(val)
300 character(len=*), optional, intent(in) :: opt
301 character(len=*), intent(in) :: def
302
303 val = def
304 if (present(opt)) val = opt
305 end function soptional_default
306
307 !-----------------------------------------------------------
308
309 logical &
310#ifndef have_openmp
311 pure &
312#endif
313 function not_in_openmp()
314
315#ifdef HAVE_OPENMP
316 not_in_openmp = .not. omp_in_parallel()
317#else
319#endif
320
321 end function not_in_openmp
322
323 !-----------------------------------------------------------
325 function cat(str1, str2)
326 character(len=*), intent(in) :: str1
327 character(len=*), intent(in) :: str2
328
329 character(len=len(str1) + len(str2)) :: cat
330 cat = str1//str2
331
332 end function cat
333
334 ! -----------------------------------------------------------
335
336 integer(i8) pure function bitand48(val1, val2)
337 integer(i4), intent(in) :: val1
338 integer(i8), intent(in) :: val2
339
340 bitand48 = iand(int(val1, 8), val2)
341
342 end function bitand48
343
344 ! -----------------------------------------------------------
345
346 integer(i8) pure function bitand84(val1, val2)
347 integer(i8), intent(in) :: val1
348 integer(i4), intent(in) :: val2
349
350 bitand84 = iand(val1, int(val2, 8))
351
352 end function bitand84
353
354 ! -----------------------------------------------------------
355
356 integer(i8) pure function bitand88(val1, val2)
357 integer(i8), intent(in) :: val1
358 integer(i8), intent(in) :: val2
359
360 bitand88 = iand(val1, val2)
361
362 end function bitand88
363
364 ! -----------------------------------------------------------
365
366 integer(i4) pure function bitand44(val1, val2)
367 integer(i4), intent(in) :: val1
368 integer(i4), intent(in) :: val2
369
370 bitand44 = iand(val1, val2)
371
372 end function bitand44
373
374 ! -----------------------------------------------------------
375
376 integer(i8) pure function i4_to_i8_0(ii)
377 integer(i4), intent(in) :: ii
378
379 i4_to_i8_0 = int(ii, i8)
380 end function i4_to_i8_0
381
382 ! -----------------------------------------------------------
383
384 integer(i4) pure function i8_to_i4_0(ii)
385 integer(i8), intent(in) :: ii
386
387 i8_to_i4_0 = int(ii, i4)
388 end function i8_to_i4_0
389
390 ! -----------------------------------------------------------
391
392 pure function i4_to_i8_1(ii)
393 integer(i4), intent(in) :: ii(:)
394 integer(i8) :: i4_to_i8_1(lbound(ii, 1, kind=i8):ubound(ii, 1, kind=i8))
395
396 i4_to_i8_1 = int(ii, i8)
397 end function i4_to_i8_1
398
399 ! -----------------------------------------------------------
400
401 pure function i8_to_i4_1(ii)
402 integer(i8), intent(in) :: ii(:)
403 integer(i4) :: i8_to_i4_1(lbound(ii, 1, kind=i8):ubound(ii, 1, kind=i8))
404
405 i8_to_i4_1 = int(ii, i4)
406 end function i8_to_i4_1
407end module global_oct_m
408
409!! Local Variables:
410!! mode: f90
411!! coding: utf-8
412!! End:
This function is defined in messages.F90.
Definition: global.F90:248
real(8), parameter, public m_five
Definition: global.F90:175
integer(i8) pure function i4_to_i8_0(ii)
Definition: global.F90:462
complex(8), parameter, public m_z2i
Definition: global.F90:183
real(8), parameter, public m_e
Definition: global.F90:169
subroutine, public global_end()
Definition: global.F90:325
integer(i4) pure function i8_to_i4_0(ii)
Definition: global.F90:470
real(8), parameter, public m_pi
some mathematical constants
Definition: global.F90:168
real(8), parameter, public m_twothird
Definition: global.F90:178
complex(8), parameter, public m_z1
Definition: global.F90:181
real(8), parameter, public m_two
Definition: global.F90:172
integer pure function ioptional_default(opt, def)
Definition: global.F90:355
real(8), parameter, public p_ang
Definition: global.F90:195
integer(i8) pure function loptional_default(opt, def)
Definition: global.F90:365
character(len= *), parameter, public casida_dir
Definition: global.F90:232
real(8), parameter, public r_small
Definition: global.F90:162
character(len= *), parameter, public pcm_dir
Definition: global.F90:234
real(8), parameter, public p_c
Definition: global.F90:199
real(8), parameter, public m_fourth
Definition: global.F90:179
pure integer(i8) function, dimension(lbound(ii, 1, kind=i8):ubound(ii, 1, kind=i8)) i4_to_i8_1(ii)
Definition: global.F90:478
real(8), parameter, public m_one
Definition: global.F90:171
real(8), parameter, public p_a_b
some physical constants
Definition: global.F90:194
character(len= *), parameter, public vib_modes_dir
Definition: global.F90:230
real(8), parameter, public m_min_exp_arg
Definition: global.F90:189
character(len= *), parameter, public partition_dir
Definition: global.F90:235
character(len=len(str1)+len(str2)) function cat(str1, str2)
Definition: global.F90:411
real(8), parameter, public m_huge
Definition: global.F90:188
real(8), parameter, public p_mu
Definition: global.F90:203
real(8) pure function doptional_default(opt, def)
Definition: global.F90:335
pure integer(i4) function, dimension(lbound(ii, 1, kind=i8):ubound(ii, 1, kind=i8)) i8_to_i4_1(ii)
Definition: global.F90:487
complex(8), parameter, public m_z0
Definition: global.F90:180
complex(8), parameter, public m_zi
Definition: global.F90:184
logical pure function looptional_default(opt, def)
Definition: global.F90:375
real(8), parameter, public p_ep
Definition: global.F90:202
complex(8) pure function zoptional_default(opt, def)
Definition: global.F90:345
logical function, public not_in_openmp()
Definition: global.F90:399
real(8), parameter, public p_g
Electron gyromagnetic ratio.
Definition: global.F90:200
real(8), parameter, public m_max_exp_arg
Definition: global.F90:190
real(8), parameter, public p_ev
Definition: global.F90:197
character(len= *), parameter, public em_resp_dir
Definition: global.F90:227
integer(i8) pure function bitand84(val1, val2)
Definition: global.F90:432
integer(i8) pure function bitand48(val1, val2)
Definition: global.F90:422
subroutine, public global_init(is_serial)
Definition: global.F90:278
real(8), parameter, public m_tiny
Definition: global.F90:187
real(8), parameter, public p_kb
Boltzmann constant in Ha/K.
Definition: global.F90:198
real(8), parameter, public m_zero
Definition: global.F90:170
real(8), parameter, public m_half
Definition: global.F90:176
character(len=80) pure function soptional_default(opt, def)
Definition: global.F90:385
integer(i8) pure function bitand88(val1, val2)
Definition: global.F90:442
character(len= *), parameter, public td_dir
Definition: global.F90:225
character(len= *), parameter, public static_dir
Definition: global.F90:226
complex(8), parameter, public m_z2
Definition: global.F90:182
real(8), parameter, public p_proton_charge
Definition: global.F90:201
real(8), parameter, public m_four
Definition: global.F90:174
real(8), parameter, public m_third
Definition: global.F90:177
real(8), parameter, public r_min_atom_dist
Minimal distance between two distinguishable atoms.
Definition: global.F90:165
real(8), parameter, public m_epsilon
Definition: global.F90:186
real(8), parameter, public m_three
Definition: global.F90:173
integer(i4) pure function bitand44(val1, val2)
Definition: global.F90:452
real(8), parameter, public p_ry
Definition: global.F90:196
character(len= *), parameter, public vdw_dir
Definition: global.F90:231
character(len= *), parameter, public oct_dir
Definition: global.F90:233
real(8), dimension(50), public time_stack
Definition: global.F90:213
subroutine, public hardware_end
Definition: hardware.F90:159
subroutine, public hardware_init
Definition: hardware.F90:136
integer, parameter i4
define kinds
Definition: kind.F90:31
integer, parameter r4
Definition: kind.F90:33
integer, parameter i8
Definition: kind.F90:32
integer, parameter r8
Definition: kind.F90:34
subroutine mpi_mod_end()
Definition: mpi.F90:313
subroutine mpi_mod_init(is_serial)
Definition: mpi.F90:256
int true(void)