18 USE iso_c_binding,
ONLY: c_char, &
23 USE iso_fortran_env,
ONLY: input_unit, &
25 USE omp_lib,
ONLY: omp_get_wtime
31#include "libxsmm_version.h"
32#if !defined(__LIBXSMM2) && (1 < __LIBXSMM || (1170000 < \
33 (libxsmm_config_version_major*1000000 + libxsmm_config_version_minor*10000 + libxsmm_config_version_update*100 + libxsmm_config_version_patch)))
36 USE libxsmm,
ONLY: libxsmm_timer_tick, libxsmm_timer_duration, libxsmm_get_target_archid, &
37 libxsmm_target_arch_generic, libxsmm_x86_sse4, libxsmm_x86_avx, libxsmm_x86_avx2, &
38#if defined(__libxsmm2)
39 libxsmm_x86_avx512_skx, libxsmm_aarch64_v81, libxsmm_aarch64_sve128
41 libxsmm_x86_avx512_skx => libxsmm_x86_avx512_core
56#include "machine_cpuid.h"
63 INTEGER,
PUBLIC,
PARAMETER :: &
130 INTEGER,
INTENT(IN) :: lunit
149#if defined(__LIBXSMM)
150 wt = libxsmm_timer_duration(0_int_8, libxsmm_timer_tick())
161 CHARACTER(LEN=default_string_length),
INTENT(OUT) :: model_name
163 INTEGER,
PARAMETER :: bufferlen = 2048
165 CHARACTER(LEN=bufferlen) :: buffer
166 INTEGER :: i, icol, iline, stat
168 model_name =
"UNKNOWN"
170 OPEN (121245, file=
"/proc/cpuinfo", action=
"READ", status=
"OLD", access=
"STREAM", iostat=stat)
173 READ (121245,
END=999) buffer(I:I)
176 i = index(buffer,
"model name")
178 icol = i - 1 + index(buffer(i:),
":")
179 iline = icol - 1 + index(buffer(icol:), new_line(
'A'))
180 IF (iline == icol - 1) iline = bufferlen + 1
181 model_name = buffer(icol + 1:iline - 1)
195#if defined(__LIBXSMM)
196 m_cpuid = libxsmm_get_target_archid()
197 IF (libxsmm_x86_sse4 <=
m_cpuid .AND.
m_cpuid < libxsmm_x86_avx)
THEN
199 ELSE IF (libxsmm_x86_avx <=
m_cpuid .AND.
m_cpuid < libxsmm_x86_avx2)
THEN
201 ELSE IF (libxsmm_x86_avx2 <=
m_cpuid .AND.
m_cpuid < libxsmm_x86_avx512_skx)
THEN
203 ELSE IF (libxsmm_x86_avx512_skx <=
m_cpuid .AND.
m_cpuid <= 1999)
THEN
205#if defined(__LIBXSMM2)
206 ELSE IF (libxsmm_aarch64_v81 <=
m_cpuid .AND.
m_cpuid < libxsmm_aarch64_sve128)
THEN
208 ELSE IF (libxsmm_aarch64_sve128 <=
m_cpuid .AND.
m_cpuid < 2401)
THEN
213 ELSE IF (libxsmm_target_arch_generic <=
m_cpuid .AND.
m_cpuid <= 2999)
THEN
232 INTEGER,
OPTIONAL,
INTENT(IN) :: cpuid
237 IF (
PRESENT(cpuid))
THEN
276 INTEGER,
OPTIONAL,
INTENT(IN) :: cpuid, typesize
280 IF (
PRESENT(typesize))
THEN
286 IF (0 < nbytes .AND. nbytes <= 16)
THEN
287 IF (
PRESENT(cpuid))
THEN
329#if defined(__CRAY_PM_ENERGY)
330 wt = read_energy(
"/sys/cray/pm_counters/energy")
331#elif defined(__CRAY_PM_ACCEL_ENERGY)
332 wt = read_energy(
"/sys/cray/pm_counters/accel_energy")
339#if defined(__CRAY_PM_ACCEL_ENERGY) || defined(__CRAY_PM_ENERGY)
347 FUNCTION read_energy(filename)
RESULT(wt)
348 CHARACTER(LEN=*) :: filename
351 CHARACTER(LEN=80) :: data
353 INTEGER(KIND=int_8) :: raw
355 OPEN (121245, file=filename, action=
"READ", status=
"OLD", access=
"STREAM")
357 READ (121245,
END=999) DATA(I:I)
361 READ (
DATA, *, iostat=iostat) raw
362 IF (iostat .NE. 0)
THEN
368 END FUNCTION read_energy
378 CHARACTER(len=*),
INTENT(OUT) :: cal_date
380 CHARACTER(len=10) :: time
381 CHARACTER(len=8) :: date
383 CALL date_and_time(date=date, time=time)
384 cal_date = date(1:4)//
"-"//date(5:6)//
"-"//date(7:8)//
" "//time(1:2)//
":"//time(3:4)//
":"//time(5:10)
393 SUBROUTINE abort()
BIND(C, name="abort")
407 INTEGER,
INTENT(IN) :: pid
415 FUNCTION kill(pid, sig)
BIND(C, name="kill") RESULT(errno)
417 INTEGER(KIND=C_INT),
VALUE :: pid, sig
418 INTEGER(KIND=C_INT) :: errno
426 istat = kill(pid=pid, sig=0)
441 INTEGER(KIND=int_8),
OPTIONAL,
INTENT(OUT) :: mem
442 INTEGER(KIND=int_8) :: mem_local
447#if defined(__NO_STATM_ACCESS)
450 INTEGER(KIND=int_8) :: m1, m2, m3
451 CHARACTER(LEN=80) :: data
456 FUNCTION getpagesize()
BIND(C, name="getpagesize") RESULT(RES)
458 INTEGER(C_INT) :: res
466 OPEN (121245, file=
"/proc/self/statm", action=
"READ", status=
"OLD", access=
"STREAM")
468 READ (121245,
END=999) DATA(I:I)
475 READ (
DATA, *, iostat=iostat) m1, m2, m3
476 IF (iostat .NE. 0)
THEN
480#if defined(__STATM_TOTAL)
483#if defined(__STATM_RESIDENT)
486 mem_local = mem_local*getpagesize()
491 IF (
PRESENT(mem)) mem = mem_local
509 SUBROUTINE m_memory_details(MemTotal, MemFree, Buffers, Cached, Slab, SReclaimable, MemLikelyFree)
511 INTEGER(kind=int_8),
OPTIONAL :: memtotal, memfree, buffers, cached, slab, sreclaimable, memlikelyfree
513 INTEGER,
PARAMETER :: nbuffer = 10000
514 CHARACTER(LEN=Nbuffer) :: meminfo
527 OPEN (unit=8123, file=
"/proc/meminfo", access=
"STREAM", err=901)
531 IF (i > nbuffer)
EXIT
532 READ (8123,
END=900, ERR=900) meminfo(i:i)
535 meminfo(i:nbuffer) =
""
537 CLOSE (8123, err=902)
539 memtotal = get_field_value_in_bytes(
'MemTotal:')
540 memfree = get_field_value_in_bytes(
'MemFree:')
541 buffers = get_field_value_in_bytes(
'Buffers:')
542 cached = get_field_value_in_bytes(
'Cached:')
543 slab = get_field_value_in_bytes(
'Slab:')
544 sreclaimable = get_field_value_in_bytes(
'SReclaimable:')
546 memlikelyfree = memfree + buffers + cached + sreclaimable
555 INTEGER(int_8) FUNCTION get_field_value_in_bytes(field)
556 CHARACTER(LEN=*) :: field
559 INTEGER(KIND=int_8) :: value
561 get_field_value_in_bytes = 0
562 start = index(meminfo, field)
563 IF (start .NE. 0)
THEN
564 start = start + len_trim(field)
565 IF (start .LT. nbuffer)
THEN
566 READ (meminfo(start:), *, err=999,
END=999) value
568 get_field_value_in_bytes =
value*1024
580 CHARACTER(len=*),
INTENT(OUT) :: hname
587 CHARACTER(len=default_path_length) :: buf
590 FUNCTION gethostname(buf, buflen)
BIND(C, name="gethostname") RESULT(errno)
592 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: buf
593 INTEGER(KIND=C_INT),
VALUE :: buflen
594 INTEGER(KIND=C_INT) :: errno
598 istat = gethostname(buf, len(buf))
600 WRITE (*, *)
"m_hostnm failed"
603 i = index(buf, c_null_char) - 1
613 CHARACTER(len=*),
INTENT(OUT) :: curdir
616 CHARACTER(len=default_path_length),
TARGET :: tmp
619 FUNCTION getcwd(buf, buflen)
BIND(C, name="getcwd") RESULT(stat)
621 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: buf
622 INTEGER(KIND=C_INT),
VALUE :: buflen
627 stat = getcwd(tmp, len(tmp))
628 IF (.NOT. c_associated(stat))
THEN
629 WRITE (*, *)
"m_getcwd failed"
632 i = index(tmp, c_null_char) - 1
642 CHARACTER(len=*),
INTENT(IN) :: dir
643 INTEGER,
INTENT(OUT) :: ierror
646 FUNCTION chdir(path)
BIND(C, name="chdir") RESULT(errno)
648 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: path
649 INTEGER(KIND=C_INT) :: errno
653 ierror = chdir(trim(dir)//c_null_char)
661 INTEGER,
INTENT(OUT) :: pid
664 FUNCTION getpid()
BIND(C, name="getpid") RESULT(pid)
666 INTEGER(KIND=C_INT) :: pid
678 FUNCTION m_unlink(path)
RESULT(istat)
680 CHARACTER(LEN=*),
INTENT(IN) :: path
685 FUNCTION unlink(path)
BIND(C, name="unlink") RESULT(errno)
687 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: path
688 INTEGER(KIND=C_INT) :: errno
692 istat = unlink(trim(path)//c_null_char)
693 END FUNCTION m_unlink
702 CHARACTER(LEN=*),
INTENT(IN) :: source, target
707 FUNCTION rename(src, dest)
BIND(C, name="rename") RESULT(errno)
709 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: src, dest
710 INTEGER(KIND=C_INT) :: errno
714 IF (
TARGET == source)
THEN
715 WRITE (*, *)
"Warning: m_mov ", trim(
TARGET),
" equals ", trim(source)
720 istat = m_unlink(
TARGET)
724 istat = rename(trim(source)//c_null_char, trim(
TARGET)//c_null_char)
725 IF (istat .NE. 0)
THEN
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)
750 CALL get_environment_variable(
"USERNAME",
value=user, status=istat)
762 CHARACTER(LEN=*),
INTENT(OUT) :: omp_stacksize
767 CALL get_environment_variable(
"OMP_STACKSIZE",
value=omp_stacksize, status=istat)
769 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
subroutine, public m_datum(cal_date)
returns a datum in human readable format using a standard Fortran routine
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
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.
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
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)
...
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)
...