Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master.dev' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
pnizenkov committed Jun 19, 2023
2 parents c69b6ec + 012e2bf commit 3ba8a07
Show file tree
Hide file tree
Showing 66 changed files with 1,562 additions and 610 deletions.
13 changes: 8 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,14 @@ FOREACH (_var IN LISTS piclasVars piclasVars2 piclasVars3 piclasVars4)
ENDIF()
ENDFOREACH()

# =========================================================================
# HOPR pre-processor
# =========================================================================
OPTION(LIBS_BUILD_HOPR "Build HOPR pre-processor by compiling the source code downloaded from https://github.com/hopr-framework/hopr.git" OFF)
SET(HOPR_TAG "v1.1.1" CACHE STRING "HOPR version tag for downloading the executable or compiling the source code (from GitHub)")
SET(HOPR_DOWNLOAD_URL "https://github.com/hopr-framework/hopr/releases/download/${HOPR_TAG}/hopr-linux64.zip")
OPTION(LIBS_DOWNLOAD_HOPR "Download HOPR pre-processor AppImage executable from ${HOPR_DOWNLOAD_URL}" OFF)

# =========================================================================
# ADD LIBRARIES
# =========================================================================
Expand All @@ -289,11 +297,6 @@ ELSE()
ENDFOREACH()
ENDIF()

# =========================================================================
# HOPR pre-processor
# =========================================================================
OPTION(LIBS_BUILD_HOPR "Build HOPR pre-processor" OFF)

# =========================================================================
# Userblock
# =========================================================================
Expand Down
54 changes: 48 additions & 6 deletions CMakeListsLib.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ STRING(TOLOWER ${LIB_TYPE} SEARCH_TYPE)
# Use system HDF5
IF(NOT LIBS_BUILD_HDF5)
# Unset leftover paths from old CMake runs
UNSET(HDF5_VERSION CACHE)
UNSET(HDF5_LIBRARIES)
UNSET(HDF5_INCLUDE_DIR_FORTRAN)
UNSET(HDF5_INCLUDE_DIR)
Expand Down Expand Up @@ -167,13 +168,16 @@ ELSE()
IF(LIBS_USE_MPI)
# HDF5 1.12.0 and greater is compatible with OpenMPI 4.0.0 and greater
IF("${LIBS_MPI_NAME}" MATCHES "OpenMPI" AND ${MPI_C_LIBRARY_VERSION} VERSION_GREATER_EQUAL "4.0.0")
SET (HDF5_TAG "hdf5-1_12_0" CACHE STRING "HDF5 version tag")
ELSE()
SET (HDF5_TAG "hdf5-1_10_6" CACHE STRING "HDF5 version tag")
ENDIF()
SET (HDF5_TAG "hdf5-1_12_0" CACHE STRING "HDF5 version tag")
SET (HDF5_VERSION "1.12" CACHE INTERNAL "HDF5 version number")
ELSE()
SET (HDF5_TAG "hdf5-1_10_6" CACHE STRING "HDF5 version tag")
SET (HDF5_VERSION "1.10" CACHE INTERNAL "HDF5 version number")
ENDIF()
MESSAGE (STATUS "Setting HDF5 to tag ${HDF5_TAG} to be compatible with detected [${LIBS_MPI_NAME}] (v${MPI_C_LIBRARY_VERSION})")
ELSE()
SET (HDF5_TAG "hdf5-1_12_0" CACHE STRING "HDF5 version tag")
SET (HDF5_TAG "hdf5-1_12_0" CACHE STRING "HDF5 version tag")
SET (HDF5_VERSION "1.12" CACHE INTERNAL "HDF5 version number")
MESSAGE (STATUS "Setting HDF5 to tag ${HDF5_TAG} as no MPI support was requested")
ENDIF()
MARK_AS_ADVANCED(FORCE HDF5_TAG)
Expand Down Expand Up @@ -262,6 +266,12 @@ ELSE()
LIST(APPEND HDF5_LIBRARIES ${HDF5_hdf5_fortran_LIBRARY_RELEASE} ${HDF5_hdf5_LIBRARY_RELEASE} ${HDF5_z_LIBRARY_RELEASE} -ldl)
ENDIF()

# HDF5 1.14 references build directory
# > https://github.com/HDFGroup/hdf5/issues/2422
IF(${HDF5_VERSION} VERSION_EQUAL "1.14")
LIST(FILTER HDF5_INCLUDE_DIR EXCLUDE REGEX "src/H5FDsubfiling")
ENDIF()

# Actually add the HDF5 paths (system/custom built) to the linking paths
# HDF5 build with CMake
IF(LIBS_HDF5_CMAKE)
Expand Down Expand Up @@ -470,7 +480,7 @@ IF(LIBS_BUILD_HOPR)
# Let CMake take care of download, configure and build
EXTERNALPROJECT_ADD(HOPR
GIT_REPOSITORY ${HOPR_DOWNLOAD}
GIT_TAG v1.1.1
GIT_TAG ${HOPR_TAG}
GIT_PROGRESS FALSE
${${GITSHALLOW}}
PREFIX ${LIBS_HOPR_DIR}
Expand All @@ -494,6 +504,38 @@ IF(LIBS_BUILD_HOPR)
ENDIF()
ENDIF()

# Download the HOPR executable directly and place it in the bin folder
IF(LIBS_DOWNLOAD_HOPR)
MESSAGE(STATUS "HOPR executable download from: ${HOPR_DOWNLOAD_URL}")
IF(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/bin/hopr")
MESSAGE(STATUS "HOPR executable not found in: ${CMAKE_CURRENT_BINARY_DIR}/bin/hopr. HOPR will be downloaded/extracted.")
# Check if .zip file has already been downloaded
FILE(GLOB HOPR_ZIP_FILE ${CMAKE_CURRENT_BINARY_DIR}/hopr-*.zip)
IF(NOT EXISTS "${HOPR_ZIP_FILE}")
EXECUTE_PROCESS(COMMAND curl -L -O ${HOPR_DOWNLOAD_URL})
FILE(GLOB HOPR_ZIP_FILE ${CMAKE_CURRENT_BINARY_DIR}/hopr-*.zip)
ENDIF()
# Check if AppImage has already been extracted
FILE(GLOB HOPR_APP_FILE ${CMAKE_CURRENT_BINARY_DIR}/hopr-*.AppImage)
IF(NOT EXISTS "${HOPR_APP_FILE}")
IF(NOT EXISTS "${HOPR_ZIP_FILE}")
MESSAGE(WARNING "FAILED to download hopr .zip file from ${HOPR_DOWNLOAD_URL}")
ELSE()
EXECUTE_PROCESS(COMMAND unzip ${HOPR_ZIP_FILE})
FILE(GLOB HOPR_APP_FILE ${CMAKE_CURRENT_BINARY_DIR}/hopr-*.AppImage)
ENDIF()
ENDIF()
# Check if AppImage file exists and create symbolic link into ./bin
IF(NOT EXISTS "${HOPR_APP_FILE}")
MESSAGE(WARNING "FAILED to extract hopr .zip file")
ELSE()
EXECUTE_PROCESS(COMMAND ln -s ${HOPR_APP_FILE} bin/hopr)
ENDIF()
ELSE()
MESSAGE(STATUS "HOPR executable already exists under ${CMAKE_CURRENT_BINARY_DIR}/bin/hopr")
ENDIF()
ENDIF()

# # =========================================================================
# # PAPI library
# # =========================================================================
Expand Down
4 changes: 2 additions & 2 deletions CMakeListsMachine.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ IF("${PICLAS_INSTRUCTION}" STREQUAL "")
ENDIF()
ENDIF()

MESSAGE(STATUS "Compiling Nitro/Release/Profile with [${CMAKE_Fortran_COMPILER_ID}] (v${CMAKE_Fortran_COMPILER_VERSION}) fortran compiler using [${PICLAS_INSTRUCTION}] instruction")
MESSAGE(STATUS "Compiling Nitro/Release/Profile with [${CMAKE_Fortran_COMPILER_ID}] (v${CMAKE_Fortran_COMPILER_VERSION}) fortran compiler using PICLAS_INSTRUCTION [${PICLAS_INSTRUCTION}] instructions.")

# =========================================================================
# CHECK SUPPORT FOR VARIOUS FORTRAN (2003,2008) FEATURES
Expand Down Expand Up @@ -259,7 +259,7 @@ ELSEIF (CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
# Compile flags depend on the generator
IF(NOT "${CMAKE_GENERATOR}" MATCHES "Ninja")
# add flags only for compiling not linking!
SET (PICLAS_COMPILE_FLAGS "-fPIC-fpp -allow nofpp_comments -assume bscc")
SET (PICLAS_COMPILE_FLAGS "-fPIC -fpp -allow nofpp_comments -assume bscc")
ELSE()
SET (PICLAS_COMPILE_FLAGS "${NINJA_COLOR_DIAGNOSTICS} -allow nofpp_comments -assume bscc")
ENDIF()
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ support the project by citing our publications given in [REFERENCE.md](REFERENCE

The documentation of PICLas can be found in the [User Guide](https://piclas.readthedocs.io/), where the installation procedure is
described in [Chapter 2](https://piclas.readthedocs.io/en/latest/userguide/installation.html).
Pre-compiled executables (that only require pre-installed MPI for parallel execution) for Linux can directly be downloaded as
AppImage containers from the [PICLas release tag assets](https://github.com/piclas-framework/piclas/releases).

## Regression Testing

Expand Down
93 changes: 93 additions & 0 deletions docs/documentation/developerguide/appimage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Building the AppImage Executable

## piclas

Navigate to the piclas repository and create a build directory

mkdir build && cd build

and compile piclas using the following cmake flags

cmake .. -DCMAKE_INSTALL_PREFIX=/usr

and then

make install DESTDIR=AppDir

or when using Ninja run

DESTDIR=AppDir ninja install

Then create an AppImage (and subsequent paths) directory in the build folder

mkdir -p AppDir/usr/share/icons/

and copy the piclas logo into the icons directory

cp ../docs/logo.png AppDir/usr/share/icons/piclas.png

A desktop file should already exist in the top-level directory containing

[Desktop Entry]
Type=Application
Name=piclas
Exec=piclas
Comment=PICLas is a flexible particle-based plasma simulation suite.
Icon=piclas
Categories=Development;
Terminal=true

Next, download the AppImage executable

curl -L -O https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage

and make it executable

chmod +x linuxdeploy-x86_64.AppImage

Then run

./linuxdeploy-x86_64.AppImage --appdir AppDir --output appimage --desktop-file=../.github/workflows/piclas.desktop

The executable should be created in the top-level directory, e.g.,

piclas-ad6830c7a-x86_64.AppImage

## piclas2vtk and other tools

Other tools such as `piclas2vtk` and `superB` etc. are also included in the AppImage container and can be extracted via

./piclas-ad6830c7a-x86_64.AppImage --appimage-extract

The tools are located under `./squashfs-root/usr/bin/`.
To make on those tools the main application of the AppImage, remove the AppDir folder

rm -rf AppDir

and then

make install DESTDIR=AppDir

or when using Ninja run

DESTDIR=AppDir ninja install

and change the following settings, e.g., for `piclas2vtk`

PROG='piclas2vtk'
cp ../.github/workflows/piclas.desktop ${PROG}.desktop
mkdir -p AppDir/usr/share/icons/
cp ../docs/logo.png AppDir/usr/share/icons/${PROG}.png
sed -i -e "s/Name=.*/Name=${PROG}/" ${PROG}.desktop
sed -i -e "s/Exec=.*/Exec=${PROG}/" ${PROG}.desktop
sed -i -e "s/Icon=.*/Icon=${PROG}/" ${PROG}.desktop
./linuxdeploy-x86_64.AppImage --appdir AppDir --output appimage --desktop-file=${PROG}.desktop

This should create

piclas2vtk-ad6830c7a-x86_64.AppImage

## Troubleshooting

If problems occur when executing the AppImage, check the [troubleshooting]( https://docs.appimage.org/user-guide/troubleshooting/index.html)
section for possible fixes.
7 changes: 5 additions & 2 deletions docs/documentation/developerguide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ numbered:
git_workflow.md
building_guide.md
styleguide.md
troubleshooting.md
code_extension.md
functions_and_subroutines.md
mpi.md
Expand All @@ -20,15 +21,16 @@ unittest.md
compiler.md
tools.md
performance.md
appimage.md
examples.md
```

This guide is organized to guide the first implementation steps as well as provide a complete overview of
This guide is organized to guide the first implementation steps as well as provide a complete overview of
the simulation code's features from a developer's point of view.

* The first Chapter {ref}`developerguide/git_workflow:GitLab Workflow` shall give an overview over the development workflow within
the Gitlab environment, and the necessary steps to create a release, deploy updates to the Collaborative Numerics Group and GitHub.
* The second Chapter {ref}`developerguide/styleguide:Style Guide` describes the rules and guidelines regarding code development
* The second Chapter {ref}`developerguide/styleguide:Style Guide` describes the rules and guidelines regarding code development
such as how the header of functions and subroutines look like.
* Chapter {ref}`developerguide/building_guide:Documentation` describes how to build the html/pdf files
locally before committing changes to the repository and pointers on writing documentation.
Expand All @@ -43,5 +45,6 @@ the simulation code's features from a developer's point of view.
* Chapter {ref}`developerguide/tools:Developer Tools` gives an overview over the tools and scripts for developers.
* Chapter {ref}`developerguide/performance:Performance Analysis` describes different tools that can be utilized for measuring the
computational performance
* Chapter {ref}`developerguide/appimage:Building the AppImage Executable` described how an AppImage executable of HOPR is created.
* Chapter {ref}`developerguide/examples:Markdown Examples` gives a short overview of how to include code, equations, figures, tables
etc. in the user and developer guides in Markdown.
78 changes: 78 additions & 0 deletions docs/documentation/developerguide/troubleshooting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Troubleshooting
The following examples are the result of lengthy debugging sessions and can be checked if problems arise during the development
process. Especially when using MPI, the debugging process can be quite cumbersome.


## WriteArrayToHDF5() and the collective flag
**Error Description**
- One or more array elements in a .h5 file are corrupt, e.g., the element contains the value `1.16828195e-314` instead of the expected
value of `7960`

**Necessary Conditions**
- `LIBS_USE_MPI=ON`: the error only occurs when using more than 1 process (a multi-node run with a large number of processes
might yield a high chance to trigger this problem)

**Sufficient Conditions**
- `CALL WriteArrayToHDF5()` with `collective=.TRUE.` but not all processes enter this function

**Finding the Bug**
- This error can be found with a regression test that runs with `LIBS_USE_MPI=OFF` or one process and again with multiple processes
at best using the multi-node feature `PICLAS_SHARED_MEMORY=OMPI_COMM_TYPE_CORE`

**Resolution**
- `CALL WriteArrayToHDF5()` with collective=.FALSE. when it is not 100% certain that all processes enter this routine

**Explanation**
- Setting collective=.TRUE. triggers the usage of `H5FD_MPIO_COLLECTIVE_F` and `collective=.FALSE.` uses `H5FD_MPIO_INDEPENDENT_F` in
`H5PSET_DXPL_MPIO_F(PList_ID, H5FD_MPIO_INDEPENDENT_F, iError)`, which configures the "transfer mode" in the hdf5 output

**git hashes**
- One of these bugs was specifically fixed in
[0b2f7b12ecdf84d095caeb8c4b35e08a8484ce42](https://github.com/piclas-framework/piclas/commit/0b2f7b12ecdf84d095caeb8c4b35e08a8484ce42)


## Seemingly meaningless change in code triggers segmentation fault or slow down of the code
**Error Description**
- A user-defined read-in parameter is commented in/out which triggers the bug due to different values that are read into the
parameter, e.g., setting `1e-14` or `10e-15` (which is basically the same value!)
The suspected problem is that something is read from the memory, which should not be read, e.g., an uninitialized variable
(that therefore points to a possibly random location in the memory)
This causes an undefined state (non-deterministic outcome, different compilers/different machines yield different effects).
The code might not crash but hang for a certain amount of time (this can be used to find the bug).

**Necessary Conditions**
- An integer variable that is used for (indirect) allocation of an array is uninitialized

**Sufficient Conditions**
- A function or subroutine is called that declares an array depending on an uninitialized integer variable

**Finding the Bug**
- When the code does not crash but instead hangs for a certain amount of time, the following print statements can be used (when not
utilizing a debugger)

IPWRITE(UNIT_StdOut,'(I0,A,I0)') ": v "//TRIM(__FILE__)//" +",__LINE__

to see the exact position in the code where the code hangs (due to a possible function call and subsequent allocation process)
for a short period of time

**Resolution**
- Nullify all integer variables that are used for allocation per default

**Explanation**
- The following variable was declared in a subroutine

REAL :: DistriOld(SpecDSMC(PartSpecies(iPart1))%MaxElecQuant)

but the integer `SpecDSMC(PartSpecies(iPart1))%MaxElecQuant` was not initialized because the corresponding model is not used in
this specific case and therefore `DistriOld` is never used. It is however allocated with an undefined state, with undefined outcome!
In this case the bug was fixed by using the "assignment to an allocatable array"

REAL,ALLOCATABLE              :: DistriOld(:)
...
DistriOld = ElectronicDistriPart(iPart1)%DistriFunc

For gfortran, Fortran 2003's assignment to an allocatable array was introduced in 4.6, 2011-01-28.

**git hashes**
- One of these bugs was specifically fixed in
[8d1129be95abc91bf56e94bf7f12987e4c214666](https://github.com/piclas-framework/piclas/commit/8d1129be95abc91bf56e94bf7f12987e4c214666)
Loading

0 comments on commit 3ba8a07

Please sign in to comment.