From 812b0f07f5fc8037df99cf62f26c9c7bccb9ed3e Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 27 Jul 2021 08:35:52 +0200 Subject: [PATCH] read file only once (per process) --- src/YAML_parse.f90 | 12 ++++++------ src/config.f90 | 19 ++++++++++++++++--- src/grid/DAMASK_grid.f90 | 4 ++-- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/YAML_parse.f90 b/src/YAML_parse.f90 index d7cfa016f..2df09936d 100644 --- a/src/YAML_parse.f90 +++ b/src/YAML_parse.f90 @@ -14,7 +14,7 @@ module YAML_parse public :: & YAML_parse_init, & - YAML_parse_file + YAML_parse_str contains @@ -29,16 +29,16 @@ end subroutine YAML_parse_init !-------------------------------------------------------------------------------------------------- -!> @brief Parse a YAML file into a a structure of nodes. +!> @brief Parse a YAML string into a a structure of nodes. !-------------------------------------------------------------------------------------------------- -function YAML_parse_file(fname) result(node) +function YAML_parse_str(str) result(node) - character(len=*), intent(in) :: fname + character(len=*), intent(in) :: str class (tNode), pointer :: node - node => parse_flow(to_flow(IO_read(fname))) + node => parse_flow(to_flow(str)) -end function YAML_parse_file +end function YAML_parse_str !-------------------------------------------------------------------------------------------------- diff --git a/src/config.f90 b/src/config.f90 index 8ee25182f..b80658213 100644 --- a/src/config.f90 +++ b/src/config.f90 @@ -51,14 +51,17 @@ subroutine parse_material() inquire(file='material.yaml',exist=fileExists) if(.not. fileExists) call IO_error(100,ext_msg='material.yaml') + print*, 'reading material.yaml'; flush(IO_STDOUT) fileContent = IO_read('material.yaml') + if (worldrank == 0) then call results_openJobFile(parallel=.false.) call results_writeDataset_str(fileContent,'setup','material.yaml','DAMASK main configuration') call results_closeJobFile endif - config_material => YAML_parse_file('material.yaml') + + config_material => YAML_parse_str(fileContent) end subroutine parse_material @@ -73,16 +76,21 @@ subroutine parse_numerics() config_numerics => emptyDict + inquire(file='numerics.yaml', exist=fileExists) if (fileExists) then + print*, 'reading numerics.yaml'; flush(IO_STDOUT) fileContent = IO_read('numerics.yaml') + if (worldrank == 0) then call results_openJobFile(parallel=.false.) call results_writeDataset_str(fileContent,'setup','numerics.yaml','numerics configuration (optional)') call results_closeJobFile endif - config_numerics => YAML_parse_file('numerics.yaml') + + config_numerics => YAML_parse_str(fileContent) + endif end subroutine parse_numerics @@ -98,16 +106,21 @@ subroutine parse_debug() config_debug => emptyDict + inquire(file='debug.yaml', exist=fileExists) if (fileExists) then + print*, 'reading debug.yaml'; flush(IO_STDOUT) fileContent = IO_read('debug.yaml') + if (worldrank == 0) then call results_openJobFile(parallel=.false.) call results_writeDataset_str(fileContent,'setup','debug.yaml','debug configuration (optional)') call results_closeJobFile endif - config_debug => YAML_parse_file('debug.yaml') + + config_debug => YAML_parse_str(fileContent) + endif end subroutine parse_debug diff --git a/src/grid/DAMASK_grid.f90 b/src/grid/DAMASK_grid.f90 index 800003552..65c050b0c 100644 --- a/src/grid/DAMASK_grid.f90 +++ b/src/grid/DAMASK_grid.f90 @@ -129,13 +129,13 @@ program DAMASK_grid if (stagItMax < 0) call IO_error(301,ext_msg='maxStaggeredIter') if (maxCutBack < 0) call IO_error(301,ext_msg='maxCutBack') + fileContent = IO_read(interface_loadFile) if (worldrank == 0) then - fileContent = IO_read(interface_loadFile) call results_openJobFile(parallel=.false.) call results_writeDataset_str(fileContent,'setup',interface_loadFile,'load case definition (grid solver)') call results_closeJobFile endif - config_load => YAML_parse_file(trim(interface_loadFile)) + config_load => YAML_parse_str(fileContent) solver => config_load%get('solver') !--------------------------------------------------------------------------------------------------