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
22 use, intrinsic :: iso_fortran_env
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
36 public :: &
37 conf_t, &
39 global_end, &
42 assert_die, &
44 operator(+), &
45 bitand, &
46 int32, int64, &
47 real32, real64, &
48 i4_to_i8, &
50 ! Make these kind variables from kind_oct_m public here so that they are
51 ! available basically everywhere in the code. They still need to be in a
52 ! separate module because they are also needed in some low-level modules.
53
54 integer, public, parameter :: MAX_PATH_LEN=512
55 integer, public, parameter :: MAX_OUTPUT_TYPES=45
56
58 type conf_t
59 logical :: devel_version
60 logical :: report_memory
61 character(len=256) :: share = share_dir
62 character(len=256) :: build_dir = build_dir
63 character(len=256) :: git_commit = git_commit
64 character(len=50) :: config_time = build_time
65 character(len=20) :: version = package_version
66 character(len=256) :: cc = cc
67 character(len=256) :: cxx = cxx
68 character(len=256) :: fc = fc
69 ! Split flag definitions in case they don`t fit in one line, following preprocessing
70 character(len=256) :: cflags = &
71 cflags //&
72 cflags_extra
73 character(len=256) :: cxxflags = &
74 cxxflags //&
75 cxxflags_extra
76 character(len=512) :: fcflags = &
77 fcflags //&
78 fcflags_extra
79 integer :: target_states_block_size = -1
80 contains
81 procedure :: init => conf_init
82 end type conf_t
83
85 type(conf_t), public :: conf
86
87 real(real64), public, parameter :: R_SMALL = 1e-8_real64
88
90 real(real64), public, parameter :: R_MIN_ATOM_DIST = 1e-3_real64
91
93 real(real64), public, parameter :: M_Pi = 3.1415926535897932384626433832795029_real64
94 real(real64), public, parameter :: M_E = 2.7182818284590452353602874713526625_real64
95 real(real64), public, parameter :: M_ZERO = 0.0_real64
96 real(real64), public, parameter :: M_ONE = 1.0_real64
97 real(real64), public, parameter :: M_TWO = 2.0_real64
98 real(real64), public, parameter :: M_THREE = 3.0_real64
99 real(real64), public, parameter :: M_FOUR = 4.0_real64
100 real(real64), public, parameter :: M_FIVE = 5.0_real64
101 real(real64), public, parameter :: M_HALF = 0.5_real64
102 real(real64), public, parameter :: M_THIRD = m_one/m_three
103 real(real64), public, parameter :: M_TWOTHIRD = m_two/m_three
104 real(real64), public, parameter :: M_FOURTH = m_one/m_four
105 complex(real64), public, parameter :: M_z0 = (0.0_real64, 0.0_real64)
106 complex(real64), public, parameter :: M_z1 = (1.0_real64, 0.0_real64)
107 complex(real64), public, parameter :: M_z2 = (2.0_real64, 0.0_real64)
108 complex(real64), public, parameter :: M_z2I = (0.0_real64, 2.0_real64)
109 complex(real64), public, parameter :: M_zI = (0.0_real64, 1.0_real64)
110
111 real(real64), public, parameter :: M_EPSILON = epsilon(m_one)
112 real(real64), public, parameter :: M_TINY = tiny(m_one)
113 real(real64), public, parameter :: M_HUGE = huge(m_one)
114 real(real64), public, parameter :: M_MIN_EXP_ARG = -650_real64
115 real(real64), public, parameter :: M_MAX_EXP_ARG = 700_real64
118 real(real64), public, parameter :: M_MIN_OCC = 1.0e-10_real64
120 real(real64), public, parameter :: M_MIN_DENSITY = 1.0e-20_real64
122 real(real64), public, parameter :: M_DEGENERARY_THRESHOLD = 1.0e-6_real64
123
125 real(real64), public, parameter :: LMM_R_SINGLE_ATOM = 100.0_real64
126
128 real(real64), public, parameter :: P_a_B = 0.52917720859_real64
129 real(real64), public, parameter :: P_Ang = m_one / p_a_b
130 real(real64), public, parameter :: P_Ry = 13.60569193_real64
131 real(real64), public, parameter :: P_eV = m_one / p_ry
132 real(real64), public, parameter :: P_Kb = 8.617343e-5_real64/(m_two*p_ry)
133 real(real64), public, parameter :: P_c = 137.035999679_real64
134
135 real(real64), public, parameter :: P_g = 2.00231930436118_real64
136 real(real64), public, parameter :: P_PROTON_CHARGE = -1.0_real64
137 real(real64), public, parameter :: P_ep = m_one/(m_four*m_pi)
138 real(real64), public, parameter :: P_mu = m_four*m_pi/(p_c**2)
139
141 integer, public, parameter :: &
142 INDEPENDENT_PARTICLES = 2, &
143 hartree = 1, &
144 hartree_fock = 3, &
145 kohn_sham_dft = 4, &
147 rdmft = 7
148
150 integer, public :: stderr, stdin, stdout
151
153 integer, public :: s_epoch_sec, s_epoch_usec
156 character(len=80), public :: sub_stack(50)
157 real(real64), public :: time_stack(50)
158 integer, public :: no_sub_stack = 0
161 logical, public :: in_profiling_mode = .false.
163 integer, public :: global_alloc_err
164 integer(int64), public :: global_sizeof
165 character(len=100), public :: global_alloc_errmsg
166
167 ! The code directories should be defined here, and not hard coded in the Fortran files.
168 character(len=*), public, parameter :: gs_dir = "gs/"
169 character(len=*), public, parameter :: td_dir = "td/"
170 character(len=*), public, parameter :: static_dir = "static/"
171 character(len=*), public, parameter :: em_resp_dir = "em_resp/"
172 character(len=*), public, parameter :: em_resp_fd_dir = "em_resp_fd/"
173 character(len=*), public, parameter :: kdotp_dir = "kdotp/"
174 character(len=*), public, parameter :: vib_modes_dir = "vib_modes/"
175 character(len=*), public, parameter :: vdw_dir = "vdw/"
176 character(len=*), public, parameter :: casida_dir = "casida/"
177 character(len=*), public, parameter :: oct_dir = "opt-control/"
178 character(len=*), public, parameter :: pcm_dir = "pcm/"
179 character(len=*), public, parameter :: partition_dir = "partition/"
180 character(len=*), public, parameter :: iteration_dir = "iteration/"
181
184 type(mpi_comm), public, parameter :: serial_dummy_comm = mpi_comm_undefined
186 ! End of declaration of public objects.
187 ! ---------------------------------------------------------
192 end interface optional_default
196 interface
197 subroutine assert_die(s, f, l)
198 implicit none
199 character(len=*), intent(in) :: s, f
200 integer, intent(in) :: l
201 end subroutine assert_die
202 end interface
204 interface operator (+)
205 module procedure cat
206 end interface operator (+)
208 interface bitand
209 module procedure bitand48
210 module procedure bitand84
211 module procedure bitand88
212 module procedure bitand44
213 end interface bitand
214
215 interface i4_to_i8
216 module procedure i4_to_i8_0, i4_to_i8_1
217 end interface i4_to_i8
218
219 interface i8_to_i4
220 module procedure i8_to_i4_0, i8_to_i4_1
221 end interface i8_to_i4
222
223contains
226 subroutine conf_init(this)
227 class(conf_t), intent(inout) :: this
229 character(len=MAX_PATH_LEN) :: share
230 character(len=MAX_PATH_LEN) :: path_exe, dir_exe
232 ! First, get the environment variable OCTOPUS_SHARE that overrides the default
233 call loct_getenv("OCTOPUS_SHARE", share)
234 if (trim(share) /= "") then
235 this%share = trim(share)
236 return
237 end if
238 ! Second, try a share directory next to the binary; this makes it work in the build tree
239 call loct_executable_path(path_exe)
240 if (trim(path_exe) /= "") then
241 ! we got a useable path, search for the share folder
242 call loct_dirname(path_exe, dir_exe)
243 share = trim(dir_exe) // "/share"
244 if (loct_dir_exists(share)) then
245 this%share = trim(share)
246 return
247 end if
248 end if
249 ! Third, take the value from the configuration step, check if it exists
250 if (.not.loct_dir_exists(conf%share)) then
251 write(*, "(A)") "Error: could not find share directory."
252 write(*, "(A, A)") "Configured location: ", trim(conf%share)
253 stop
254 end if
255
256 end subroutine conf_init
257
264 subroutine global_init(communicator)
265 type(mpi_comm), intent(in), optional :: communicator
267 type(mpi_comm) :: comm
269 if (present(communicator)) then
270 comm = communicator
271 else
272 call mpi_init_comm(comm)
273 endif
276
277 ! Order of call is important. mpi_world is used implicitly by blacs_init
278 call blacs_init()
280 end subroutine global_init
281
282
293 subroutine init_octopus_globals(comm)
294 type(mpi_comm), intent(in) :: comm
295
296 call mpi_grp_init(mpi_world, comm)
297
298 call mpi_world%barrier()
299 ! Get epoch time at node startup, just after the barrier to synchronize nodes first.
300 call loct_gettimeofday(s_epoch_sec, s_epoch_usec)
301
302 ! These defaults are initialised here because the Intel 2022a compiler complains:
303 ! "This array or function or substring is invalid in constant expressions"
304 ! This is not a problem with Intel 2023a, and so can be returned to hardware.F90
305 ! once Intel 2022a support is dropped
306 default_l1 = cache_t( 32*1024, 64)
307 default_l2 = cache_t(4096*1024, 64)
308
309 ! TODO(Alex) Issue 1013. Change hardware class to a free function, and make cache_t instance global.
311
312 call conf%init()
313
314 ! initialize info for the input variables
315 call varinfo_init(trim(conf%share)//'/varinfo')
316
317 end subroutine init_octopus_globals
318
319
321 subroutine global_end()
322
323 call varinfo_end()
324 call mpi_mod_end()
325
326 end subroutine global_end
327
328
329 real(real64) pure function doptional_default(opt, def) result(val)
330 real(real64), optional, intent(in) :: opt
331 real(real64), intent(in) :: def
332
333 val = def
334 if (present(opt)) val = opt
335 end function doptional_default
336
337 !----------------------------------------------------------
338
339 complex(real64) pure function zoptional_default(opt, def) result(val)
340 complex(real64), optional, intent(in) :: opt
341 complex(real64), intent(in) :: def
342
343 val = def
344 if (present(opt)) val = opt
345 end function zoptional_default
346
347 !----------------------------------------------------------
348
349 integer pure function ioptional_default(opt, def) result(val)
350 integer, optional, intent(in) :: opt
351 integer, intent(in) :: def
352
353 val = def
354 if (present(opt)) val = opt
355 end function ioptional_default
356
357 !----------------------------------------------------------
358
359 integer(int64) pure function loptional_default(opt, def) result(val)
360 integer(int64), optional, intent(in) :: opt
361 integer(int64), intent(in) :: def
362
363 val = def
364 if (present(opt)) val = opt
365 end function loptional_default
366
367 !----------------------------------------------------------
368
369 logical pure function looptional_default(opt, def) result(val)
370 logical, optional, intent(in) :: opt
371 logical, intent(in) :: def
372
373 val = def
374 if (present(opt)) val = opt
375 end function looptional_default
376
377 !----------------------------------------------------------
378
379 character(len=80) pure function soptional_default(opt, def) result(val)
380 character(len=*), optional, intent(in) :: opt
381 character(len=*), intent(in) :: def
382
383 val = def
384 if (present(opt)) val = opt
385 end function soptional_default
386
387 !-----------------------------------------------------------
389 logical &
390#ifndef have_openmp
391 pure &
392#endif
393 function not_in_openmp()
394
395#ifdef HAVE_OPENMP
396 not_in_openmp = .not. omp_in_parallel()
397#else
399#endif
400
401 end function not_in_openmp
402
403 !-----------------------------------------------------------
404
405 function cat(str1, str2)
406 character(len=*), intent(in) :: str1
407 character(len=*), intent(in) :: str2
408
409 character(len=len(str1) + len(str2)) :: cat
410 cat = str1//str2
411
412 end function cat
413
414 ! -----------------------------------------------------------
415
416 integer(int64) pure function bitand48(val1, val2)
417 integer(int32), intent(in) :: val1
418 integer(int64), intent(in) :: val2
419
420 bitand48 = iand(int(val1, int64), val2)
421
422 end function bitand48
423
424 ! -----------------------------------------------------------
425
426 integer(int64) pure function bitand84(val1, val2)
427 integer(int64), intent(in) :: val1
428 integer(int32), intent(in) :: val2
429
430 bitand84 = iand(val1, int(val2, int64))
431
432 end function bitand84
433
434 ! -----------------------------------------------------------
435
436 integer(int64) pure function bitand88(val1, val2)
437 integer(int64), intent(in) :: val1
438 integer(int64), intent(in) :: val2
439
440 bitand88 = iand(val1, val2)
441
442 end function bitand88
443
444 ! -----------------------------------------------------------
445
446 integer(int32) pure function bitand44(val1, val2)
447 integer(int32), intent(in) :: val1
448 integer(int32), intent(in) :: val2
449
450 bitand44 = iand(val1, val2)
451
452 end function bitand44
453
454 ! -----------------------------------------------------------
455
456 integer(int64) pure function i4_to_i8_0(ii)
457 integer(int32), intent(in) :: ii
458
459 i4_to_i8_0 = int(ii, int64)
460 end function i4_to_i8_0
461
462 ! -----------------------------------------------------------
463
464 integer(int32) pure function i8_to_i4_0(ii)
465 integer(int64), intent(in) :: ii
466
467 i8_to_i4_0 = int(ii, int32)
468 end function i8_to_i4_0
469
470 ! -----------------------------------------------------------
471
472 pure function i4_to_i8_1(ii)
473 integer(int32), intent(in) :: ii(:)
474 integer(int64) :: i4_to_i8_1(lbound(ii, 1, kind=int64):ubound(ii, 1, kind=int64))
475
476 i4_to_i8_1 = int(ii, int64)
477 end function i4_to_i8_1
478
479 ! -----------------------------------------------------------
480
481 pure function i8_to_i4_1(ii)
482 integer(int64), intent(in) :: ii(:)
483 integer(int32) :: i8_to_i4_1(lbound(ii, 1, kind=int64):ubound(ii, 1, kind=int64))
485 i8_to_i4_1 = int(ii, int32)
486 end function i8_to_i4_1
487end module global_oct_m
488
489!! Local Variables:
490!! mode: f90
491!! coding: utf-8
492!! End:
This function is defined in messages.F90.
Definition: global.F90:292
character(len= *), parameter, public em_resp_fd_dir
Definition: global.F90:267
integer(int32) pure function bitand44(val1, val2)
Definition: global.F90:542
subroutine, public global_end()
Finalise parser varinfo file, and MPI.
Definition: global.F90:417
pure integer(int32) function, dimension(lbound(ii, 1, kind=int64):ubound(ii, 1, kind=int64)) i8_to_i4_1(ii)
Definition: global.F90:577
character(len= *), parameter, public gs_dir
Definition: global.F90:263
integer(int64) pure function bitand88(val1, val2)
Definition: global.F90:532
integer(int64) pure function i4_to_i8_0(ii)
Definition: global.F90:552
character(len= *), parameter, public iteration_dir
Definition: global.F90:275
integer pure function ioptional_default(opt, def)
Definition: global.F90:445
integer, public no_sub_stack
Definition: global.F90:253
character(len= *), parameter, public casida_dir
Definition: global.F90:271
integer, parameter, public rdmft
Definition: global.F90:236
integer(int64), public global_sizeof
Definition: global.F90:259
character(len= *), parameter, public pcm_dir
Definition: global.F90:273
integer(int64) pure function bitand84(val1, val2)
Definition: global.F90:522
integer, parameter, public hartree_fock
Definition: global.F90:236
character(len= *), parameter, public vib_modes_dir
Definition: global.F90:269
character(len= *), parameter, public partition_dir
Definition: global.F90:274
integer(int64) pure function loptional_default(opt, def)
Definition: global.F90:455
character(len= *), parameter, public kdotp_dir
Definition: global.F90:268
character(len=len(str1)+len(str2)) function cat(str1, str2)
Definition: global.F90:501
type(mpi_comm), parameter, public serial_dummy_comm
Alias MPI_COMM_UNDEFINED for the specific use case of initialising Octopus utilities with no MPI supp...
Definition: global.F90:279
subroutine, public init_octopus_globals(comm)
Initialise Octopus-specific global constants and files. This routine performs no initialisation calls...
Definition: global.F90:389
real(real64), dimension(50), public time_stack
Definition: global.F90:252
logical pure function, public not_in_openmp()
Definition: global.F90:489
real(real64) pure function doptional_default(opt, def)
Definition: global.F90:425
logical pure function looptional_default(opt, def)
Definition: global.F90:465
integer, parameter, public generalized_kohn_sham_dft
Definition: global.F90:236
integer, parameter, public kohn_sham_dft
Definition: global.F90:236
integer(int32) pure function i8_to_i4_0(ii)
Definition: global.F90:560
character(len=80), dimension(50), public sub_stack
The stack.
Definition: global.F90:251
character(len= *), parameter, public em_resp_dir
Definition: global.F90:266
character(len=100), public global_alloc_errmsg
Definition: global.F90:260
logical, public in_profiling_mode
Same for profiling mode.
Definition: global.F90:256
integer, public global_alloc_err
Definition: global.F90:258
character(len=80) pure function soptional_default(opt, def)
Definition: global.F90:475
character(len= *), parameter, public td_dir
Definition: global.F90:264
pure integer(int64) function, dimension(lbound(ii, 1, kind=int64):ubound(ii, 1, kind=int64)) i4_to_i8_1(ii)
Definition: global.F90:568
character(len= *), parameter, public static_dir
Definition: global.F90:265
subroutine, public global_init(communicator)
Initialise Octopus.
Definition: global.F90:360
complex(real64) pure function zoptional_default(opt, def)
Definition: global.F90:435
subroutine conf_init(this)
Initialiser for conf_t.
Definition: global.F90:322
integer, parameter, public hartree
Definition: global.F90:236
character(len= *), parameter, public vdw_dir
Definition: global.F90:270
character(len= *), parameter, public oct_dir
Definition: global.F90:272
integer(int64) pure function bitand48(val1, val2)
Definition: global.F90:512
type(hardware_t), public cpu_hardware
Global instance of CPU hardware specification.
Definition: hardware.F90:61
type(cache_t), public default_l2
Definition: hardware.F90:65
type(cache_t), public default_l1
Defaults covers common chip specification for (l1, l2) cache.
Definition: hardware.F90:64
logical function, public loct_dir_exists(dirname)
Definition: loct.F90:335
subroutine blacs_init()
Initialize BLACS to enable use of SCALAPACK.
Definition: mpi.F90:295
type(mpi_comm), parameter, public mpi_comm_undefined
used to indicate a communicator has not been initialized
Definition: mpi.F90:138
type(mpi_grp_t), public mpi_world
Definition: mpi.F90:272
subroutine mpi_mod_end()
Finalize MPI, and optionally BLACS.
Definition: mpi.F90:301
subroutine mpi_grp_init(grp, comm)
Initialize MPI group instance.
Definition: mpi.F90:310
subroutine mpi_init_comm(comm)
Wrapper for MPI_COMM_WORLD initialisation.
Definition: mpi.F90:285
static double f(double w, void *p)
Build configuration type.
Definition: global.F90:153
int true(void)