Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions .github/workflows/single-platform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Build and Run Unit Tests

on:
push:
branches: [ "main", "dane_dev" ]
pull_request:
branches: [ "main", "dane_dev" ]

jobs:
testMPI:
runs-on: ubuntu-latest
# Define a build matrix over compilers
strategy:
matrix:
compiler: [GCC, ICC, CLANG]

steps:
# 1) Check out the repository code
- name: Checkout repository
uses: actions/checkout@v4

# 2) Set up Spack for package management
- name: Set-up Spack
uses: spack/setup-spack@v2
with:
ref: develop # Use the 'develop' branch of the spack/setup-spack action
buildcache: true # Enable Spack binary cache
color: true # Enable colored output
path: spack # Install Spack under ./spack directory

# 3) Install necessary compiler and MPI packages via Spack
- name: Install Compilers and MPI Wrappers
run: |
# Source Spack environment to get spack commands
. ./spack/share/spack/setup-env.sh

# Based on matrix.compiler, install the right packages
case "${{ matrix.compiler }}" in
GCC)
# Install OpenMPI for GCC
spack install -j 4 openmpi;;
ICC)
# Install Intel compilers and Intel MPI
spack install -j 4 intel-oneapi-compilers
spack install -j 4 intel-oneapi-mpi;;
CLANG)
# Install LLVM/Clang and OpenMPI
spack install -j 4 llvm
spack install -j 4 openmpi;;
esac

# 4) Configure, build, and run tests in one step to preserve environment
- name: Configure and Make SparseBench Tests
run: |
# Re-source Spack so we have spack load available
. ./spack/share/spack/setup-env.sh

# Based on matrix.compiler, load the correct compiler/MPI into this shell
case "${{ matrix.compiler }}" in
GCC)
# Load OpenMPI for GCC
eval "$(spack load --sh openmpi)";;
ICC)
# Load Intel compilers and Intel MPI
eval "$(spack load --sh intel-oneapi-compilers)"
eval "$(spack load --sh intel-oneapi-mpi)";;
CLANG)
# Load LLVM/Clang and OpenMPI
eval "$(spack load --sh llvm)"
eval "$(spack load --sh openmpi)";;
esac

# Export TOOLCHAIN for the Makefile
export TOOLCHAIN="${{ matrix.compiler }}"

# Define reusable logic
run_tests() {
local FMT=$1
echo ">>> Building and testing with $FMT matrix format."

sed -E -i \
-e 's/^(ENABLE_MPI[[:space:]]*\?=[[:space:]]*).*/\1true/' \
-e 's/^(ENABLE_OPENMP[[:space:]]*\?=[[:space:]]*).*/\1false/' \
-e "s/^(MTX_FMT[[:space:]]*\?=[[:space:]]*).*/\1${FMT}/" \
-e "s/^(TOOLCHAIN[[:space:]]*\?=[[:space:]]*).*/\1${TOOLCHAIN}/" \
config.mk

# Build (MPI-only) sparseBench
make

# Build tests
cd tests && make clean && make

# Run (single rank) tests
mpirun -n 1 ./runTests
cd ..
}

# Run tests with both formats
run_tests CRS
run_tests SCS
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ tests/runTests
tests/*.o
tests/matrix/*.o
tests/data/reported/*
!tests/data/reported/.gitignore
5 changes: 4 additions & 1 deletion mk/include_CLANG.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ OPENMP = -fopenmp
#OPENMP = -Xpreprocessor -fopenmp #required on Macos with homebrew libomp
endif

# Set default
C_VERSION = c17

VERSION = --version
CFLAGS = -O3 -ffast-math -std=c23 $(OPENMP)
CFLAGS = -O3 -ffast-math -std=$(C_VERSION) $(OPENMP)
# CFLAGS = -O0 -g -std=c99 $(OPENMP)
LFLAGS = $(OPENMP)
DEFINES += -D_GNU_SOURCE
Expand Down
5 changes: 4 additions & 1 deletion mk/include_GCC.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ ifeq ($(strip $(ENABLE_OPENMP)),true)
OPENMP = -fopenmp
endif

# Set default
C_VERSION = c17

VERSION = --version
CFLAGS = -O3 -ffast-math -std=c23 $(OPENMP)
CFLAGS = -O3 -ffast-math -std=$(C_VERSION) $(OPENMP)
# CFLAGS = -O0 -g -std=c99 $(OPENMP)
LFLAGS = $(OPENMP)
DEFINES += -D_GNU_SOURCE # -DVERBOSE
Expand Down
5 changes: 4 additions & 1 deletion mk/include_ICC.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ ifeq ($(strip $(ENABLE_OPENMP)),true)
OPENMP = -qopenmp
endif

# Set default
C_VERSION = c17

VERSION = --version
CFLAGS = -O3 -ffast-math -xHost -std=c23 $(OPENMP)
CFLAGS = -O3 -ffast-math -xHost -std=$(C_VERSION) $(OPENMP)
# CFLAGS = -O0 -g -std=c99 $(OPENMP)
LFLAGS = $(OPENMP)
DEFINES += -D_GNU_SOURCE # -DVERBOSE
Expand Down
79 changes: 41 additions & 38 deletions src/comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ void commPrintConfig(
#endif
}

// TODO: Unify matrix dumping
void commMatrixDump(Comm* c, Matrix* m)
{
int rank = c->rank;
Expand All @@ -726,81 +727,83 @@ void commMatrixDump(Comm* c, Matrix* m)
CG_FLOAT* val = m->val;

if (commIsMaster(c)) {
printf("Matrix: %d total non zeroes, total number of rows %d\n",
fprintf(c->logFile,
"Matrix: %d total non zeroes, total number of rows %d\n",
m->totalNnz,
m->totalNr);
}

for (int i = 0; i < size; i++) {
if (i == rank) {
printf("Rank %d: number of rows %d\n", rank, numRows);
fprintf(c->logFile, "Rank %d: number of rows %d\n", rank, numRows);

for (int rowID = 0; rowID < numRows; rowID++) {
printf("Row [%d]: ", rowID);
fprintf(c->logFile, "Row [%d]: ", rowID);

for (int rowEntry = rowPtr[rowID]; rowEntry < rowPtr[rowID + 1];
rowEntry++) {
printf("[%d]:%.2f ", colInd[rowEntry], val[rowEntry]);
fprintf(c->logFile, "[%d]:%.2f ", colInd[rowEntry], val[rowEntry]);
}

printf("\n");
fprintf(c->logFile, "\n");
}
fflush(stdout);
fflush(c->logFile);
}
#ifdef _MPI
MPI_Barrier(MPI_COMM_WORLD);
#endif
}
#endif /* ifdef CRS */
#ifdef SCS
printf("m->startRow = %d\n", m->startRow);
printf("m->stopRow = %d\n", m->stopRow);
printf("m->totalNr = %d\n", m->totalNr);
printf("m->totalNnz = %d\n", m->totalNnz);
printf("m->nr = %d\n", m->nr);
printf("m->nc = %d\n", m->nc);
printf("m->nnz = %d\n", m->nnz);
printf("m->C = %d\n", m->C);
printf("m->sigma = %d\n", m->sigma);
printf("m->nChunks = %d\n", m->nChunks);
printf("m->nrPadded = %d\n", m->nrPadded);
fprintf(c->logFile, "m->startRow = %d\n", m->startRow);
fprintf(c->logFile, "m->stopRow = %d\n", m->stopRow);
fprintf(c->logFile, "m->totalNr = %d\n", m->totalNr);
fprintf(c->logFile, "m->totalNnz = %d\n", m->totalNnz);
fprintf(c->logFile, "m->nr = %d\n", m->nr);
fprintf(c->logFile, "m->nc = %d\n", m->nc);
fprintf(c->logFile, "m->nnz = %d\n", m->nnz);
fprintf(c->logFile, "m->C = %d\n", m->C);
fprintf(c->logFile, "m->sigma = %d\n", m->sigma);
fprintf(c->logFile, "m->nChunks = %d\n", m->nChunks);
fprintf(c->logFile, "m->nrPadded = %d\n", m->nrPadded);
fprintf(c->logFile, "m->nElems = %d\n", m->nElems);

// Dump permutation arrays
printf("oldToNewPerm: ");
fprintf(c->logFile, "oldToNewPerm: ");
for (int i = 0; i < m->nr; ++i) {
printf("%d, ", m->oldToNewPerm[i]);
fprintf(c->logFile, "%d, ", m->oldToNewPerm[i]);
}
printf("\n");
printf("newToOldPerm: ");
fprintf(c->logFile, "\n");
fprintf(c->logFile, "newToOldPerm: ");
for (int i = 0; i < m->nr; ++i) {
printf("%d, ", m->newToOldPerm[i]);
fprintf(c->logFile, "%d, ", m->newToOldPerm[i]);
}
printf("\n");
fprintf(c->logFile, "\n");

// Dump chunk data
printf("chunkLens: ");
fprintf(c->logFile, "chunkLens: ");
for (int i = 0; i < m->nChunks; ++i) {
printf("%d, ", m->chunkLens[i]);
fprintf(c->logFile, "%d, ", m->chunkLens[i]);
}
printf("\n");
printf("chunkPtr: ");
fprintf(c->logFile, "\n");
fprintf(c->logFile, "chunkPtr: ");
for (int i = 0; i < m->nChunks + 1; ++i) {
printf("%d, ", m->chunkPtr[i]);
fprintf(c->logFile, "%d, ", m->chunkPtr[i]);
}
printf("\n");
fprintf(c->logFile, "\n");

// Dump matrix data
printf("colInd: ");
fprintf(c->logFile, "colInd: ");
for (int i = 0; i < m->nElems; ++i) {
printf("%d, ", m->colInd[i]);
fprintf(c->logFile, "%d, ", m->colInd[i]);
}
printf("\n");
printf("val: ");
fprintf(c->logFile, "\n");
fprintf(c->logFile, "val: ");
for (int i = 0; i < m->nElems; ++i) {
printf("%f, ", m->val[i]);
fprintf(c->logFile, "%f, ", m->val[i]);
}
printf("\n");
fprintf(c->logFile, "\n");
#endif /* ifdef SCS */
#ifdef _MPI
MPI_Barrier(MPI_COMM_WORLD);
#endif
}

void commVectorDump(Comm* c, CG_FLOAT* v, CG_UINT size, char* name)
Expand Down
4 changes: 2 additions & 2 deletions src/matrix-SCS.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ void convertMatrix(Matrix* m, GMatrix* im)
m->nnz = im->nnz;
m->nChunks = (m->nr + m->C - 1) / m->C;
m->nrPadded = m->nChunks * m->C;
m->C = (CG_UINT)1;
m->sigma = (CG_UINT)1;
// m->C = (CG_UINT)1;
// m->sigma = (CG_UINT)1;

// (Temporary array) Assign an index to each row to use for row sorting
SellCSigmaPair* elemsPerRow = (SellCSigmaPair*)allocate(ARRAY_ALIGNMENT,
Expand Down
20 changes: 13 additions & 7 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# # # DL 2025.04.04
# # # DL 2025.06.25
# # # Collection of unit tests

include ../config.mk
include ../mk/include_$(TOOLCHAIN).mk

BUILD_DIR=../build
TC_DIR=${BUILD_DIR}/$(TOOLCHAIN)
TC_DIR=${BUILD_DIR}/$(MTX_FMT)-$(TOOLCHAIN)

# List of test modules
MOD1=matrix
Expand All @@ -18,12 +18,18 @@ LINKS := $(filter-out ${TC_DIR}/main.o, $(wildcard ${TC_DIR}/*.o))
TARGET=runTests

# Collect objects from all test modules
MOD1_OBJECTS=${MOD1}/convertSCS.o ${MOD1}/matrixTests.o
MOD2_OBJECTS=${MOD2}/spmvSCS.o ${MOD2}/solverTests.o
MOD1_OBJECTS=${MOD1}/convert$(MTX_FMT).o ${MOD1}/matrixTests.o
MOD2_OBJECTS=${MOD2}/spmv$(MTX_FMT).o ${MOD2}/solverTests.o
OBJECTS := $(shell echo $(MOD1_OBJECTS) $(MOD2_OBJECTS) | tr ' ' '\n' | sort -u | tr '\n' ' ')

# Always leave debugging flag on
CFLAGS=-g -qopenmp
CFLAGS=-g $(DEFINES)

# Only enable OpenMP if it defined in the parent config.mk
ifeq ($(strip $(ENABLE_OPENMP)),true)
CFLAGS += $(OPENMP)
endif
# If enabled, MPI wrappers are already in CC

.PHONY: all clean

Expand All @@ -44,12 +50,12 @@ runTests.o: runTests.c
$(MOD1)/matrixTests.o: $(MOD1)/matrixTests.c
$(CC) $(CFLAGS) -c -o $@ $<

$(MOD1)/convertSCS.o: $(MOD1)/convertSCS.c
$(MOD1)/convert$(MTX_FMT).o: $(MOD1)/convert$(MTX_FMT).c
$(CC) $(CFLAGS) -c -o $@ $<

# Module 2 tests: solver
$(MOD2)/solverTests.o: $(MOD2)/solverTests.c
$(CC) $(CFLAGS) -c -o $@ $<

$(MOD2)/spmvSCS.o: $(MOD2)/spmvSCS.c
$(MOD2)/spmv$(MTX_FMT).o: $(MOD2)/spmv$(MTX_FMT).c
$(CC) $(CFLAGS) -c -o $@ $<
Loading