18 USE iso_c_binding,
ONLY: c_char, &
23 USE iso_fortran_env,
ONLY: error_unit, &
26 USE omp_lib,
ONLY: omp_get_wtime
32 USE libxs,
ONLY: libxs_timer_tick, libxs_timer_duration, libxs_cpuid, &
33 libxs_target_arch_generic, libxs_x86_sse42, libxs_x86_avx, libxs_x86_avx2, &
34 libxs_x86_avx512, libxs_aarch64, libxs_aarch64_sve128, &
35 libxs_aarch64_sve256, libxs_aarch64_sve512, &
52#include "machine_cpuid.h"
59 INTEGER,
PUBLIC,
PARAMETER :: &
126 INTEGER,
INTENT(IN) :: lunit
146 wt = libxs_timer_duration(0_int_8, libxs_timer_tick())
157 CHARACTER(LEN=default_string_length),
INTENT(OUT) :: model_name
159 INTEGER,
PARAMETER :: bufferlen = 2048
161 CHARACTER(LEN=bufferlen) :: buffer
162 INTEGER :: i, icol, iline, stat
164 model_name =
"UNKNOWN"
166 OPEN (121245, file=
"/proc/cpuinfo", action=
"READ", status=
"OLD", access=
"STREAM", iostat=stat)
169 READ (121245,
END=999) buffer(I:I)
172 i = index(buffer,
"model name")
174 icol = i - 1 + index(buffer(i:),
":")
175 iline = icol - 1 + index(buffer(icol:), new_line(
'A'))
176 IF (iline == icol - 1) iline = bufferlen + 1
177 model_name = buffer(icol + 1:iline - 1)
197 archid = libxs_cpuid(c_null_ptr)
198 IF (libxs_x86_sse42 <= archid .AND. archid < libxs_x86_avx)
THEN
200 ELSE IF (libxs_x86_avx <= archid .AND. archid < libxs_x86_avx2)
THEN
202 ELSE IF (libxs_x86_avx2 <= archid .AND. archid < libxs_x86_avx512)
THEN
204 ELSE IF (libxs_x86_avx512 <= archid .AND. archid <= 1999)
THEN
209 IF (libxs_aarch64 <= archid .AND. archid < libxs_aarch64_sve128)
THEN
211 ELSE IF (libxs_aarch64_sve128 <= archid .AND. archid < libxs_aarch64_sve256)
THEN
213 ELSE IF (libxs_aarch64_sve256 <= archid .AND. archid < libxs_aarch64_sve512)
THEN
215 ELSE IF (libxs_aarch64_sve512 <= archid .AND. archid <= 2999)
THEN
235 INTEGER,
INTENT(IN),
OPTIONAL :: cpuid
240 IF (
PRESENT(cpuid))
THEN
279 INTEGER,
INTENT(IN),
OPTIONAL :: cpuid, typesize
282 INTEGER :: isa, nbytes
284 IF (
PRESENT(typesize))
THEN
290 IF (0 < nbytes .AND. nbytes <= 16)
THEN
291 IF (
PRESENT(cpuid))
THEN
333#if defined(__CRAY_PM_ENERGY)
334 wt = read_energy(
"/sys/cray/pm_counters/energy")
335#elif defined(__CRAY_PM_ACCEL_ENERGY)
336 wt = read_energy(
"/sys/cray/pm_counters/accel_energy")
343#if defined(__CRAY_PM_ACCEL_ENERGY) || defined(__CRAY_PM_ENERGY)
351 FUNCTION read_energy(filename)
RESULT(wt)
352 CHARACTER(LEN=*) :: filename
355 CHARACTER(LEN=80) :: data
357 INTEGER(KIND=int_8) :: raw
359 OPEN (121245, file=filename, action=
"READ", status=
"OLD", access=
"STREAM")
361 READ (121245,
END=999) DATA(I:I)
365 READ (
DATA, *, iostat=iostat) raw
366 IF (iostat /= 0)
THEN
372 END FUNCTION read_energy
383 CHARACTER(len=timestamp_length),
INTENT(OUT) :: timestamp
385 CHARACTER(len=10) :: time
386 CHARACTER(len=8) :: date
388 CALL date_and_time(date=date, time=time)
389 timestamp = date(1:4)//
"-"//date(5:6)//
"-"//date(7:8)//
" "// &
390 time(1:2)//
":"//time(3:4)//
":"//time(5:10)
399 SUBROUTINE abort()
BIND(C, name="abort")
413 INTEGER,
INTENT(IN) :: pid
418 FUNCTION kill(pid, sig)
RESULT(errno)
BIND(C, name="kill")
420 INTEGER(KIND=C_INT),
VALUE :: pid, sig
421 INTEGER(KIND=C_INT) :: errno
429 istat = kill(pid=pid, sig=0)
443 INTEGER(KIND=int_8),
OPTIONAL,
INTENT(OUT) :: mem
444 INTEGER(KIND=int_8) :: mem_local
449#if defined(__NO_STATM_ACCESS)
452 INTEGER(KIND=int_8) :: m1, m2, m3
453 CHARACTER(LEN=80) :: data
458 FUNCTION getpagesize()
BIND(C, name="getpagesize") RESULT(RES)
460 INTEGER(C_INT) :: res
461 END FUNCTION getpagesize
468 OPEN (121245, file=
"/proc/self/statm", action=
"READ", status=
"OLD", access=
"STREAM")
470 READ (121245,
END=999) DATA(I:I)
477 READ (
DATA, *, iostat=iostat) m1, m2, m3
478 IF (iostat /= 0)
THEN
482#if defined(__STATM_TOTAL)
485#if defined(__STATM_RESIDENT)
488 mem_local = mem_local*getpagesize()
493 IF (
PRESENT(mem)) mem = mem_local
511 SUBROUTINE m_memory_details(MemTotal, MemFree, Buffers, Cached, Slab, SReclaimable, MemLikelyFree)
513 INTEGER(kind=int_8),
OPTIONAL :: memtotal, memfree, buffers, cached, slab, sreclaimable, memlikelyfree
515 INTEGER,
PARAMETER :: nbuffer = 10000
516 CHARACTER(LEN=Nbuffer) :: meminfo
529 OPEN (unit=8123, file=
"/proc/meminfo", access=
"STREAM", err=901)
533 IF (i > nbuffer)
EXIT
534 READ (8123,
END=900, ERR=900) meminfo(i:i)
537 meminfo(i:nbuffer) =
""
539 CLOSE (8123, err=902)
541 memtotal = get_field_value_in_bytes(
'MemTotal:')
542 memfree = get_field_value_in_bytes(
'MemFree:')
543 buffers = get_field_value_in_bytes(
'Buffers:')
544 cached = get_field_value_in_bytes(
'Cached:')
545 slab = get_field_value_in_bytes(
'Slab:')
546 sreclaimable = get_field_value_in_bytes(
'SReclaimable:')
548 memlikelyfree = memfree + buffers + cached + sreclaimable
557 INTEGER(int_8) FUNCTION get_field_value_in_bytes(field)
558 CHARACTER(LEN=*) :: field
561 INTEGER(KIND=int_8) :: value
563 get_field_value_in_bytes = 0
564 start = index(meminfo, field)
566 start = start + len_trim(field)
567 IF (start < nbuffer)
THEN
568 READ (meminfo(start:), *, err=999,
END=999) value
570 get_field_value_in_bytes =
value*1024
574 END FUNCTION get_field_value_in_bytes
582 CHARACTER(len=*),
INTENT(OUT) :: hname
584 CHARACTER(len=default_path_length) :: buf
587 FUNCTION gethostname(buf, buflen)
BIND(C, name="gethostname") RESULT(errno)
589 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: buf
590 INTEGER(KIND=C_INT),
VALUE :: buflen
591 INTEGER(KIND=C_INT) :: errno
592 END FUNCTION gethostname
595 istat = gethostname(buf, len(buf))
597 WRITE (*, *)
"m_hostnm failed"
600 i = index(buf, c_null_char) - 1
609 CHARACTER(len=*),
INTENT(OUT) :: curdir
612 CHARACTER(len=default_path_length),
TARGET :: tmp
615 FUNCTION getcwd(buf, buflen)
BIND(C, name="getcwd") RESULT(stat)
617 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: buf
618 INTEGER(KIND=C_INT),
VALUE :: buflen
623 stat = getcwd(tmp, len(tmp))
624 IF (.NOT. c_associated(stat))
THEN
625 WRITE (*, *)
"m_getcwd failed"
628 i = index(tmp, c_null_char) - 1
638 CHARACTER(len=*),
INTENT(IN) :: dir
639 INTEGER,
INTENT(OUT) :: ierror
642 FUNCTION chdir(path)
BIND(C, name="chdir") RESULT(errno)
644 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: path
645 INTEGER(KIND=C_INT) :: errno
649 ierror = chdir(trim(dir)//c_null_char)
657 INTEGER,
INTENT(OUT) :: pid
660 FUNCTION getpid()
BIND(C, name="getpid") RESULT(pid)
662 INTEGER(KIND=C_INT) :: pid
676 CHARACTER(LEN=*),
INTENT(IN) :: path
681 FUNCTION unlink(path)
BIND(C, name="unlink") RESULT(errno)
683 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: path
684 INTEGER(KIND=C_INT) :: errno
688 istat = unlink(trim(path)//c_null_char)
698 CHARACTER(LEN=*),
INTENT(IN) :: source, target
701 LOGICAL :: src_exists
704 FUNCTION rename(src, dest)
BIND(C, name="rename") RESULT(errno)
706 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: src, dest
707 INTEGER(KIND=C_INT) :: errno
711 IF (
TARGET == source)
THEN
712 WRITE (*, *)
"Warning: m_mov ", trim(
TARGET),
" equals ", trim(source)
721 istat = rename(trim(source)//c_null_char, trim(
TARGET)//c_null_char)
724 INQUIRE (file=source, exist=src_exists)
725 IF (.NOT. src_exists)
RETURN
726 WRITE (*, *)
"Trying to move "//trim(source)//
" to "//trim(
TARGET)//
"."
727 WRITE (*, *)
"rename returned status: ", istat
728 WRITE (*, *)
"Problem moving file"
739 CHARACTER(LEN=*),
INTENT(OUT) :: user
744 CALL get_environment_variable(
"LOGNAME",
value=user, status=istat)
747 CALL get_environment_variable(
"USER",
value=user, status=istat)
751 CALL get_environment_variable(
"USERNAME",
value=user, status=istat)
765 CHARACTER(LEN=*),
INTENT(OUT) :: omp_stacksize
770 CALL get_environment_variable(
"OMP_STACKSIZE",
value=omp_stacksize, status=istat)
772 IF (istat /= 0) omp_stacksize =
"default"
Target architecture or instruction set extension according to compiler target flags.
Trace OpenMP constructs if ennvironment variable CP2K_OMP_TRACE=1.
Defines the basic variable types.
integer, parameter, public int_8
integer, parameter, public dp
integer, parameter, public default_string_length
integer, parameter, public default_path_length
Machine interface based on Fortran 2003 and POSIX.
integer, parameter, public machine_x86_avx
logical, save, public flush_should_flush
subroutine, public m_getpid(pid)
...
integer, parameter, public machine_arm_sve512
integer, parameter, public default_output_unit
integer, parameter, public machine_x86_sse4
subroutine, public m_memory(mem)
Returns the total amount of memory [bytes] in use, if known, zero otherwise.
integer, parameter, public machine_cpu_generic
integer, parameter, public default_input_unit
integer, parameter, public timestamp_length
subroutine, public m_flush(lunit)
flushes units if the &GLOBAL flag is set accordingly
integer, parameter, public machine_arm_sve256
integer, parameter, public machine_x86_avx2
subroutine, public m_abort()
Can be used to get a nice core.
subroutine, public m_timestamp(timestamp)
Returns a human readable timestamp.
integer function, public m_procrun(pid)
Returns if a process is running on the local machine 1 if yes and 0 if not.
subroutine, public m_memory_details(memtotal, memfree, buffers, cached, slab, sreclaimable, memlikelyfree)
get more detailed memory info, all units are bytes. the only 'useful' option is MemLikelyFree which i...
pure integer function, public m_cpuid()
Target architecture or instruction set extension according to CPU-check at runtime.
subroutine, public m_getcwd(curdir)
...
integer, parameter, public machine_x86
subroutine, public m_chdir(dir, ierror)
...
pure integer function, public m_cpuid_vlen(cpuid, typesize)
Determine vector-length for a given CPUID.
real(kind=dp) function, public m_energy()
returns the energy used since some time in the past. The precise meaning depends on the infrastructur...
integer, parameter, public machine_arm
integer function, public m_unlink(path)
...
subroutine, public m_cpuinfo(model_name)
reads /proc/cpuinfo if it exists (i.e. Linux) to return relevant info
subroutine, public m_mov(source, target)
...
integer, parameter, public default_error_unit
pure character(len=default_string_length) function, public m_cpuid_name(cpuid)
Determine name of target architecture for a given CPUID.
integer, parameter, public machine_x86_avx512
integer, parameter, public machine_arm_arch64
subroutine, public m_omp_get_stacksize(omp_stacksize)
Retrieve environment variable OMP_STACKSIZE.
integer, parameter, public machine_cpu_unknown
integer(kind=int_8), save, public m_memory_max
integer, parameter, public machine_arm_sve128
subroutine, public m_getlog(user)
...
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
subroutine, public m_hostnm(hname)
...