forked from trilinos/Trilinos
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into jgfouca/measure_fa…
…stilu * origin/develop: (179 commits) Framework: Update `detect-mpi-comm-world` GitHub action (trilinos#12199) Ifpack2: fix dashboard failures in MDF unit tests (trilinos#12217) teuchos(cleaning): remove old type traits is_same Use ternary in conditionals involving is_contiguous. Extract diagonal blocks from a CRS matrix into separate CRS matrices Tpetra: Update Building.rst Zoltan2: fix shadow warning Stokhos: fix KokkosKernels trilinos#1959 NOX: fix font in screen output Tpetra: fix TAFC changes for UVM enabled Tpetra: remove unnecessary exception test MueLu: remove deep_copy timers Tpetra: fix unit tests, eliminate more deep copies Tpetra: remove obsolete TAFC method Tpetra: merge two TAFC methods MueLu: update lumped diagonal code Tpetra: replace device type of resulting view Belos: Remove use of hardcoded MPI_COMM_WORLD Stokhos: update for new KokkosSparse::spmv overloads Tpetra: Removing the incorrect ETI_DEVICES ...
- Loading branch information
Showing
1,723 changed files
with
12,305 additions
and
406,930 deletions.
There are no files selected for viewing
This file contains 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,20 @@ | ||
name: Check MPI_COMM_WORLD | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Search for MPI_COMM_WORLD in modified lines | ||
run: | | ||
python $GITHUB_WORKSPACE/commonTools/test/utilities/check-mpi-comm-world-usage.py \ | ||
--base origin/${{ github.event.pull_request.base.ref }} \ | ||
--head ${{ github.event.pull_request.head.sha }} |
This file contains 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 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 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
128 changes: 128 additions & 0 deletions
128
commonTools/test/utilities/check-mpi-comm-world-usage.py
This file contains 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,128 @@ | ||
import sys | ||
import subprocess | ||
import re | ||
import argparse | ||
|
||
|
||
def parse_diff_output(changed_files): | ||
# Regex to capture filename and the line numbers of the changes | ||
file_pattern = re.compile(r"^\+\+\+ b/(.*?)$", re.MULTILINE) | ||
line_pattern = re.compile(r"^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@", re.MULTILINE) | ||
|
||
files = {} | ||
for match in file_pattern.finditer(changed_files): | ||
file_name = match.group(1) | ||
|
||
# Filtering for C/C++ files and excluding certain directories | ||
if file_name.endswith((".c", ".cpp", ".h", ".hpp")) and all( | ||
excluded not in file_name | ||
for excluded in [ | ||
"doc/", | ||
"test_utils/", | ||
"test/", | ||
"tests/", | ||
"unit_test", | ||
"perf_test", | ||
"example/", | ||
"examples/", | ||
] | ||
): | ||
# Find the lines that changed for this file | ||
lines_start_at = match.end() | ||
next_file_match = file_pattern.search(changed_files, pos=match.span(0)[1]) | ||
|
||
# Slice out the part of the diff that pertains to this file | ||
file_diff = changed_files[ | ||
lines_start_at : next_file_match.span(0)[0] if next_file_match else None | ||
] | ||
|
||
# Extract line numbers of the changes | ||
changed_lines = [] | ||
for line_match in line_pattern.finditer(file_diff): | ||
start_line = int(line_match.group(1)) | ||
num_lines = int(line_match.group(2) or 1) | ||
|
||
# The start and end positions for this chunk of diff | ||
chunk_start = line_match.end() | ||
next_chunk = line_pattern.search(file_diff, pos=line_match.span(0)[1]) | ||
chunk_diff = file_diff[ | ||
chunk_start : next_chunk.span(0)[0] if next_chunk else None | ||
] | ||
|
||
lines = chunk_diff.splitlines() | ||
line_counter = 0 | ||
for line in lines: | ||
if line.startswith("+"): | ||
if ( | ||
"MPI_COMM_WORLD" in line | ||
and not "CHECK: ALLOW MPI_COMM_WORLD" in line | ||
): | ||
# Only include lines where "MPI_COMM_WORLD" is added | ||
# and "CHECK: ALLOW MPI_COMM_WORLD" is not present | ||
changed_lines.append(start_line + line_counter) | ||
|
||
line_counter += 1 | ||
|
||
if changed_lines: | ||
files[file_name] = changed_lines | ||
|
||
return files | ||
|
||
|
||
def get_common_ancestor(target_branch, feature_branch): | ||
cmd = ["git", "merge-base", target_branch, feature_branch] | ||
return subprocess.check_output(cmd).decode("utf-8").strip() | ||
|
||
|
||
def get_changed_files(target_branch, feature_branch): | ||
"""Get a dictionary of files and their changed lines between the common ancestor and feature_branch.""" | ||
start_commit = get_common_ancestor(target_branch, feature_branch) | ||
cmd = [ | ||
"git", | ||
"diff", | ||
"-U0", | ||
"--ignore-all-space", | ||
start_commit, | ||
feature_branch | ||
] | ||
result = subprocess.check_output(cmd).decode("utf-8") | ||
|
||
return parse_diff_output(result) | ||
|
||
|
||
def print_occurences(changed_files, title): | ||
print(title) | ||
for file_name, lines in changed_files.items(): | ||
print("-----") | ||
print(f"File: {file_name}") | ||
print("Changed Lines:", ", ".join(map(str, lines))) | ||
print("-----") | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
|
||
parser.add_argument( | ||
"--base", default="origin/develop", help="BASE commit (default: %(default)s)" | ||
) | ||
parser.add_argument( | ||
"--head", default="HEAD", help="HEAD commit (default: %(default)s)" | ||
) | ||
|
||
start_commit = parser.parse_args().base | ||
print(f"Start commit: {start_commit}") | ||
|
||
end_commit = parser.parse_args().head | ||
print(f"End commit: {end_commit}") | ||
|
||
mpi_comm_world_detected = get_changed_files(start_commit, end_commit) | ||
|
||
if mpi_comm_world_detected: | ||
print_occurences( | ||
mpi_comm_world_detected, "Detected MPI_COMM_WORLD in the following files:" | ||
) | ||
|
||
sys.exit(1) # Exit with an error code to fail the GitHub Action | ||
else: | ||
print("No addition of MPI_COMM_WORLD detected.") | ||
sys.exit(0) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.