18 USE iso_c_binding,
ONLY: c_char, &
23 USE iso_fortran_env,
ONLY: input_unit, &
25 USE omp_lib,
ONLY: omp_get_wtime
30 #if defined(__LIBXSMM)
31 USE libxsmm,
ONLY: libxsmm_timer_tick, &
32 libxsmm_timer_duration, &
33 libxsmm_get_target_archid, &
48 #include "machine_cpuid.h"
55 INTEGER,
PUBLIC,
PARAMETER :: &
106 INTEGER,
INTENT(IN) :: lunit
125 #if defined(__LIBXSMM)
126 wt = libxsmm_timer_duration(0_int_8, libxsmm_timer_tick())
137 CHARACTER(LEN=default_string_length) :: model_name
139 INTEGER,
PARAMETER :: bufferlen = 2048
141 CHARACTER(LEN=bufferlen) :: buffer
142 INTEGER :: i, icol, iline, imod, stat
144 model_name =
"UNKNOWN"
146 OPEN (121245, file=
"/proc/cpuinfo", action=
"READ", status=
"OLD", access=
"STREAM", iostat=stat)
149 READ (121245,
END=999) buffer(I:I)
152 imod = index(buffer,
"model name")
154 icol = imod - 1 + index(buffer(imod:),
":")
155 iline = icol - 1 + index(buffer(icol:), new_line(
'A'))
156 IF (iline == icol - 1) iline = bufferlen + 1
157 model_name = buffer(icol + 1:iline - 1)
170 #if defined(__LIBXSMM)
171 cpuid = libxsmm_get_target_archid()
188 CHARACTER(len=default_string_length),
POINTER ::
m_cpuid_name
190 CHARACTER(len=default_string_length),
SAVE,
TARGET :: name_generic =
"generic", &
191 name_unknown =
"unknown", name_x86_avx =
"x86_avx", name_x86_avx2 =
"x86_avx2", &
192 name_x86_avx512 =
"x86_avx512", name_x86_sse4 =
"x86_sse4"
221 #if defined(__CRAY_PM_ENERGY)
222 wt = read_energy(
"/sys/cray/pm_counters/energy")
223 #elif defined(__CRAY_PM_ACCEL_ENERGY)
224 wt = read_energy(
"/sys/cray/pm_counters/accel_energy")
231 #if defined(__CRAY_PM_ACCEL_ENERGY) || defined(__CRAY_PM_ENERGY)
239 FUNCTION read_energy(filename)
RESULT(wt)
240 CHARACTER(LEN=*) :: filename
243 CHARACTER(LEN=80) :: data
245 INTEGER(KIND=int_8) :: raw
247 OPEN (121245, file=filename, action=
"READ", status=
"OLD", access=
"STREAM")
249 READ (121245,
END=999) DATA(I:I)
253 READ (
DATA, *, iostat=iostat) raw
254 IF (iostat .NE. 0)
THEN
260 END FUNCTION read_energy
270 CHARACTER(len=*),
INTENT(OUT) :: cal_date
272 CHARACTER(len=10) :: time
273 CHARACTER(len=8) :: date
275 CALL date_and_time(date=date, time=time)
276 cal_date = date(1:4)//
"-"//date(5:6)//
"-"//date(7:8)//
" "//time(1:2)//
":"//time(3:4)//
":"//time(5:10)
285 SUBROUTINE abort()
BIND(C, name="abort")
299 INTEGER,
INTENT(IN) :: pid
307 FUNCTION kill(pid, sig)
BIND(C, name="kill") RESULT(errno)
309 INTEGER(KIND=C_INT),
VALUE :: pid, sig
310 INTEGER(KIND=C_INT) :: errno
318 istat = kill(pid=pid, sig=0)
333 INTEGER(KIND=int_8),
OPTIONAL,
INTENT(OUT) :: mem
334 INTEGER(KIND=int_8) :: mem_local
340 #if defined(__NO_STATM_ACCESS)
343 INTEGER(KIND=int_8) :: m1, m2, m3
344 CHARACTER(LEN=80) :: data
349 FUNCTION getpagesize()
BIND(C, name="getpagesize") RESULT(RES)
351 INTEGER(C_INT) :: res
360 OPEN (121245, file=
"/proc/self/statm", action=
"READ", status=
"OLD", access=
"STREAM")
362 READ (121245,
END=999) DATA(I:I)
369 READ (
DATA, *, iostat=iostat) m1, m2, m3
370 IF (iostat .NE. 0)
THEN
374 #if defined(__STATM_TOTAL)
377 #if defined(__STATM_RESIDENT)
380 mem_local = mem_local*getpagesize()
385 IF (
PRESENT(mem)) mem = mem_local
403 SUBROUTINE m_memory_details(MemTotal, MemFree, Buffers, Cached, Slab, SReclaimable, MemLikelyFree)
405 INTEGER(kind=int_8),
OPTIONAL :: memtotal, memfree, buffers, cached, slab, sreclaimable, memlikelyfree
407 INTEGER,
PARAMETER :: nbuffer = 10000
408 CHARACTER(LEN=Nbuffer) :: meminfo
421 OPEN (unit=8123, file=
"/proc/meminfo", access=
"STREAM", err=901)
425 IF (i > nbuffer)
EXIT
426 READ (8123,
END=900, ERR=900) meminfo(i:i)
429 meminfo(i:nbuffer) =
""
431 CLOSE (8123, err=902)
433 memtotal = get_field_value_in_bytes(
'MemTotal:')
434 memfree = get_field_value_in_bytes(
'MemFree:')
435 buffers = get_field_value_in_bytes(
'Buffers:')
436 cached = get_field_value_in_bytes(
'Cached:')
437 slab = get_field_value_in_bytes(
'Slab:')
438 sreclaimable = get_field_value_in_bytes(
'SReclaimable:')
440 memlikelyfree = memfree + buffers + cached + sreclaimable
449 INTEGER(int_8) FUNCTION get_field_value_in_bytes(field)
450 CHARACTER(LEN=*) :: field
453 INTEGER(KIND=int_8) :: value
455 get_field_value_in_bytes = 0
456 start = index(meminfo, field)
457 IF (start .NE. 0)
THEN
458 start = start + len_trim(field)
459 IF (start .LT. nbuffer)
THEN
460 READ (meminfo(start:), *, err=999,
END=999) value
462 get_field_value_in_bytes =
value*1024
474 CHARACTER(len=*),
INTENT(OUT) :: hname
481 CHARACTER(len=default_path_length) :: buf
484 FUNCTION gethostname(buf, buflen)
BIND(C, name="gethostname") RESULT(errno)
486 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: buf
487 INTEGER(KIND=C_INT),
VALUE :: buflen
488 INTEGER(KIND=C_INT) :: errno
492 istat = gethostname(buf, len(buf))
494 WRITE (*, *)
"m_hostnm failed"
497 i = index(buf, c_null_char) - 1
507 CHARACTER(len=*),
INTENT(OUT) :: curdir
510 CHARACTER(len=default_path_length),
TARGET :: tmp
513 FUNCTION getcwd(buf, buflen)
BIND(C, name="getcwd") RESULT(stat)
515 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: buf
516 INTEGER(KIND=C_INT),
VALUE :: buflen
521 stat = getcwd(tmp, len(tmp))
522 IF (.NOT. c_associated(stat))
THEN
523 WRITE (*, *)
"m_getcwd failed"
526 i = index(tmp, c_null_char) - 1
536 CHARACTER(len=*),
INTENT(IN) :: dir
537 INTEGER,
INTENT(OUT) :: ierror
540 FUNCTION chdir(path)
BIND(C, name="chdir") RESULT(errno)
542 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: path
543 INTEGER(KIND=C_INT) :: errno
547 ierror = chdir(trim(dir)//c_null_char)
555 INTEGER,
INTENT(OUT) :: pid
558 FUNCTION getpid()
BIND(C, name="getpid") RESULT(pid)
560 INTEGER(KIND=C_INT) :: pid
572 FUNCTION m_unlink(path)
RESULT(istat)
574 CHARACTER(LEN=*),
INTENT(IN) :: path
579 FUNCTION unlink(path)
BIND(C, name="unlink") RESULT(errno)
581 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: path
582 INTEGER(KIND=C_INT) :: errno
586 istat = unlink(trim(path)//c_null_char)
587 END FUNCTION m_unlink
596 CHARACTER(LEN=*),
INTENT(IN) :: source, target
601 FUNCTION rename(src, dest)
BIND(C, name="rename") RESULT(errno)
603 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: src, dest
604 INTEGER(KIND=C_INT) :: errno
608 IF (
TARGET == source)
THEN
609 WRITE (*, *)
"Warning: m_mov ", trim(
TARGET),
" equals ", trim(source)
614 istat = m_unlink(
TARGET)
618 istat = rename(trim(source)//c_null_char, trim(
TARGET)//c_null_char)
619 IF (istat .NE. 0)
THEN
620 WRITE (*, *)
"Trying to move "//trim(source)//
" to "//trim(
TARGET)//
"."
621 WRITE (*, *)
"rename returned status: ", istat
622 WRITE (*, *)
"Problem moving file"
633 CHARACTER(LEN=*),
INTENT(OUT) :: user
638 CALL get_environment_variable(
"LOGNAME",
value=user, status=istat)
641 CALL get_environment_variable(
"USER",
value=user, status=istat)
644 CALL get_environment_variable(
"USERNAME",
value=user, status=istat)
656 CHARACTER(LEN=*),
INTENT(OUT) :: omp_stacksize
661 CALL get_environment_variable(
"OMP_STACKSIZE",
value=omp_stacksize, status=istat)
663 IF (istat /= 0) omp_stacksize =
"default"
int m_cpuid_static(void)
This routine determines the CPUID according to the given compiler flags (expected to be similar to Fo...
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 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_x86_avx2
subroutine, public m_get_omp_stacksize(omp_stacksize)
Retrieve environment variable OMP_STACKSIZE.
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.
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)
...
real(kind=dp) function, public m_energy()
returns the energy used since some time in the past. The precise meaning depends on the infrastructur...
subroutine, public m_cpuinfo(model_name)
reads /proc/cpuinfo if it exists (i.e. Linux) to return relevant info
integer, parameter, public machine_x86_avx512
subroutine, public m_mov(source, TARGET)
...
integer(kind=int_8), save, public m_memory_max
character(len=default_string_length) function, pointer, public m_cpuid_name(cpuid)
Determine name of target architecture for a given CPUID.
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)
...
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...