Commit 3b29c0a8 authored by Joerg Behrens's avatar Joerg Behrens
Browse files

Fortran interface for setting hdf5 attributes.

Testet on mistral with intel/15.0.6 and
/sw/rhel6-x64/hdf5/hdf5-1.8.16-threadsafe-intel14
parent 5bd98310
......@@ -456,6 +456,7 @@ AC_CONFIG_FILES([tests/test_precision_run
tests/test_sct_run
tests/test_papi_run
tests/test_hdf5_run
tests/test2_hdf5_run
tests/test_serial_run
tests/test_omp_run
tests/test_mpi_run
......
......@@ -4,7 +4,7 @@
!> the interface/module of sct for all FORTRAN users
MODULE sct
USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_CHAR, C_INT, C_DOUBLE, C_NULL_CHAR
USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_CHAR, C_INT, C_LONG, C_FLOAT, C_DOUBLE, C_NULL_CHAR
#ifdef HAVE_MPI
USE MPI
#endif
......@@ -20,7 +20,7 @@ MODULE sct
& sct_reset_timer, sct_reset_all, sct_resolution, sct_val, sct_report, &
& sct_new_context, sct_context_start, sct_context_stop, sct_active, &
& sct_last_dt, sct_stop_all, sct_set_callstats, sct_set_eventcounters, &
& sct_set_nestedtimers
& sct_set_nestedtimers, sct_add_report_attribute
#ifdef HAVE_MPI
INTEGER, PARAMETER, PUBLIC :: SCT_COMM_WORLD = MPI_COMM_WORLD
......@@ -48,6 +48,15 @@ MODULE sct
MODULE PROCEDURE new_general_context
END INTERFACE sct_new_context
!> generic interface for sct_add_report_attribute_* family
INTERFACE sct_add_report_attribute
MODULE PROCEDURE sct_add_report_attribute_int_f
MODULE PROCEDURE sct_add_report_attribute_long_f
MODULE PROCEDURE sct_add_report_attribute_float_f
MODULE PROCEDURE sct_add_report_attribute_double_f
MODULE PROCEDURE sct_add_report_attribute_string_f
END INTERFACE sct_add_report_attribute
!> interface for C-function ::sct_set_callstats
INTERFACE
!> en-/dis-able callstats output
......@@ -201,6 +210,96 @@ MODULE sct
CONTAINS
!> Fortran wrapper for sct_add_report_attribute_int
SUBROUTINE sct_add_report_attribute_int_f(key, val)
CHARACTER(len=*), INTENT(in) :: key
INTEGER(C_INT), INTENT(in) :: val
INTERFACE
SUBROUTINE sct_add_report_attribute_int(key, val) BIND(C, NAME='sct_add_report_attribute_int')
IMPORT:: C_CHAR, C_INT
IMPLICIT NONE
CHARACTER(C_CHAR), DIMENSION(*), INTENT(in) :: key
INTEGER(C_INT), VALUE, INTENT(in) :: val
END SUBROUTINE sct_add_report_attribute_int
END INTERFACE
CALL sct_add_report_attribute_int(TRIM(ADJUSTL(key)) // c_null_char, val)
END SUBROUTINE sct_add_report_attribute_int_f
!> Fortran wrapper for sct_add_report_attribute_long
SUBROUTINE sct_add_report_attribute_long_f(key, val)
CHARACTER(len=*), INTENT(in) :: key
INTEGER(C_LONG), INTENT(in) :: val
INTERFACE
SUBROUTINE sct_add_report_attribute_long(key, val) BIND(C, NAME='sct_add_report_attribute_long')
IMPORT:: C_CHAR, C_LONG
IMPLICIT NONE
CHARACTER(C_CHAR), DIMENSION(*), INTENT(in) :: key
INTEGER(C_LONG), VALUE, INTENT(in) :: val
END SUBROUTINE sct_add_report_attribute_long
END INTERFACE
CALL sct_add_report_attribute_long(TRIM(ADJUSTL(key)) // c_null_char, val)
END SUBROUTINE sct_add_report_attribute_long_f
!> Fortran wrapper for sct_add_report_attribute_float
SUBROUTINE sct_add_report_attribute_float_f(key, val)
CHARACTER(len=*), INTENT(in) :: key
REAL(C_FLOAT), INTENT(in) :: val
INTERFACE
SUBROUTINE sct_add_report_attribute_float(key, val) BIND(C, NAME='sct_add_report_attribute_float')
IMPORT:: C_CHAR, C_FLOAT
IMPLICIT NONE
CHARACTER(C_CHAR), DIMENSION(*), INTENT(in) :: key
REAL(C_FLOAT), VALUE, INTENT(in) :: val
END SUBROUTINE sct_add_report_attribute_float
END INTERFACE
CALL sct_add_report_attribute_float(TRIM(ADJUSTL(key)) // c_null_char, val)
END SUBROUTINE sct_add_report_attribute_float_f
!> Fortran wrapper for sct_add_report_attribute_double
SUBROUTINE sct_add_report_attribute_double_f(key, val)
CHARACTER(len=*), INTENT(in) :: key
REAL(C_DOUBLE), INTENT(in) :: val
INTERFACE
SUBROUTINE sct_add_report_attribute_double(key, val) BIND(C, NAME='sct_add_report_attribute_double')
IMPORT:: C_CHAR, C_DOUBLE
IMPLICIT NONE
CHARACTER(C_CHAR), DIMENSION(*), INTENT(in) :: key
REAL(C_DOUBLE), VALUE, INTENT(in) :: val
END SUBROUTINE sct_add_report_attribute_double
END INTERFACE
CALL sct_add_report_attribute_double(TRIM(ADJUSTL(key)) // c_null_char, val)
END SUBROUTINE sct_add_report_attribute_double_f
!> Fortran wrapper for sct_add_report_attribute_string
SUBROUTINE sct_add_report_attribute_string_f(key, val)
CHARACTER(len=*), INTENT(in) :: key
CHARACTER(len=*), INTENT(in) :: val
INTERFACE
SUBROUTINE sct_add_report_attribute_string(key, val) BIND(C, NAME='sct_add_report_attribute_string')
IMPORT:: C_CHAR, C_DOUBLE
IMPLICIT NONE
CHARACTER(C_CHAR), DIMENSION(*), INTENT(in) :: key
CHARACTER(C_CHAR), DIMENSION(*), INTENT(in) :: val
END SUBROUTINE sct_add_report_attribute_string
END INTERFACE
CALL sct_add_report_attribute_string(TRIM(ADJUSTL(key)) // c_null_char, TRIM(ADJUSTL(val)) // c_null_char)
END SUBROUTINE sct_add_report_attribute_string_f
!> \brief initialisation function of sct
!! \param[in] timer_max maximum number of timers to be used
!! \param[in] default_context_name name of the context to be used
......
......@@ -16,6 +16,7 @@ endif
if HDF5
noinst_PROGRAMS += test_hdf5
noinst_PROGRAMS += test2_hdf5
LIBS += $(LIBHDF5)
endif
......@@ -50,6 +51,7 @@ endif
test_papi_SOURCES = test_papi.c
test_hdf5_SOURCES = test_hdf5.c
test2_hdf5_SOURCES = test2_hdf5.f90
test_serial_SOURCES = test_serial.c
test_omp_SOURCES = test_omp.c
test_mpi_SOURCES = test_mpi.c
......@@ -71,6 +73,7 @@ endif
if HDF5
TESTS += test_hdf5_run
TESTS += test2_hdf5_run
endif
if !OPENMP
......
PROGRAM test2_hdf5
USE, INTRINSIC :: iso_c_binding, ONLY: c_int, c_long, c_float, c_double
USE sct, ONLY: sct_init, sct_new_timer, sct_start, sct_stop, sct_report, &
& sct_set_callstats, sct_add_report_attribute
IMPLICIT NONE
INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12,307)
INTEGER :: itimer
INTEGER(c_int) :: val_int
INTEGER(c_long) :: val_long
REAL(c_float) :: val_float
REAL(c_double) :: val_double
CHARACTER(len=20) :: val_string
CALL sct_init(timer_max=3)
itimer = sct_new_timer('test timer')
CALL sct_start(itimer)
CALL test1
CALL sct_stop(itimer)
val_int = 123
val_long = 456
val_float = 0.5
val_double = 0.25
val_string = 'abc'
CALL sct_add_report_attribute('test_att_int',val_int)
CALL sct_add_report_attribute('test_att_long',val_long)
CALL sct_add_report_attribute('test_att_float',val_float)
CALL sct_add_report_attribute('test_att_double',val_double)
CALL sct_add_report_attribute('test_att_string',val_string)
CALL sct_report()
CONTAINS
SUBROUTINE test1
REAL(dp) :: s, x, dt
INTEGER :: i,j
DO j = 1, 8
s = 0.0_dp
DO i = 0, j*100000
x = REAL(i,dp)
s = s + EXP(-SQRT(x))
ENDDO
IF (s<2.0_dp) PRINT*,'j, s =',j,s ! fake interest in the result
ENDDO
END SUBROUTINE test1
END PROGRAM test2_hdf5
#! @SHELL@
export SCT_OUT="hdf5"
#export SCT_OUT="stdout"
export SCT_FILENAME="sct-testfile.h5"
rm -f $SCT_FILENAME
export SCT_CALLSTATS=1
@abs_top_srcdir@/tests/test2_hdf5 || exit 1
h5dump -a '/report_attributes/test_att_int' $SCT_FILENAME | grep 123 || exit 1
h5dump -a '/report_attributes/test_att_long' $SCT_FILENAME | grep 456 || exit 1
h5dump -a '/report_attributes/test_att_float' $SCT_FILENAME | grep 0.5 || exit 1
h5dump -a '/report_attributes/test_att_double' $SCT_FILENAME | grep 0.25 || exit 1
h5dump -a '/report_attributes/test_att_string' $SCT_FILENAME | grep abc || exit 1
rm -f $SCT_FILENAME
exit 0
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment