Changes to filename_template checks #1464
Conversation
|
I've run a few quick tests, and it looks like the core logic is now functioning as expected. I had just a couple of ideas that might clean up the implementation:
|
I've incorporated the 2nd idea in the most recent commit. But having either the outer loop or the inner loop consider only output streams, appears to miss some filename conflicts, due to the directionality introduced by idea #2. |
| !> Checks that there are no identical filename templates among active I/O | ||
| !> streams in the stream manager, which may lead to file conflicts. This | ||
| !> routine can be called from within MPAS_stream_mgr_validate_streams or | ||
| !> separately as needed. |
There was a problem hiding this comment.
Could we add a sentence or two about the return values from this routine? That may be especially relevant, since the return value of this routine may be used directly as the return value to MPAS_stream_mgr_validate_streams.
It might also be helpful to add a bit more detail as to what exactly this routine is checking. For example, the description "among active I/O streams" suggests that two active input streams might be caught by this routine.
| type (MPAS_streamManager_type), intent(inout) :: manager | ||
| integer, intent(out), optional :: ierr | ||
|
|
||
| integer :: threadNum, err_local,err_local1, err_local2 |
There was a problem hiding this comment.
Could you take another pass through the code changes in this PR and regularize the whitespace? For example, there's no space between err_local and err_local1 here. Other places, the whitespace is inconsistent within parentheses (e.g., lines 608 and 612).
| stream1_input_nalarms = MPAS_stream_mgr_get_num_alarms(manager, trim(stream1_cursor % name), & | ||
| MPAS_STREAM_INPUT, err_local1) | ||
| stream1_output_nalarms = MPAS_stream_mgr_get_num_alarms(manager, trim(stream1_cursor % name), & | ||
| MPAS_STREAM_OUTPUT, err_local2) |
There was a problem hiding this comment.
It doesn't look like the err_local1 or err_local2 return error codes are ever used. It might simplify the code to make ierr an optional argument to MPAS_stream_mgr_get_num_alarms, and to not pass any corresponding actual argument in these calls. That would also allow the local variables err_local1 and err_local2 to be removed.
| stream1_input_nalarms > 0) | ||
| stream1_output = ((stream1_cursor % direction == MPAS_STREAM_OUTPUT .or. & | ||
| stream1_cursor % direction == MPAS_STREAM_INPUT_OUTPUT) .and. & | ||
| stream1_output_nalarms > 0) |
There was a problem hiding this comment.
I may be mistaken, but with the exception of stream1_input, the above stream1_* variables are only used until the point where we enter the second loop over streams, and so it might be possible to simply declare the variables pkg_active (rather than stream1_pkg_active and stream2_pkg_active), etc. This would cut down on the number of local variables that the reader would need to consider when looking through this code.
| message = 'Found identical values of the filename_template attribute for multiple active output streams, ' & | ||
| // trim(stream1_cursor % name) // ' and ' // trim(stream2_cursor % name) // & | ||
| ', in streams.<CORE>. This may result in file conflicts.' | ||
| call mpas_log_write(message, messageType=MPAS_LOG_ERR) |
There was a problem hiding this comment.
The error message can be quite long when printed to a single line, e.g.,
ERROR: Found identical values of the filename_template attribute for multiple active output streams, restart and output, in streams.<CORE>. This may result in file conflicts.
It might be better to explicitly write a multi-line error message with multiple calls to mpas_log_write.
|
I have addressed the remaining suggestions in the last few commits. |
Issue:
Previously, if two active, output stream definitions in the streams. file specified the same string as the
filename_templateattribute, the corresponding MPAS CORE would crash with an error message. This was also the case for when one of the streams, sharing thefilename_template, included an inactive package, hence effectively making it inactive. The existing logic to perform stream uniqueness checks insrc/framework/xml_stream_parser.cdid not have the information about which packages associated with a stream were active, and hence did not account for inactive packages.Solution
This PR introduces a new subroutine
MPAS_stream_mgr_check_filename_templateinsrc/framework/mpas_stream_manager.Fto check whether two active streams might potentially be accessing the same file (viafilename_template) resulting in file conflicts. More specifically, this subroutine checks that there are no active output streams that share an identicalfilename_templateattribute with any other active input or output streams in the stream manager. An active stream in this context is a stream with attributeactive_stream = .true.and is not deactivated by an inactive package and is either an input or output stream with at least one active alarm. This routine can be called from withinMPAS_stream_mgr_validate_streamsor separately as needed.This PR also introduces a new function 'MPAS_stream_mgr_get_num_alarms', which returns the number of active alarms for a given stream in the specified direction.
The previous logic to check for unique
filename_templateattributes insrc/framework/xml_stream_parser.chas been removed, while retaining the checks for unique stream names in the same location. Note that the previous logic only check for conflicts between two output streams, whereas the new logic also checks for potential conflicts between an input stream and an output stream accessing the same file.