Skip to content
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

Code cleanup (using namespace std) #260

Merged
merged 35 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ef0eaf7
Get rid of using namespace std in tools files
HomesGH May 24, 2023
cb4c493
Get rid of using namespace std in src files
HomesGH May 24, 2023
7d843e4
Add checks for various cases
HomesGH May 24, 2023
c6eac0a
Fix compiling errors regarding std::
HomesGH May 24, 2023
6d52afb
Remove src/MarDyn_version.h as it is generated automatically
HomesGH May 24, 2023
ef56cef
Fixes regarding std::
HomesGH May 24, 2023
86e8ab3
Fix in static code analysis script
HomesGH May 24, 2023
8b43b70
Fix in static code analysis script
HomesGH May 24, 2023
f147e77
Merge branch 'codeCleanup' of https://github.com/ls1mardyn/ls1-mardyn…
HomesGH May 24, 2023
c879bf8
Fix of std:: in python files
HomesGH May 25, 2023
e6cd790
remove and use Log::global_log everywhere
FG-TUM May 26, 2023
35ee376
Add CI check for static code analysis
HomesGH May 26, 2023
5fd975d
Fix in CI
HomesGH May 26, 2023
eb58e92
Fix in CI (indent)
HomesGH May 26, 2023
c6b7edc
Fix in CI (print)
HomesGH May 26, 2023
0968d1f
CI Static code analysis: make checkout master work
HomesGH May 26, 2023
b06a0c6
CI Static code analysis: cleanup
HomesGH May 26, 2023
3fcea1b
CI job summary - use Markdown
HomesGH May 26, 2023
0d6f851
CI - further cleanup
HomesGH May 26, 2023
217cc56
CI - final cleanup
HomesGH May 26, 2023
12cb3c4
Update static code analysis script
HomesGH Jun 9, 2023
544be4e
Smaller formatting and fix some warnings to trigger CI
HomesGH Jun 12, 2023
148ab42
Fix in static code analysis script
HomesGH Jun 12, 2023
7cca072
Add newline if missing
HomesGH Jun 12, 2023
c416d09
Replace CRLF line endings
HomesGH Jun 12, 2023
7577212
Merge branch 'master' into codeCleanup
FG-TUM Jun 12, 2023
5db9788
add missing namespace prefix
FG-TUM Jun 12, 2023
bca7c93
more missing namespaces
FG-TUM Jun 12, 2023
e8835b4
add missing line endings and convert CRLFs
FG-TUM Jun 12, 2023
720a367
purge all trailing whitespaces
FG-TUM Jun 12, 2023
ed1c7ea
chop some long lines
FG-TUM Jun 12, 2023
4ac864f
fix include order
FG-TUM Jun 12, 2023
28dfeba
remove one redundant empty line
FG-TUM Jun 12, 2023
2b41ba2
Merge branch 'master' into codeCleanup
HomesGH Oct 10, 2023
89e9198
Remove pre-tests with cpplint
HomesGH Oct 10, 2023
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
21 changes: 21 additions & 0 deletions .github/workflows/ls1_staticCodeAnalysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Static-Code-Analysis

on:
push:
# pushes to master
branches: [ master ]
pull_request:
# PRs to master
branches: [ master ]

jobs:
static_analysis:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup
run: |
sudo apt-get update
sudo apt-get install -y cpplint
- name: Run static code analysis script
run: ./checks/run-staticAnalysis.sh $PWD
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ src/MarDyn
src/MarDyn.*
!src/MarDyn.cpp
src/MarDyn_*.*
!src/MarDyn_version.h*
.project
.settings
*.so.1.0
*.a
*.so
doxygen_doc/
__pycache__/
__pycache__/
52 changes: 52 additions & 0 deletions checks/check-buildOptions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
# Script to test the building process by altering through different build options
# It uses the default settings and sets the specified options one by one

numJobs=20

checkFolder=$PWD
buildFolder=$PWD/../build_test_$(date '+%Y-%m-%d')

declare -A optionsList

optionsList[ENABLE_MPI]=ON
optionsList[VECTOR_INSTRUCTIONS]=SSE
optionsList[VECTOR_INSTRUCTIONS]=AVX2
optionsList[CMAKE_BUILD_TYPE]=Debug
optionsList[OPENMP]=ON
optionsList[ENABLE_AUTOPAS]=ON
optionsList[ENABLE_UNIT_TESTS]=ON
optionsList[QUICKSCHED]=ON
optionsList[FMM_FFT]=ON
optionsList[WITH_PAPI]=ON
optionsList[ENABLE_ALLLBL]=ON
optionsList[ENABLE_VTK]=ON
optionsList[REDUCED_MEMORY_MODE]=ON


# CMAKE
mkdir -p $buildFolder
cd $buildFolder

echo "Running CMAKE in folder: $buildFolder"

for option in "${!optionsList[@]}"
do
echo " Running option: ${option}=${optionsList[${option}]}"
rm $buildFolder/* -rf
( CC=mpicc CXX=mpicxx cmake -D${option}=${optionsList[${option}]} .. && make -j${numJobs} ; echo "$?" ) &> $checkFolder/build_test_cmake_${option}.log
done


# MAKE
cd $checkFolder/../src

echo "Running make in src"

for option in "${!optionsList[@]}"
do
echo " Running option: ${option}=${optionsList[${option}]}"
make clean &> /dev/null
( make -j${numJobs} -f Makefile ${option}=${optionsList[${option}]} ; echo "$?" ) &> $checkFolder/build_test_make_${option}.log
done

120 changes: 120 additions & 0 deletions checks/run-staticAnalysis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#!/bin/bash
# Script to run static code analysis

#set strict pipefail option
#set -eo pipefail

# A path to the root folder of ls1 mardyn can be set via an argument; if not, the parent folder of "checks" is used
if [ $# -eq 1 ]
then
rootFolder=$1
else
rootFolder=$PWD/..
fi

echo "Running in $rootFolder"

warnings=""

codeFiles=$( find $rootFolder/src -name "*.h" -or -name "*.cpp" -printf "%p " )

# Similar to check_format of MegaMol repo
for file in $codeFiles; do

# Check if using namespace std is used
if grep -q "using namespace std;" "$file"; then
echo "\"using namespace std;\" was used in $file"
warnings+="Do not use \"using namespace std;\"\n"
fi

# Check if using Log::global_log is used
if grep -q "using namespace std;" "$file"; then
echo "\"using Log::global_log;\" was used in $file"
HomesGH marked this conversation as resolved.
Show resolved Hide resolved
warnings+="Do not use \"using Log::global_log;\"\n"
fi

# Check if file is UTF-8 (or ASCII)
encoding=$(file -b --mime-encoding "$file")
if [[ $encoding != "us-ascii" && $encoding != "utf-8" ]]; then
# Fix
#tmp_file=$(mktemp)
#iconv -f "$encoding" -t utf-8 -o "$tmp_file" "$file"
#mv -f "$tmp_file" "$file"
HomesGH marked this conversation as resolved.
Show resolved Hide resolved
echo "The following file is not ASCII/UTF-8 encoded: $file"
warnings+="At least one file is not ASCII/UTF-8 encoded\n"
fi

# Check if file contains CRLF line endings
fileinfo=$(file -k "$file")
if [[ $fileinfo == *"CRLF"* ]]; then
# Fix
#sed -i 's/\r$//' "$file"
echo "The following file contains CRLF line endings: $file"
warnings+="At least one file contains CRLF line endings\n"
fi

# Check if file starts with BOM
if [[ $fileinfo == *"BOM"* ]]; then
# Fix
#sed -i '1s/^\xEF\xBB\xBF//' "$file"
echo "The following file starts with BOM: $file"
warnings+="At least one file starts with BOM\n"
fi

# Check if file ends with newline
if [[ -n "$(tail -c 1 "$file")" ]]; then
# Fix
#sed -i -e '$a\' "$file"
echo "The following file does not end with newline: $file"
warnings+="At least one file does not end with newline\n"
fi

done

# Only print warnings once
warnings=$(printf "$warnings" | sort | uniq)
warnings="# Warnings\n"$warnings"\n\n"

# Run cpplint

# Lines starting with one minus sign are filters which exclude certain rules

#-runtime/int,\
#-readability/alt_tokens,\
#-whitespace/blank_line,\
#-whitespace/braces,\
#-whitespace/comma,\
#-whitespace/comments,\
#-whitespace/indent,\
#-whitespace/operators,\
#-whitespace/parens,\

currentVersion=$(git rev-parse --abbrev-ref HEAD)

for VERSION in "new" "master"
do
echo "Checking ${VERSION} version"

if [[ "${VERSION}" == "master" ]]
then
git fetch &> /dev/null
git switch master &> /dev/null
else
git switch ${currentVersion} &> /dev/null
fi

cpplint --filter=-whitespace/tab --linelength=200 --counting=detailed ${codeFiles} &> $rootFolder/staticAnalysis_${VERSION}.log

grep "Category\|Total errors found" $rootFolder/staticAnalysis_${VERSION}.log > $rootFolder/staticAnalysis_${VERSION}_summary.log

done

git switch ${currentVersion} &> /dev/null

warnings+="\n# cpplint\n New or fixed warnings/errors (master <-> new commit):\n\`\`\`master $(printf '%54s' " ") | new\n"

# Delete "--suppress-common-lines" to see all errors/warnings
warnings+=$(diff -y --suppress-common-lines $rootFolder/staticAnalysis_master_summary.log $rootFolder/staticAnalysis_new_summary.log)

printf "\n\n$warnings\n"
printf "$warnings\`\`\`\n" >> $GITHUB_STEP_SUMMARY
31 changes: 31 additions & 0 deletions checks/run-validation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# Testscript running validation tests according to GitHub Actions but without comparison to master
#
# Copyright (c) 2023 Simon Homes
#

repoPath="$PWD/.." # Path to root directory

export OMP_NUM_THREADS=2

logfileName="${repoPath}/examples/run-validation.log"
rm -f ${logfileName}

IFS=$'\n'
for i in $(cat "${repoPath}/examples/example-list.txt" )
do
# skip if comment or empty line
if [[ $i == \#* || -z "$i" ]]
then
continue
fi
cd ${repoPath}/examples/$(dirname $i)

# run the examples
printf "Running example: ${i} ... " | tee -a ${logfileName}
EXE=${repoPath}/build/src/MarDyn

mpirun --oversubscribe -np 4 ${EXE} $(basename $i) --steps=20 | tee -a ${logfileName}
printf "done\n"
done

4 changes: 2 additions & 2 deletions src/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ void calculateDistances( float * __restrict__ valuesA[3], float* __restrict__ co
float ** __restrict__ distances, float *** __restrict__ distanceVectors ) {

/* for (int i = 0; i < numValuesA; i++) {
std::cout << "A Points: " << valuesA[0][i] << "," << valuesA[1][i] << "," << valuesA[2][i] << endl;
std::cout << "A Points: " << valuesA[0][i] << "," << valuesA[1][i] << "," << valuesA[2][i] << std::endl;
}
for (int i = 0; i < numValuesB; i++) {
std::cout << "B Points: " << valuesB[0][i] << "," << valuesB[1][i] << "," << valuesB[2][i] << endl;
std::cout << "B Points: " << valuesB[0][i] << "," << valuesB[1][i] << "," << valuesB[2][i] << std::endl;
}
*/

Expand Down
Loading