Skip to content

Commit

Permalink
Merge 'trilinos/Trilinos:develop' (73dcc21) into 'tcad-charon/Trilino…
Browse files Browse the repository at this point in the history
…s:develop' (6fabf51).

* trilinos-develop: (30 commits)
  Stokhos: update for new KokkosSparse::spmv overloads
  MueLu: Adding finer grained profiling regions for H2D/D2H diagnosis
  Update detect-mpi-comm-world.yml
  Delete mybadfile.c
  Rename mybadfile to mybadfile.c
  Rename check to be 'codestyle'
  Delete mygoodfile
  Delete probited-strings.yml
  Framework: Create GitHub action check for detecting addition of MPI_COMM_WORLD
  Update probited-strings.yml
  Update probited-strings.yml
  Update probited-strings.yml
  Update probited-strings.yml
  Update probited-strings.yml
  Add/move testing files
  Update probited-strings.yml
  Update probited-strings.yml
  Update probited-strings.yml
  Update probited-strings.yml
  Update probited-strings.yml
  ...
  • Loading branch information
prwolfe committed Sep 2, 2023
2 parents 6fabf51 + 73dcc21 commit 8ca5e24
Show file tree
Hide file tree
Showing 6 changed files with 273 additions and 16 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/detect-mpi-comm-world.yml
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 }}
131 changes: 131 additions & 0 deletions commonTools/test/utilities/check-mpi-comm-world-usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
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("+"):
line_counter += 1
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)

if changed_lines:
files[file_name] = changed_lines

return files


def get_changed_files_uncommitted():
"""Get a dictionary of files and their changed lines where MPI_COMM_WORLD was added from uncommitted changes."""
cmd = ["git", "diff", "-U0", "--ignore-all-space", "HEAD"]
result = subprocess.check_output(cmd).decode("utf-8")

return parse_diff_output(result)


def get_changed_files(start_commit, end_commit):
"""Get a dictionary of files and their changed lines between two commits where MPI_COMM_WORLD was added."""
cmd = ["git", "diff", "-U0", "--ignore-all-space", start_commit, end_commit]
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}")

commited_occurences = get_changed_files(start_commit, end_commit)
uncommited_occurences = get_changed_files_uncommitted()

mpi_comm_world_detected = commited_occurences or uncommited_occurences

if mpi_comm_world_detected:
if commited_occurences:
print_occurences(
commited_occurences, "Detected MPI_COMM_WORLD in the following files:"
)
if uncommited_occurences:
print_occurences(
uncommited_occurences,
"Detected MPI_COMM_WORLD in the following files (uncommited changes):",
)

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)
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ namespace MueLu {
}
// NOTE: If the communicator is restricted away, Build returns Teuchos::null.
XpetraList.set("Timer Label","MueLu::RebalanceAc-" + Teuchos::toString(coarseLevel.GetLevelID()));
rebalancedAc = MatrixFactory::Build(originalAc, *rebalanceImporter, *rebalanceImporter, targetMap, targetMap, rcp(&XpetraList,false));
{
SubFactoryMonitor subM2(*this, "Rebalancing existing Ac: MatrixFactory::Build", coarseLevel);
rebalancedAc = MatrixFactory::Build(originalAc, *rebalanceImporter, *rebalanceImporter, targetMap, targetMap, rcp(&XpetraList,false));
}

if (!rebalancedAc.is_null()) {
rebalancedAc->SetFixedBlockSize(originalAc->GetFixedBlockSize());
Expand Down
39 changes: 24 additions & 15 deletions packages/muelu/src/Rebalancing/MueLu_RepartitionFactory_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,22 +296,26 @@ namespace MueLu {

// Step 1: Find out how many processors send me data
// partsIndexBase starts from zero, as the processors ids start from zero
GO partsIndexBase = 0;
RCP<Map> partsIHave = MapFactory ::Build(lib, Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid(), myParts(), partsIndexBase, comm);
RCP<Map> partsIOwn = MapFactory ::Build(lib, numProcs, myPart(), partsIndexBase, comm);
RCP<Export> partsExport = ExportFactory::Build(partsIHave, partsIOwn);

RCP<GOVector> partsISend = Xpetra::VectorFactory<GO, LO, GO, NO>::Build(partsIHave);
RCP<GOVector> numPartsIRecv = Xpetra::VectorFactory<GO, LO, GO, NO>::Build(partsIOwn);
if (numSend) {
ArrayRCP<GO> partsISendData = partsISend->getDataNonConst(0);
for (int i = 0; i < numSend; i++)
partsISendData[i] = 1;
{
SubFactoryMonitor m1(*this, "Mapping Step 1", currentLevel);
GO partsIndexBase = 0;
RCP<Map> partsIHave = MapFactory ::Build(lib, Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid(), myParts(), partsIndexBase, comm);
RCP<Map> partsIOwn = MapFactory ::Build(lib, numProcs, myPart(), partsIndexBase, comm);
RCP<Export> partsExport = ExportFactory::Build(partsIHave, partsIOwn);

RCP<GOVector> partsISend = Xpetra::VectorFactory<GO, LO, GO, NO>::Build(partsIHave);
RCP<GOVector> numPartsIRecv = Xpetra::VectorFactory<GO, LO, GO, NO>::Build(partsIOwn);
if (numSend) {
ArrayRCP<GO> partsISendData = partsISend->getDataNonConst(0);
for (int i = 0; i < numSend; i++)
partsISendData[i] = 1;
}
(numPartsIRecv->getDataNonConst(0))[0] = 0;

numPartsIRecv->doExport(*partsISend, *partsExport, Xpetra::ADD);
numRecv = (numPartsIRecv->getData(0))[0];
}
(numPartsIRecv->getDataNonConst(0))[0] = 0;

numPartsIRecv->doExport(*partsISend, *partsExport, Xpetra::ADD);
numRecv = (numPartsIRecv->getData(0))[0];

// Step 2: Get my GIDs from everybody else
MPI_Datatype MpiType = Teuchos::Details::MpiTypeTraits<GO>::getType();
Expand Down Expand Up @@ -359,7 +363,12 @@ namespace MueLu {
std::sort(myGIDs.begin(), myGIDs.end());

// Step 3: Construct importer
RCP<Map> newRowMap = MapFactory ::Build(lib, rowMap->getGlobalNumElements(), myGIDs(), indexBase, origComm);
RCP<Map> newRowMap;
{
SubFactoryMonitor m1(*this, "Map construction", currentLevel);
newRowMap = MapFactory ::Build(lib, rowMap->getGlobalNumElements(), myGIDs(), indexBase, origComm);
}

RCP<const Import> rowMapImporter;

RCP<const BlockedMap> blockedRowMap = Teuchos::rcp_dynamic_cast<const BlockedMap>(rowMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,53 @@ spmv(
spmv(mode, a, A, x, b, y, RANK_TWO());
}

template <typename AlphaType,
typename BetaType,
typename MatrixType,
typename InputType,
typename ... InputP,
typename OutputType,
typename ... OutputP>
std::enable_if_t<
Kokkos::is_view_uq_pce< Kokkos::View< InputType, InputP... > >::value &&
Kokkos::is_view_uq_pce< Kokkos::View< OutputType, OutputP... > >::value &&
KokkosSparse::is_crs_matrix<MatrixType>::value>
spmv(
KokkosKernels::Experimental::Controls controls,
const char mode[],
const AlphaType& a,
const MatrixType& A,
const Kokkos::View< InputType, InputP... >& x,
const BetaType& b,
const Kokkos::View< OutputType, OutputP... >& y)
{
using RANK_SPECIALISE = std::conditional_t<std::decay_t<decltype(x)>::rank == 2, RANK_TWO, RANK_ONE>;
spmv(controls, mode, a, A, x, b, y, RANK_SPECIALISE());
}

template <typename AlphaType,
typename BetaType,
typename MatrixType,
typename InputType,
typename ... InputP,
typename OutputType,
typename ... OutputP>
std::enable_if_t<
Kokkos::is_view_uq_pce< Kokkos::View< InputType, InputP... > >::value &&
Kokkos::is_view_uq_pce< Kokkos::View< OutputType, OutputP... > >::value &&
KokkosSparse::is_crs_matrix<MatrixType>::value>
spmv(
const char mode[],
const AlphaType& a,
const MatrixType& A,
const Kokkos::View< InputType, InputP... >& x,
const BetaType& b,
const Kokkos::View< OutputType, OutputP... >& y)
{
using RANK_SPECIALISE = std::conditional_t<std::decay_t<decltype(x)>::rank == 2, RANK_TWO, RANK_ONE>;
spmv(mode, a, A, x, b, y, RANK_SPECIALISE());
}

}

#endif /* #ifndef KOKKOS_CRSMATRIX_UQ_PCE_HPP */
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,53 @@ spmv(
spmv(mode, a, A, x, b, y, RANK_TWO());
}

template <typename AlphaType,
typename BetaType,
typename MatrixType,
typename InputType,
typename ... InputP,
typename OutputType,
typename ... OutputP>
std::enable_if_t<
Kokkos::is_view_mp_vector< Kokkos::View< InputType, InputP... > >::value &&
Kokkos::is_view_mp_vector< Kokkos::View< OutputType, OutputP... > >::value &&
KokkosSparse::is_crs_matrix<MatrixType>::value>
spmv(
KokkosKernels::Experimental::Controls controls,
const char mode[],
const AlphaType& a,
const MatrixType& A,
const Kokkos::View< InputType, InputP... >& x,
const BetaType& b,
const Kokkos::View< OutputType, OutputP... >& y)
{
using RANK_SPECIALISE = std::conditional_t<std::decay_t<decltype(x)>::rank == 2, RANK_TWO, RANK_ONE>;
spmv(controls, mode, a, A, x, b, y, RANK_SPECIALISE());
}

template <typename AlphaType,
typename BetaType,
typename MatrixType,
typename InputType,
typename ... InputP,
typename OutputType,
typename ... OutputP>
std::enable_if_t<
Kokkos::is_view_mp_vector< Kokkos::View< InputType, InputP... > >::value &&
Kokkos::is_view_mp_vector< Kokkos::View< OutputType, OutputP... > >::value &&
KokkosSparse::is_crs_matrix<MatrixType>::value>
spmv(
const char mode[],
const AlphaType& a,
const MatrixType& A,
const Kokkos::View< InputType, InputP... >& x,
const BetaType& b,
const Kokkos::View< OutputType, OutputP... >& y)
{
using RANK_SPECIALISE = std::conditional_t<std::decay_t<decltype(x)>::rank == 2, RANK_TWO, RANK_ONE>;
spmv(mode, a, A, x, b, y, RANK_SPECIALISE());
}

}

#endif /* #ifndef KOKKOS_CRSMATRIX_MP_VECTOR_HPP */

0 comments on commit 8ca5e24

Please sign in to comment.