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=44
56
58 type conf_t
59 logical :: devel_version
60 logical :: report_memory
61 character(len=256) :: share = share_dir
62 character(len=256) :: git_commit = git_commit
63 character(len=50) :: config_time = build_time
64 character(len=20) :: version = package_version
65 character(len=256) :: cc = cc
66 character(len=256) :: cxx = cxx
67 character(len=256) :: fc = fc
68 ! Split flag definitions in case they don`t fit in one line, following preprocessing
69 character(len=256) :: cflags = &
70 cflags //&
71 cflags_extra
72 character(len=256) :: cxxflags = &
73 cxxflags //&
74 cxxflags_extra
75 character(len=256) :: fcflags = &
76 fcflags //&
77 fcflags_extra
78 integer :: target_states_block_size = -1
79 contains
80 procedure :: init => conf_init
81 end type conf_t
82
84 type(conf_t), public :: conf
85
86 real(real64), public, parameter :: R_SMALL = 1e-8_real64
87
89 real(real64), public, parameter :: R_MIN_ATOM_DIST = 1e-3_real64
90
92 real(real64), public, parameter :: M_Pi = 3.1415926535897932384626433832795029_real64
93 real(real64), public, parameter :: M_E = 2.7182818284590452353602874713526625_real64
94 real(real64), public, parameter :: M_ZERO = 0.0_real64
95 real(real64), public, parameter :: M_ONE = 1.0_real64
96 real(real64), public, parameter :: M_TWO = 2.0_real64
97 real(real64), public, parameter :: M_THREE = 3.0_real64
98 real(real64), public, parameter :: M_FOUR = 4.0_real64
99 real(real64), public, parameter :: M_FIVE = 5.0_real64
100 real(real64), public, parameter :: M_HALF = 0.5_real64
101 real(real64), public, parameter :: M_THIRD = m_one/m_three
102 real(real64), public, parameter :: M_TWOTHIRD = m_two/m_three
103 real(real64), public, parameter :: M_FOURTH = m_one/m_four
104 complex(real64), public, parameter :: M_z0 = (0.0_real64, 0.0_real64)
105 complex(real64), public, parameter :: M_z1 = (1.0_real64, 0.0_real64)
106 complex(real64), public, parameter :: M_z2 = (2.0_real64, 0.0_real64)
107 complex(real64), public, parameter :: M_z2I = (0.0_real64, 2.0_real64)
108 complex(real64), public, parameter :: M_zI = (0.0_real64, 1.0_real64)
109
110 real(real64), public, parameter :: M_EPSILON = epsilon(m_one)
111 real(real64), public, parameter :: M_TINY = tiny(m_one)
112 real(real64), public, parameter :: M_HUGE = huge(m_one)
113 real(real64), public, parameter :: M_MIN_EXP_ARG = -650_real64
114 real(real64), public, parameter :: M_MAX_EXP_ARG = 700_real64
115
117 real(real64), public, parameter :: M_MIN_OCC = 1.0e-10_real64
119 real(real64), public, parameter :: M_MIN_DENSITY = 1.0e-20_real64
120
122 real(real64), public, parameter :: LMM_R_SINGLE_ATOM = 100.0_real64
123
125 real(real64), public, parameter :: P_a_B = 0.52917720859_real64
126 real(real64), public, parameter :: P_Ang = m_one / p_a_b
127 real(real64), public, parameter :: P_Ry = 13.60569193_real64
128 real(real64), public, parameter :: P_eV = m_one / p_ry
129 real(real64), public, parameter :: P_Kb = 8.617343e-5_real64/(m_two*p_ry)
130 real(real64), public, parameter :: P_c = 137.035999679_real64
131
132 real(real64), public, parameter :: P_g = 2.00231930436118_real64
133 real(real64), public, parameter :: P_PROTON_CHARGE = -1.0_real64
134 real(real64), public, parameter :: P_ep = m_one/(m_four*m_pi)
135 real(real64), public, parameter :: P_mu = m_four*m_pi/(p_c**2)
136
138 integer, public :: stderr, stdin, stdout
139
141 integer, public :: s_epoch_sec, s_epoch_usec
142
144 character(len=80), public :: sub_stack(50)
145 real(real64), public :: time_stack(50)
146 integer, public :: no_sub_stack = 0
149 logical, public :: in_profiling_mode = .false.
150
151 integer, public :: global_alloc_err
152 integer(int64), public :: global_sizeof
153 character(len=100), public :: global_alloc_errmsg
155 ! The code directories should be defined here, and not hard coded in the Fortran files.
156 character(len=*), public, parameter :: gs_dir = "gs/"
157 character(len=*), public, parameter :: td_dir = "td/"
158 character(len=*), public, parameter :: static_dir = "static/"
159 character(len=*), public, parameter :: em_resp_dir = "em_resp/"
160 character(len=*), public, parameter :: em_resp_fd_dir = "em_resp_fd/"
161 character(len=*), public, parameter :: kdotp_dir = "kdotp/"
162 character(len=*), public, parameter :: vib_modes_dir = "vib_modes/"
163 character(len=*), public, parameter :: vdw_dir = "vdw/"
164 character(len=*), public, parameter :: casida_dir = "casida/"
165 character(len=*), public, parameter :: oct_dir = "opt-control/"
166 character(len=*), public, parameter :: pcm_dir = "pcm/"
167 character(len=*), public, parameter :: partition_dir = "partition/"
171 type(mpi_comm), public, parameter :: serial_dummy_comm = mpi_comm_undefined
172
173 ! End of declaration of public objects.
174 ! ---------------------------------------------------------
175
176 interface optional_default
178 module procedure looptional_default, soptional_default
179 end interface optional_default
180
181
183 interface
184 subroutine assert_die(s, f, l)
185 implicit none
186 character(len=*), intent(in) :: s, f
187 integer, intent(in) :: l
188 end subroutine assert_die
189 end interface
191 interface operator (+)
192 module procedure cat
193 end interface operator (+)
195 interface bitand
196 module procedure bitand48
197 module procedure bitand84
198 module procedure bitand88
199 module procedure bitand44
200 end interface bitand
202 interface i4_to_i8
203 module procedure i4_to_i8_0, i4_to_i8_1
204 end interface i4_to_i8
206 interface i8_to_i4
207 module procedure i8_to_i4_0, i8_to_i4_1
208 end interface i8_to_i4
209
210contains
211
213 subroutine conf_init(this)
214 class(conf_t), intent(inout) :: this
216 character(len=256) :: share
217
218 ! Get the environment variable OCTOPUS_SHARE that overrides the default
219 call loct_getenv("OCTOPUS_SHARE", share)
220 if (share /= "") this%share = trim(share)
222 end subroutine conf_init
224
230 subroutine global_init(communicator)
231 type(mpi_comm), intent(in), optional :: communicator
232
233 type(mpi_comm) :: comm
235 if (present(communicator)) then
236 comm = communicator
237 else
238 call mpi_init_comm(comm)
239 endif
240
241 call init_octopus_globals(comm)
243 ! Order of call is important. mpi_world is used implicitly by blacs_init
246 end subroutine global_init
247
248
259 subroutine init_octopus_globals(comm)
260 type(mpi_comm), intent(in) :: comm
261
262 call mpi_grp_init(mpi_world, comm)
263
264 call mpi_world%barrier()
265 ! Get epoch time at node startup, just after the barrier to synchronize nodes first.
266 call loct_gettimeofday(s_epoch_sec, s_epoch_usec)
267
268 ! These defaults are initialised here because the Intel 2022a compiler complains:
269 ! "This array or function or substring is invalid in constant expressions"
270 ! This is not a problem with Intel 2023a, and so can be returned to hardware.F90
271 ! once Intel 2022a support is dropped
272 default_l1 = cache_t( 32*1024, 64)
273 default_l2 = cache_t(4096*1024, 64)
274
275 ! TODO(Alex) Issue 1013. Change hardware class to a free function, and make cache_t instance global.
278 call conf%init()
279
280 ! initialize info for the input variables
281 call varinfo_init(trim(conf%share)//'/varinfo')
282
283 end subroutine init_octopus_globals
285
287 subroutine global_end()
289 call varinfo_end()
290 call mpi_mod_end()
291
292 end subroutine global_end
293
294
295 real(real64) pure function doptional_default(opt, def) result(val)
296 real(real64), optional, intent(in) :: opt
297 real(real64), intent(in) :: def
298
299 val = def
300 if (present(opt)) val = opt
301 end function doptional_default
302
303 !----------------------------------------------------------
304
305 complex(real64) pure function zoptional_default(opt, def) result(val)
306 complex(real64), optional, intent(in) :: opt
307 complex(real64), intent(in) :: def
308
309 val = def
310 if (present(opt)) val = opt
311 end function zoptional_default
312
313 !----------------------------------------------------------
314
315 integer pure function ioptional_default(opt, def) result(val)
316 integer, optional, intent(in) :: opt
317 integer, intent(in) :: def
318
319 val = def
320 if (present(opt)) val = opt
321 end function ioptional_default
322
323 !----------------------------------------------------------
324
325 integer(int64) pure function loptional_default(opt, def) result(val)
326 integer(int64), optional, intent(in) :: opt
327 integer(int64), intent(in) :: def
328
329 val = def
330 if (present(opt)) val = opt
331 end function loptional_default
332
333 !----------------------------------------------------------
334
335 logical pure function looptional_default(opt, def) result(val)
336 logical, optional, intent(in) :: opt
337 logical, intent(in) :: def
338
339 val = def
340 if (present(opt)) val = opt
341 end function looptional_default
342
343 !----------------------------------------------------------
344
345 character(len=80) pure function soptional_default(opt, def) result(val)
346 character(len=*), optional, intent(in) :: opt
347 character(len=*), intent(in) :: def
348
349 val = def
350 if (present(opt)) val = opt
351 end function soptional_default
353 !-----------------------------------------------------------
354
355 logical &
356#ifndef have_openmp
357 pure &
358#endif
359 function not_in_openmp()
360
361#ifdef HAVE_OPENMP
362 not_in_openmp = .not. omp_in_parallel()
363#else
365#endif
366
367 end function not_in_openmp
368
369 !-----------------------------------------------------------
370
371 function cat(str1, str2)
372 character(len=*), intent(in) :: str1
373 character(len=*), intent(in) :: str2
374
375 character(len=len(str1) + len(str2)) :: cat
376 cat = str1//str2
377
378 end function cat
379
380 ! -----------------------------------------------------------
381
382 integer(int64) pure function bitand48(val1, val2)
383 integer(int32), intent(in) :: val1
384 integer(int64), intent(in) :: val2
385
386 bitand48 = iand(int(val1, int64), val2)
387
388 end function bitand48
389
390 ! -----------------------------------------------------------
391
392 integer(int64) pure function bitand84(val1, val2)
393 integer(int64), intent(in) :: val1
394 integer(int32), intent(in) :: val2
395
396 bitand84 = iand(val1, int(val2, int64))
397
398 end function bitand84
399
400 ! -----------------------------------------------------------
401
402 integer(int64) pure function bitand88(val1, val2)
403 integer(int64), intent(in) :: val1
404 integer(int64), intent(in) :: val2
405
406 bitand88 = iand(val1, val2)
407
408 end function bitand88
409
410 ! -----------------------------------------------------------
411
412 integer(int32) pure function bitand44(val1, val2)
413 integer(int32), intent(in) :: val1
414 integer(int32), intent(in) :: val2
415
416 bitand44 = iand(val1, val2)
417
418 end function bitand44
419
420 ! -----------------------------------------------------------
421
422 integer(int64) pure function i4_to_i8_0(ii)
423 integer(int32), intent(in) :: ii
424
425 i4_to_i8_0 = int(ii, int64)
426 end function i4_to_i8_0
427
428 ! -----------------------------------------------------------
429
430 integer(int32) pure function i8_to_i4_0(ii)
431 integer(int64), intent(in) :: ii
432
433 i8_to_i4_0 = int(ii, int32)
434 end function i8_to_i4_0
435
436 ! -----------------------------------------------------------
437
438 pure function i4_to_i8_1(ii)
439 integer(int32), intent(in) :: ii(:)
440 integer(int64) :: i4_to_i8_1(lbound(ii, 1, kind=int64):ubound(ii, 1, kind=int64))
441
442 i4_to_i8_1 = int(ii, int64)
443 end function i4_to_i8_1
444
445 ! -----------------------------------------------------------
446
447 pure function i8_to_i4_1(ii)
448 integer(int64), intent(in) :: ii(:)
449 integer(int32) :: i8_to_i4_1(lbound(ii, 1, kind=int64):ubound(ii, 1, kind=int64))
450
451 i8_to_i4_1 = int(ii, int32)
452 end function i8_to_i4_1
453end module global_oct_m
454
455!! Local Variables:
456!! mode: f90
457!! coding: utf-8
458!! End:
This function is defined in messages.F90.
Definition: global.F90:277
character(len= *), parameter, public em_resp_fd_dir
Definition: global.F90:253
integer(int32) pure function bitand44(val1, val2)
Definition: global.F90:506
subroutine, public global_end()
Finalise parser varinfo file, and MPI.
Definition: global.F90:381
pure integer(int32) function, dimension(lbound(ii, 1, kind=int64):ubound(ii, 1, kind=int64)) i8_to_i4_1(ii)
Definition: global.F90:541
character(len= *), parameter, public gs_dir
Definition: global.F90:249
integer(int64) pure function bitand88(val1, val2)
Definition: global.F90:496
integer(int64) pure function i4_to_i8_0(ii)
Definition: global.F90:516
integer pure function ioptional_default(opt, def)
Definition: global.F90:409
character(len= *), parameter, public casida_dir
Definition: global.F90:257
integer(int64), public global_sizeof
Definition: global.F90:245
character(len= *), parameter, public pcm_dir
Definition: global.F90:259
integer(int64) pure function bitand84(val1, val2)
Definition: global.F90:486
character(len= *), parameter, public vib_modes_dir
Definition: global.F90:255
character(len= *), parameter, public partition_dir
Definition: global.F90:260
integer(int64) pure function loptional_default(opt, def)
Definition: global.F90:419
character(len= *), parameter, public kdotp_dir
Definition: global.F90:254
character(len=len(str1)+len(str2)) function cat(str1, str2)
Definition: global.F90:465
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:264
subroutine, public init_octopus_globals(comm)
Initialise Octopus-specific global constants and files. This routine performs no initialisation calls...
Definition: global.F90:353
logical pure function, public not_in_openmp()
Definition: global.F90:453
real(real64) pure function doptional_default(opt, def)
Definition: global.F90:389
logical pure function looptional_default(opt, def)
Definition: global.F90:429
integer(int32) pure function i8_to_i4_0(ii)
Definition: global.F90:524
character(len= *), parameter, public em_resp_dir
Definition: global.F90:252
character(len=100), public global_alloc_errmsg
Definition: global.F90:246
logical, public in_profiling_mode
Same for profiling mode.
Definition: global.F90:242
character(len=80) pure function soptional_default(opt, def)
Definition: global.F90:439
character(len= *), parameter, public td_dir
Definition: global.F90:250
pure integer(int64) function, dimension(lbound(ii, 1, kind=int64):ubound(ii, 1, kind=int64)) i4_to_i8_1(ii)
Definition: global.F90:532
character(len= *), parameter, public static_dir
Definition: global.F90:251
subroutine, public global_init(communicator)
Initialise Octopus.
Definition: global.F90:324
complex(real64) pure function zoptional_default(opt, def)
Definition: global.F90:399
subroutine conf_init(this)
Initialiser for conf_t.
Definition: global.F90:307
character(len= *), parameter, public vdw_dir
Definition: global.F90:256
character(len= *), parameter, public oct_dir
Definition: global.F90:258
integer(int64) pure function bitand48(val1, val2)
Definition: global.F90:476
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
subroutine blacs_init()
Initialize BLACS to enable use of SCALAPACK.
Definition: mpi.F90:301
type(mpi_comm), parameter, public mpi_comm_undefined
used to indicate a communicator has not been initialized
Definition: mpi.F90:136
type(mpi_grp_t), public mpi_world
Definition: mpi.F90:266
subroutine mpi_mod_end()
Finalize MPI, and optionally BLACS.
Definition: mpi.F90:328
subroutine mpi_grp_init(grp, comm)
Initialize MPI group instance.
Definition: mpi.F90:346
subroutine mpi_init_comm(comm)
Wrapper for MPI_COMM_WORLD initialisation.
Definition: mpi.F90:282
Build configuration type.
Definition: global.F90:151
int true(void)