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
26 use string_oct_m
28#ifdef HAVE_OPENMP
29 use omp_lib
30#endif
31
32 implicit none
33
34 private
35
37 public :: &
38 conf_t, &
40 global_end, &
43 assert_die, &
45 operator(+), &
46 bitand, &
47 int32, int64, &
48 real32, real64, &
49 i4_to_i8, &
51 ! Make these kind variables from kind_oct_m public here so that they are
52 ! available basically everywhere in the code. They still need to be in a
53 ! separate module because they are also needed in some low-level modules.
54
55 integer, public, parameter :: MAX_PATH_LEN=512
56 integer, public, parameter :: MAX_OUTPUT_TYPES=45
57
59 type conf_t
60 logical :: devel_version
61 logical :: report_memory
62 character(len=256) :: share = share_dir
63 character(len=256) :: build_dir = build_dir
64 character(len=256) :: git_commit = git_commit
65 character(len=50) :: config_time = build_time
66 character(len=20) :: version = package_version
67 character(len=256) :: cc = cc
68 character(len=256) :: cxx = cxx
69 character(len=256) :: fc = fc
70 ! Split flag definitions in case they don`t fit in one line, following preprocessing
71 character(len=256) :: cflags = &
72 cflags //&
73 cflags_extra
74 character(len=256) :: cxxflags = &
75 cxxflags //&
76 cxxflags_extra
77 character(len=512) :: fcflags = &
78 fcflags //&
79 fcflags_extra
80 integer :: target_states_block_size = -1
81 contains
82 procedure :: init => conf_init
83 end type conf_t
84
86 type(conf_t), public :: conf
87
88 real(real64), public, parameter :: R_SMALL = 1e-8_real64
89
91 real(real64), public, parameter :: R_MIN_ATOM_DIST = 1e-3_real64
92
94 real(real64), public, parameter :: M_Pi = 3.1415926535897932384626433832795029_real64
95 real(real64), public, parameter :: M_E = 2.7182818284590452353602874713526625_real64
96 real(real64), public, parameter :: M_ZERO = 0.0_real64
97 real(real64), public, parameter :: M_ONE = 1.0_real64
98 real(real64), public, parameter :: M_TWO = 2.0_real64
99 real(real64), public, parameter :: M_THREE = 3.0_real64
100 real(real64), public, parameter :: M_FOUR = 4.0_real64
101 real(real64), public, parameter :: M_FIVE = 5.0_real64
102 real(real64), public, parameter :: M_HALF = 0.5_real64
103 real(real64), public, parameter :: M_THIRD = m_one/m_three
104 real(real64), public, parameter :: M_TWOTHIRD = m_two/m_three
105 real(real64), public, parameter :: M_FOURTH = m_one/m_four
106 complex(real64), public, parameter :: M_z0 = (0.0_real64, 0.0_real64)
107 complex(real64), public, parameter :: M_z1 = (1.0_real64, 0.0_real64)
108 complex(real64), public, parameter :: M_z2 = (2.0_real64, 0.0_real64)
109 complex(real64), public, parameter :: M_z2I = (0.0_real64, 2.0_real64)
110 complex(real64), public, parameter :: M_zI = (0.0_real64, 1.0_real64)
111
112 real(real64), public, parameter :: M_EPSILON = epsilon(m_one)
113 real(real64), public, parameter :: M_TINY = tiny(m_one)
114 real(real64), public, parameter :: M_HUGE = huge(m_one)
115 real(real64), public, parameter :: M_MIN_EXP_ARG = -650_real64
116 real(real64), public, parameter :: M_MAX_EXP_ARG = 700_real64
117 real(real64), public, protected :: M_PINF
118 real(real64), public, protected :: M_NINF
119 real(real64), public, protected :: M_SNAN
120 real(real64), public, protected :: M_QNAN
121
123 real(real64), public, parameter :: M_MIN_OCC = 1.0e-10_real64
125 real(real64), public, parameter :: M_MIN_DENSITY = 1.0e-20_real64
127 real(real64), public, parameter :: M_DEGENERARY_THRESHOLD = 1.0e-6_real64
128
130 real(real64), public, parameter :: LMM_R_SINGLE_ATOM = 100.0_real64
131
133 real(real64), public, parameter :: P_a_B = 0.52917720859_real64
134 real(real64), public, parameter :: P_Ang = m_one / p_a_b
135 real(real64), public, parameter :: P_Ry = 13.60569193_real64
136 real(real64), public, parameter :: P_eV = m_one / p_ry
137 real(real64), public, parameter :: P_Kb = 8.617343e-5_real64/(m_two*p_ry)
138 real(real64), public, parameter :: P_c = 137.035999679_real64
139
140 real(real64), public, parameter :: P_g = 2.00231930436118_real64
141 real(real64), public, parameter :: P_PROTON_CHARGE = -1.0_real64
142 real(real64), public, parameter :: P_ep = m_one/(m_four*m_pi)
143 real(real64), public, parameter :: P_mu = m_four*m_pi/(p_c**2)
144
146 integer, public, parameter :: &
147 INDEPENDENT_PARTICLES = 2, &
148 hartree = 1, &
149 hartree_fock = 3, &
152 rdmft = 7
153
155 integer, public :: stderr, stdin, stdout
158 integer, public :: s_epoch_sec, s_epoch_usec
161 character(len=80), public :: sub_stack(50)
162 real(real64), public :: time_stack(50)
163 integer, public :: no_sub_stack = 0
166 logical, public :: in_profiling_mode = .false.
167
168 integer, public :: global_alloc_err
169 integer(int64), public :: global_sizeof
170 character(len=100), public :: global_alloc_errmsg
171
172 ! The code directories should be defined here, and not hard coded in the Fortran files.
173 character(len=*), public, parameter :: gs_dir = "gs/"
174 character(len=*), public, parameter :: td_dir = "td/"
175 character(len=*), public, parameter :: static_dir = "static/"
176 character(len=*), public, parameter :: em_resp_dir = "em_resp/"
177 character(len=*), public, parameter :: em_resp_fd_dir = "em_resp_fd/"
178 character(len=*), public, parameter :: kdotp_dir = "kdotp/"
179 character(len=*), public, parameter :: vib_modes_dir = "vib_modes/"
180 character(len=*), public, parameter :: vdw_dir = "vdw/"
181 character(len=*), public, parameter :: casida_dir = "casida/"
182 character(len=*), public, parameter :: oct_dir = "opt-control/"
183 character(len=*), public, parameter :: pcm_dir = "pcm/"
184 character(len=*), public, parameter :: partition_dir = "partition/"
185 character(len=*), public, parameter :: iteration_dir = "iteration/"
189 type(mpi_comm), public, parameter :: serial_dummy_comm = mpi_comm_undefined
191 ! End of declaration of public objects.
192 ! ---------------------------------------------------------
197 end interface optional_default
201 interface
202 subroutine assert_die(s, f, l)
203 implicit none
204 character(len=*), intent(in) :: s, f
205 integer, intent(in) :: l
206 end subroutine assert_die
207 end interface
209 interface operator (+)
210 module procedure cat
211 end interface operator (+)
213 interface bitand
214 module procedure bitand48
215 module procedure bitand84
216 module procedure bitand88
217 module procedure bitand44
218 end interface bitand
219
220 interface i4_to_i8
221 module procedure i4_to_i8_0, i4_to_i8_1
222 end interface i4_to_i8
223
224 interface i8_to_i4
225 module procedure i8_to_i4_0, i8_to_i4_1
226 end interface i8_to_i4
227
228contains
231 subroutine conf_init(this)
232 class(conf_t), intent(inout) :: this
234 character(len=MAX_PATH_LEN) :: share
235 character(len=MAX_PATH_LEN) :: path_exe, dir_exe
237 ! First, get the environment variable OCTOPUS_SHARE that overrides the default
238 call loct_getenv("OCTOPUS_SHARE", share)
239 if (trim(share) /= "") then
240 this%share = trim(share)
241 return
242 end if
243 ! Second, try a share directory next to the binary; this makes it work in the build tree
244 call loct_executable_path(path_exe)
245 if (trim(path_exe) /= "") then
246 ! we got a useable path, search for the share folder
247 call loct_dirname(path_exe, dir_exe)
248 share = trim(dir_exe) // "/share"
249 if (loct_dir_exists(share)) then
250 this%share = trim(share)
251 return
252 end if
253 end if
254 ! Third, take the value from the configuration step, check if it exists
255 if (.not.loct_dir_exists(conf%share)) then
256 write(*, "(A)") "Error: could not find share directory."
257 write(*, "(A, A)") "Configured location: ", trim(conf%share)
258 stop
259 end if
260
261 end subroutine conf_init
262
269 subroutine global_init(communicator)
270 type(mpi_comm), intent(in), optional :: communicator
272 type(mpi_comm) :: comm
274 if (present(communicator)) then
275 comm = communicator
277 else
278 call mpi_init_comm(comm)
279 endif
281 call init_octopus_globals(comm)
282
283 ! Order of call is important. mpi_world is used implicitly by blacs_init
285
286 end subroutine global_init
287
288
300 subroutine init_octopus_globals(comm)
301 type(mpi_comm), intent(in) :: comm
302
303 character(len=256) :: path
305 call mpi_grp_init(mpi_world, comm)
306
307 call mpi_world%barrier()
308 ! Get epoch time at node startup, just after the barrier to synchronize nodes first.
310
311 ! These defaults are initialised here because the Intel 2022a compiler complains:
312 ! "This array or function or substring is invalid in constant expressions"
313 ! This is not a problem with Intel 2023a, and so can be returned to hardware.F90
314 ! once Intel 2022a support is dropped
315 default_l1 = cache_t( 32*1024, 64)
316 default_l2 = cache_t(4096*1024, 64)
317
318 ! TODO(Alex) Issue 1013. Change hardware class to a free function, and make cache_t instance global.
320
321 call conf%init()
322
323 ! initialize info for the input variables
324 path = trim(conf%share)//'/varinfo'
325 call varinfo_init(string_f_to_c(path))
327 block
328 use, intrinsic :: ieee_arithmetic, only: &
329 ieee_negative_inf, &
330 ieee_positive_inf, &
331 ieee_quiet_nan, &
332 ieee_signaling_nan, &
333 ieee_support_inf, &
334 ieee_support_nan, &
335 ieee_value
336 if (ieee_support_inf(m_pinf)) then
337 m_pinf = ieee_value(m_pinf, ieee_positive_inf)
338 else
339 m_pinf = huge(m_pinf)
340 end if
341 if (ieee_support_inf(m_ninf)) then
342 m_ninf = ieee_value(m_ninf, ieee_negative_inf)
343 else
344 m_ninf = -huge(m_ninf)
345 end if
346 if (ieee_support_nan(m_qnan)) then
347 m_qnan = ieee_value(m_qnan, ieee_quiet_nan)
348 else
349 m_qnan = real(0.0, kind(m_qnan))
350 end if
351 if (ieee_support_nan(m_snan)) then
352 m_snan = ieee_value(m_snan, ieee_signaling_nan)
353 else
354 m_snan = real(0.0, kind(m_snan))
355 end if
356 end block
357
358 end subroutine init_octopus_globals
359
360
362 subroutine global_end()
363
364 call varinfo_end()
365 call mpi_mod_end()
366
367 end subroutine global_end
368
369
370 real(real64) pure function doptional_default(opt, def) result(val)
371 real(real64), optional, intent(in) :: opt
372 real(real64), intent(in) :: def
373
374 val = def
375 if (present(opt)) val = opt
376 end function doptional_default
377
378 !----------------------------------------------------------
379
380 complex(real64) pure function zoptional_default(opt, def) result(val)
381 complex(real64), optional, intent(in) :: opt
382 complex(real64), intent(in) :: def
383
384 val = def
385 if (present(opt)) val = opt
386 end function zoptional_default
387
388 !----------------------------------------------------------
389
390 integer pure function ioptional_default(opt, def) result(val)
391 integer, optional, intent(in) :: opt
392 integer, intent(in) :: def
393
394 val = def
395 if (present(opt)) val = opt
396 end function ioptional_default
397
398 !----------------------------------------------------------
399
400 integer(int64) pure function loptional_default(opt, def) result(val)
401 integer(int64), optional, intent(in) :: opt
402 integer(int64), intent(in) :: def
403
404 val = def
405 if (present(opt)) val = opt
406 end function loptional_default
407
408 !----------------------------------------------------------
409
410 logical pure function looptional_default(opt, def) result(val)
411 logical, optional, intent(in) :: opt
412 logical, intent(in) :: def
413
414 val = def
415 if (present(opt)) val = opt
416 end function looptional_default
417
418 !----------------------------------------------------------
419
420 character(len=80) pure function soptional_default(opt, def) result(val)
421 character(len=*), optional, intent(in) :: opt
422 character(len=*), intent(in) :: def
423
424 val = def
425 if (present(opt)) val = opt
426 end function soptional_default
427
428 !-----------------------------------------------------------
429
430 logical &
431#ifndef have_openmp
432 pure &
433#endif
434 function not_in_openmp()
435
436#ifdef HAVE_OPENMP
437 not_in_openmp = .not. omp_in_parallel()
438#else
440#endif
441
442 end function not_in_openmp
443
444 !-----------------------------------------------------------
445
446 function cat(str1, str2)
447 character(len=*), intent(in) :: str1
448 character(len=*), intent(in) :: str2
449
450 character(len=len(str1) + len(str2)) :: cat
451 cat = str1//str2
452
453 end function cat
454
455 ! -----------------------------------------------------------
456
457 integer(int64) pure function bitand48(val1, val2)
458 integer(int32), intent(in) :: val1
459 integer(int64), intent(in) :: val2
460
461 bitand48 = iand(int(val1, int64), val2)
462
463 end function bitand48
464
465 ! -----------------------------------------------------------
466
467 integer(int64) pure function bitand84(val1, val2)
468 integer(int64), intent(in) :: val1
469 integer(int32), intent(in) :: val2
470
471 bitand84 = iand(val1, int(val2, int64))
472
473 end function bitand84
474
475 ! -----------------------------------------------------------
476
477 integer(int64) pure function bitand88(val1, val2)
478 integer(int64), intent(in) :: val1
479 integer(int64), intent(in) :: val2
480
481 bitand88 = iand(val1, val2)
482
483 end function bitand88
484
485 ! -----------------------------------------------------------
486
487 integer(int32) pure function bitand44(val1, val2)
488 integer(int32), intent(in) :: val1
489 integer(int32), intent(in) :: val2
490
491 bitand44 = iand(val1, val2)
492
493 end function bitand44
494
495 ! -----------------------------------------------------------
496
497 integer(int64) pure function i4_to_i8_0(ii)
498 integer(int32), intent(in) :: ii
499
500 i4_to_i8_0 = int(ii, int64)
501 end function i4_to_i8_0
502
503 ! -----------------------------------------------------------
504
505 integer(int32) pure function i8_to_i4_0(ii)
506 integer(int64), intent(in) :: ii
507
508 i8_to_i4_0 = int(ii, int32)
509 end function i8_to_i4_0
510
511 ! -----------------------------------------------------------
512
513 pure function i4_to_i8_1(ii)
514 integer(int32), intent(in) :: ii(:)
515 integer(int64) :: i4_to_i8_1(lbound(ii, 1, kind=int64):ubound(ii, 1, kind=int64))
516
517 i4_to_i8_1 = int(ii, int64)
518 end function i4_to_i8_1
519
520 ! -----------------------------------------------------------
521
522 pure function i8_to_i4_1(ii)
523 integer(int64), intent(in) :: ii(:)
524 integer(int32) :: i8_to_i4_1(lbound(ii, 1, kind=int64):ubound(ii, 1, kind=int64))
526 i8_to_i4_1 = int(ii, int32)
527 end function i8_to_i4_1
528end module global_oct_m
529
530!! Local Variables:
531!! mode: f90
532!! coding: utf-8
533!! End:
This function is defined in messages.F90.
Definition: global.F90:297
character(len= *), parameter, public em_resp_fd_dir
Definition: global.F90:272
integer(int32) pure function bitand44(val1, val2)
Definition: global.F90:583
subroutine, public global_end()
Finalise parser varinfo file, and MPI.
Definition: global.F90:458
pure integer(int32) function, dimension(lbound(ii, 1, kind=int64):ubound(ii, 1, kind=int64)) i8_to_i4_1(ii)
Definition: global.F90:618
character(len= *), parameter, public gs_dir
Definition: global.F90:268
integer(int64) pure function bitand88(val1, val2)
Definition: global.F90:573
integer(int64) pure function i4_to_i8_0(ii)
Definition: global.F90:593
character(len= *), parameter, public iteration_dir
Definition: global.F90:280
integer, public s_epoch_sec
global epoch time (time at startup)
Definition: global.F90:253
integer pure function ioptional_default(opt, def)
Definition: global.F90:486
integer, public no_sub_stack
Definition: global.F90:258
character(len= *), parameter, public casida_dir
Definition: global.F90:276
integer, parameter, public rdmft
Definition: global.F90:241
integer(int64), public global_sizeof
Definition: global.F90:264
character(len= *), parameter, public pcm_dir
Definition: global.F90:278
integer(int64) pure function bitand84(val1, val2)
Definition: global.F90:563
integer, parameter, public hartree_fock
Definition: global.F90:241
character(len= *), parameter, public vib_modes_dir
Definition: global.F90:274
character(len= *), parameter, public partition_dir
Definition: global.F90:279
integer(int64) pure function loptional_default(opt, def)
Definition: global.F90:496
character(len= *), parameter, public kdotp_dir
Definition: global.F90:273
character(len=len(str1)+len(str2)) function cat(str1, str2)
Definition: global.F90:542
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:284
subroutine, public init_octopus_globals(comm)
Initialise Octopus-specific global constants and files. This routine performs no initialisation calls...
Definition: global.F90:396
real(real64), dimension(50), public time_stack
Definition: global.F90:257
logical pure function, public not_in_openmp()
Definition: global.F90:530
real(real64) pure function doptional_default(opt, def)
Definition: global.F90:466
logical pure function looptional_default(opt, def)
Definition: global.F90:506
integer, parameter, public generalized_kohn_sham_dft
Definition: global.F90:241
integer, parameter, public kohn_sham_dft
Definition: global.F90:241
integer(int32) pure function i8_to_i4_0(ii)
Definition: global.F90:601
character(len=80), dimension(50), public sub_stack
The stack.
Definition: global.F90:256
integer, public s_epoch_usec
Definition: global.F90:253
character(len= *), parameter, public em_resp_dir
Definition: global.F90:271
character(len=100), public global_alloc_errmsg
Definition: global.F90:265
logical, public in_profiling_mode
Same for profiling mode.
Definition: global.F90:261
integer, public global_alloc_err
Definition: global.F90:263
character(len=80) pure function soptional_default(opt, def)
Definition: global.F90:516
character(len= *), parameter, public td_dir
Definition: global.F90:269
pure integer(int64) function, dimension(lbound(ii, 1, kind=int64):ubound(ii, 1, kind=int64)) i4_to_i8_1(ii)
Definition: global.F90:609
character(len= *), parameter, public static_dir
Definition: global.F90:270
subroutine, public global_init(communicator)
Initialise Octopus.
Definition: global.F90:365
complex(real64) pure function zoptional_default(opt, def)
Definition: global.F90:476
subroutine conf_init(this)
Initialiser for conf_t.
Definition: global.F90:327
integer, parameter, public hartree
Definition: global.F90:241
character(len= *), parameter, public vdw_dir
Definition: global.F90:275
character(len= *), parameter, public oct_dir
Definition: global.F90:277
integer(int64) pure function bitand48(val1, val2)
Definition: global.F90:553
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
System information (time, memory, sysname)
Definition: loct.F90:117
subroutine, public loct_getenv(var, val)
Definition: loct.F90:364
subroutine, public loct_dirname(path, dir)
Definition: loct.F90:442
logical function, public loct_dir_exists(dirname)
Definition: loct.F90:349
character(kind=c_char, len=1) function, dimension(len_trim(f_string)+1), private string_f_to_c(f_string)
convert a Fortran string to a C string
Definition: loct.F90:240
subroutine, public loct_executable_path(fpath)
Definition: loct.F90:425
subroutine blacs_init()
Initialize BLACS to enable use of SCALAPACK.
Definition: mpi.F90:316
subroutine check_threading_support(comm)
Check that the threading support of the MPI library is consistent with the requested support from Oct...
Definition: mpi.F90:306
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_grp_init(grp, comm)
Initialize MPI group instance.
Definition: mpi.F90:341
subroutine mpi_init_comm(comm)
Wrapper for MPI_COMM_WORLD initialisation.
Definition: mpi.F90:295
static double f(double w, void *p)
Build configuration type.
Definition: global.F90:154
int true(void)