Repository navigation
fix(input): broadcast parser errors before MPI exits #8215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mohanchen
merged 2 commits into
deepmodeling:develop
from
Stardust0831:fix/input-parser-mpi-exit
Oct 26, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| file(MAKE_DIRECTORY "${CASE_DIR}") | ||
| set(input_file "${CASE_DIR}/INPUT") | ||
| set(contents "INPUT_PARAMETERS\nbasis_type pw\nntype 1\n") | ||
| set(expected_exit 1) | ||
| set(expected_manual "input-main.html") | ||
|
|
||
| if(INPUT_CASE STREQUAL "missing_file") | ||
| file(REMOVE "${input_file}") | ||
| set(expected "Cannot open the INPUT file") | ||
| set(expected_manual "") | ||
| elseif(INPUT_CASE STREQUAL "missing_header") | ||
| set(contents "basis_type pw\nntype 1\n") | ||
| set(expected "Missing INPUT_PARAMETERS header") | ||
| elseif(INPUT_CASE STREQUAL "unknown_parameter") | ||
| string(APPEND contents "unknown_input_option 1\n") | ||
| set(expected "Unknown INPUT parameter 'unknown_input_option'") | ||
| elseif(INPUT_CASE STREQUAL "duplicate_parameter") | ||
| string(APPEND contents "nspin 1\nnspin 2\n") | ||
| set(expected "The parameter nspin has been read twice") | ||
| set(expected_manual "input-main.html#nspin") | ||
| elseif(INPUT_CASE STREQUAL "duplicate_string_eof") | ||
| # Repeat a scalar string parameter with no value or final newline. | ||
| string(APPEND contents "basis_type") | ||
| set(expected "The parameter basis_type has been read twice") | ||
| set(expected_manual "input-main.html#basis-type") | ||
| elseif(INPUT_CASE STREQUAL "invalid_value") | ||
| string(APPEND contents "nspin 2abc\n") | ||
| set(expected "Expected one Integer from {1, 2, 4}") | ||
| set(expected_manual "input-main.html#nspin") | ||
| elseif(INPUT_CASE STREQUAL "invalid_dependency") | ||
| string(APPEND contents "nspin 2\nnoncolin true\n") | ||
| set(expected "Requires nspin==4") | ||
| set(expected_manual "input-main.html#nspin") | ||
| elseif(INPUT_CASE STREQUAL "valid") | ||
| string(APPEND contents "nspin 2\n") | ||
| set(expected_exit 0) | ||
| else() | ||
| message(FATAL_ERROR "Unknown INPUT test case: ${INPUT_CASE}") | ||
| endif() | ||
|
|
||
| if(NOT INPUT_CASE STREQUAL "missing_file") | ||
| file(WRITE "${input_file}" "${contents}") | ||
| endif() | ||
|
|
||
| execute_process( | ||
| COMMAND "${MPIEXEC_EXECUTABLE}" ${MPIEXEC_NUMPROC_FLAG} 4 ${MPIEXEC_PREFLAGS} | ||
| "${READER}" ${MPIEXEC_POSTFLAGS} "${input_file}" | ||
| WORKING_DIRECTORY "${CASE_DIR}" | ||
| RESULT_VARIABLE result | ||
| OUTPUT_VARIABLE output | ||
| ERROR_VARIABLE error | ||
| TIMEOUT 30) | ||
| string(APPEND output "${error}") | ||
|
|
||
| if(NOT "${result}" STREQUAL "${expected_exit}") | ||
| message(FATAL_ERROR "Expected exit ${expected_exit}, got ${result}:\n${output}") | ||
| endif() | ||
| string(REGEX MATCHALL "INPUT reader process reached shutdown" exits "${output}") | ||
| list(LENGTH exits exit_count) | ||
| if(NOT exit_count EQUAL 4) | ||
| message(FATAL_ERROR "Only ${exit_count} of 4 processes reached reader shutdown:\n${output}") | ||
| endif() | ||
| if(expected_exit EQUAL 1) | ||
| foreach(diagnostic IN ITEMS "${input_file}" "${expected}" "${expected_manual}") | ||
| string(FIND "${output}" "${diagnostic}" found) | ||
| if(found EQUAL -1) | ||
| message(FATAL_ERROR "Missing diagnostic '${diagnostic}':\n${output}") | ||
| endif() | ||
| endforeach() | ||
| endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #include "source_base/parallel_global.h" | ||
| #include "source_io/module_parameter/read_input.h" | ||
|
|
||
| #include <cstdio> | ||
| #include <cstdlib> | ||
| #include <string> | ||
|
|
||
| namespace | ||
| { | ||
| void finish_reader() | ||
| { | ||
| // Print before finalization so an early nonzero exit cannot make the | ||
| // MPI launcher terminate peers before their shutdown markers are written. | ||
| std::fputs("INPUT reader process reached shutdown\n", stderr); | ||
| std::fflush(stderr); | ||
| // Finalization makes a rank-0-only exit fail the test's timeout even if | ||
| // the MPI launcher would otherwise terminate the remaining ranks for us. | ||
| Parallel_Global::finalize_mpi(); | ||
| } | ||
| } // namespace | ||
|
|
||
| int main(int argc, char** argv) | ||
| { | ||
| if (argc != 2) | ||
| { | ||
| return 2; | ||
| } | ||
| int process_count = 1; | ||
| int thread_count = 1; | ||
| int rank = 0; | ||
| Parallel_Global::read_pal_param(argc, argv, process_count, thread_count, rank); | ||
| // Input-only tests do not create the legacy calculation communicators. | ||
| POOL_WORLD = MPI_COMM_NULL; | ||
| KP_WORLD = MPI_COMM_NULL; | ||
| INT_BGROUP = MPI_COMM_NULL; | ||
| BP_WORLD = MPI_COMM_NULL; | ||
| GRID_WORLD = MPI_COMM_NULL; | ||
| DIAG_WORLD = MPI_COMM_NULL; | ||
| std::atexit(finish_reader); | ||
|
|
||
| const std::string filename = argv[1]; | ||
| ModuleIO::ReadInput reader(rank); | ||
| reader.check_ntype_flag = false; | ||
| Parameter input; | ||
| reader.read_parameters(input, filename); | ||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.