Skip to content

Commit

Permalink
Merge pull request #155 from lanl/Daniel
Browse files Browse the repository at this point in the history
Important fixes to uncrustify
  • Loading branch information
nathanielmorgan authored Apr 4, 2024
2 parents d9c2fa8 + c5c39b2 commit 5748d03
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .conda/evpfft/cpu/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ cmake ../src/ \
-D CMAKE_CXX_COMPILER=$BUILD_PREFIX/bin/mpicxx \
-D CMAKE_C_COMPILER=$BUILD_PREFIX/bin/mpicc \

make install
make install
1 change: 1 addition & 0 deletions .conda/evpfft/cpu/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ build:
requirements:
build:
- cmake >=3.17.0
- make
- {{ compiler('c') }}={{ linux_compiler_version }} # [linux]
- {{ compiler('c') }}={{ macos_compiler_version }} # [osx]
- {{ compiler('cxx') }}={{ linux_compiler_version }} # [linux]
Expand Down
21 changes: 18 additions & 3 deletions .conda/fierro-dev/cpu/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% set version = "1.0.0" %}
{% set compiler_version = "10.4.0" %}
{% set linux_compiler_version = "10.4.0" %}
{% set macos_compiler_version = "12" %}

package:
name: fierro-dev
Expand All @@ -13,9 +14,23 @@ build:
- PLATFORM={{ target_platform }}

requirements:
run:
host:
- cmake >=3.17
- {{ compiler('cxx') }}={{ compiler_version }}
- {{ compiler('c') }}={{ linux_compiler_version }} # [linux]
- {{ compiler('c') }}={{ macos_compiler_version }} # [osx]
- {{ compiler('cxx') }}={{ linux_compiler_version }} # [linux]
- {{ compiler('cxx') }}={{ macos_compiler_version }} # [osx]
- {{ compiler('fortran') }}
- fierro-trilinos-cpu
- mpi
- elements
run:
#- cmake >=3.17
- {{ compiler('c') }}={{ linux_compiler_version }} # [linux]
- {{ compiler('c') }}={{ macos_compiler_version }} # [osx]
- {{ compiler('cxx') }}={{ linux_compiler_version }} # [linux]
- {{ compiler('cxx') }}={{ macos_compiler_version }} # [osx]
- {{ compiler('fortran') }}
- fierro-trilinos-cpu
- mpi
- elements
Expand Down
1 change: 1 addition & 0 deletions .conda/fierro/cpu/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ requirements:
- {{ compiler('c') }}={{ macos_compiler_version }} # [osx]
- {{ compiler('cxx') }}={{ linux_compiler_version }} # [linux]
- {{ compiler('cxx') }}={{ macos_compiler_version }} # [osx]
- {{ compiler('fortran') }}
- openmpi={{ mpi_version }}
host:
- _openmp_mutex # [linux]
Expand Down
4 changes: 2 additions & 2 deletions .conda/heffte/cpu/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ requirements:
- {{ compiler('cxx') }} # [osx]
- openmpi
host:
- openmpi
- openmpi >=4.1.6,<5.0a0
- fftw
run:
- openmpi
- openmpi >=4.1.6,<5.0a0
- fftw

about:
Expand Down
2 changes: 1 addition & 1 deletion .conda/trilinos/cpu/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ requirements:
host:
- libblas
- liblapack
- openmpi
- openmpi >=4.1.6,<5.0a0
- boost-cpp
- libnetcdf
- libmatio
Expand Down
1 change: 1 addition & 0 deletions .etc/conda_build_environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ channels:
- defaults
dependencies:
- boa # For building
- conda-build
- anaconda-client # For uploading
4 changes: 2 additions & 2 deletions .github/workflows/build-conda-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ jobs:

- name: Update environment
run:
mamba env update -n build-env -f .etc/conda_build_environment.yaml
conda env update -n build-env -f .etc/conda_build_environment.yaml
#if: steps.cache.outputs.cache-hit != 'true'
- run: |
if [ ${{ inputs.debug }} = true ] ; then export DEBUG="--debug"; fi;
mamba mambabuild $DEBUG ${{ inputs.recipe_dir }} -e .conda/build_variants.yaml -m ${{ inputs.additional_variant }} --token ${{ secrets.ANACONDA_TOKEN }} --no-test -c fierromechanics -c conda-forge -c nvidia
conda build $DEBUG ${{ inputs.recipe_dir }} -e .conda/build_variants.yaml -m ${{ inputs.additional_variant }} --token ${{ secrets.ANACONDA_TOKEN }} --no-test -c fierromechanics -c conda-forge -c nvidia
continue-on-error: ${{ inputs.debug }}
- name: Setup tmate session
Expand Down
46 changes: 6 additions & 40 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,8 @@ openmpi
```

### Environment Variables
We need to have several environment variables point to these homebrew installations so that our build system knows where to look. These variables can either be set individually, or put into your ***~/.bashrc*** file and sourced.
The current setup for the build scripts is to add the below lines to your environment automatically. For user that are using a different software stack such as GCC, these path's would need to point to those paths in the script file they are pulled from. This file is
```
scripts/<solver>/machines/mac-env.sh
```
If you are changing the environment paths in your ***~/.bashrc*** then the file could look like this
```
export CC=/opt/homebrew/opt/llvm/bin/clang
export CXX=/opt/homebrew/opt/llvm/bin/clang++
export PATH="/opt/homebrew/opt/llvm/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/llvm/lib"
export CPPFLAGS="-I/opt/homebrew/opt/llvm/include"
export OMPI_CC=${CC}
export OMPI_CXX=${CXX}
```
and then you would source those variables with
```
source ~/.bashrc
```
For those that noticed, this looks exactly like the ***mac-env.sh*** file mentioned above.
There are two things of note with this example. First, it is using the llvm/clang compiler. This is one of the possible options. If you prefer to use GCC as your base compiler, all of the variables (CC,CXX,PATH,LDFLAGS,CPPFLAGS) would need to be modified to point to the corresonding spot in the gcc directory. The second thing to note with this example is the path that homebrew has installed your software. By default on Apple silicon hardware (M1/M2), it should be the one listed as in the above example
The paths are set in the **scripts/machine/mac.sh** script.
There are two things of note. First, it is using the llvm/clang compiler. This is one of the possible options. If you prefer to use GCC as your base compiler, all of the variables (CC,CXX,PATH,LDFLAGS,CPPFLAGS) would need to be modified to point to the corresonding spot in the gcc directory. The second thing to note with this example is the path that homebrew has installed your software. By default on Apple silicon hardware (M1/M2), it should be the one listed as in the above example
```
/opt/homebrew/opt/<software>
```
Expand All @@ -55,10 +36,11 @@ If you explicitally tell homebrew to install them elsewhere, or it does it in a

### Running the build scripts
Now the assumption is that you have the software installed and the system knows where to look for that software. The code can be built using the scripts in the ***scripts*** directory. There are several options here depending on the problems you'd like to run, but the build process is identical, so we will use the *Explicit* folder for our example. The script can be run from anywhere in the Fierro repository. If we were at the top of the directory would run
Now the assumption is that you have the software installed and the system knows where to look for that software. The code can be built as normal now, with the exception that we always need to pass in the machine argument and set it to mac (also of note, unlike linux systems, we do not ***source*** script, we instead have to just run the script with ./)
```
./scripts/Explicit/build-it.sh --machine=mac --kokkos_build_type=openmp
./{path-to-repo}/scripts/build-fierro.sh --machine=mac [any other parameters we need to pass]
```
***Note*** you can see more information on the script arguments in the *README.md* or running the script with the argument ***--help***. However this is the standard script you would run on a Mac. You could subistitue 'serial' in for 'openmp', but since the build supports OpenMP that is the suggestion option for better runtime performance.
***Note*** you can still see more information on the script arguments by running the script with the argument ***--help***. However this is the standard script you would run on a Mac.

## Running the example
Assuming a smooth build, you will be placed at the top of the repository again. You can move yourself into the build directory
Expand All @@ -69,20 +51,4 @@ From there you can run this example with
```
./bin/fierro-parallel-explicit ../src/Parallel-Solvers/Parallel-Explicit/example_simple.yaml
```
***Note*** For this example the mesh file that is passed into *example_simple.yaml* needs to be present in your build directory.

## Important Notes
Hopefully the above steps result in a smooth build process. When making changes to code that require another cmake configuration, we suggest running the full ***build-it.sh <args>*** script again. This is because it sources the necessaryfiles to setup environment paths. Trilinos will *not* get re-built as a result of this.
The reason for this suggestion is ease of environment. It is possible to simply source the cmake script
```
source cmake_build.sh
```
However you may end up in an unexpected directory since all internal paths were not set. It is possible to
```
source setup-env.sh --machine=mac --kokkos_build_type=openmp
```
before the cmake step. This would set all path's globally, instead of self-contained inside the script run. However any software changes made after this needs to have environment-correcting commands.
Also, it is not advised to source the ***build-it.sh*** script from anywhere as the initial step, because of how Macs handle that source. In bash shells the behavior would be more or less expected. However on others (for instance Mac's default zsh shell) the paths would not be expected.
Therefore, we suggest one of the two options
- run the script with ***./<path to script>/build-it.sh*** from anywhere or
- ***source build-it.sh*** from *inside* the scripts/[solver] directory
***Note*** For this example the mesh file that is passed into *example_simple.yaml* needs to be present in your build directory. For the examples, you can copy the one in {path-to-repo}/single-node/src/Explicit-Lagrange/meshes/mesh_Sedov_32.geo
39 changes: 5 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,46 +59,17 @@ You are welcome to only compile one solver or the other, and the one(s) that you
As for Trilinos, we recommend installing the Anaconda package for the desired build into a new Anaconda environment to satisfy **Fierro**'s dependency rather than building it from source. If you do wish to build it from source, however, sample build scripts for Trilinos can be found in `Fierro/Trilinos-Build-Scripts`. Build scripts for all Anaconda packages can be found in `Fierro/Anaconda-Packages/`.

## Alternative Build Workflows
In addition to the primary build workflow described above, there are build scripts for a variety of alternative workflows. These scripts can be found under `Fierro/scripts`.
In addition to the primary build workflow described above, there are build scripts for a variety of alternative workflows. These scripts can be found under `Fierro/scripts`. Although there are multiple scripts shown in this directory, the only one that will be run directly by the user is ***build-fierro.sh***
### Building the explicit and implicit Lagrangian methods with Trilinos+Kokkos
Explicit Lagrangian codes are being added to the repository that are written using MATAR+Kokkos and run with fine-grained parallellism on multi-core CPUs and GPUs. Build scripts are provided for each Lagrangian code, and those scripts follow those used in the [MATAR](https://github.com/lanl/MATAR/) GitHub repository. The scripts to build the Lagrangian codes (that use MATAR+Kokkos) are in the scripts folder. The user must update the modules loaded by the build scripts (for the compiler etc.), and then type
Immediate help with all scripts can be had running
```
<script> --help
```
The build-it script can take up to 3 arguments (with a minimum of 2)
```
source build-it.sh --machine=<arg> --kokkos_build_type=<arg> (optional)--build_cores=<arg>
```
machine currently has three options: darwin,linux,mc
```
darwin: builds by loading modules on the darwin cluster. and can perform parallel builds (make -j). Changes can be made to scripts/[solver]/machines/darwin-setup.sh to reflect your machine.
linux: does not load any modules and instead sources some paths related to your loaded software. Additionally, the builds can be parallel (make -j <build_cores>)
macos: does not load any modules and instead sources some paths related to your loaded software. Additionally, the builds will be forced to beserial (make)
For Mac builds, please see the ***BUILD.md*** file for more info
```
kokkos_build_type has four options: 'cuda', 'hip', 'openmp', 'serial'
***Note*** - all builds use Trilinos with Kokkos. The 'serial' option will utilize the Kokkos serial build
```
cuda: loads cuda module and a working gcc module pairing
hip: loads hip module and a working clang module pairing
openmp: loads gcc module and sets openmp environment variables
serial: loads gcc module
```
***Note*** - compiler can be changed with the appropriate variables in *setup-env.sh*, the ones provided are simply known to work together
If running on Mac, only the openmp and serial options are enabled

All other scripts will be called with the appropriate arguments as a result of running build-it.

If you need to simply rebuild Fierro without making a new Trilinos installation, simply
```
source cmake_build.sh
```
If you are getting back on to a machine or allocation to continue development, you will need to run
```
source setup-env.sh <same args you passed to build-it>
source {path-to-repo}/build-fierro.sh --help
```
The default run will build the **full-app** settting up the **Explicit*** solver with **serial** Kokkos for a **linux** computer (non-HPC machine)
Running with ```--help``` option will list all parameters and their accepted arguments
If the scripts fail to build a Lagrangian code, then carefully review the modules used and the computer architecture settings.
For building on a Mac, please see the extra info in the BUILD.md
#A more lenghtly discussion of the build scripts is provided in the MATAR GitHub repository.

For help with [Trilinos](https://github.com/trilinos/Trilinos/wiki/New-Trilinos-Developers)
Expand Down
19 changes: 5 additions & 14 deletions scripts/build-fierro.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ show_help() {
echo " install-trilinos builds and installs Trilinos if not already installed. Clones from github if necessary"
echo " install-hdf5 builds and installs hdf5 if not already installed. Clones from github if necessary"
echo " install-heffte builds and installs heffte. Always rebuilds to avoid stale builds. If this action is being done, --heffte_build_type is necessary"
echo " install-uncrustify builds and installs uncrustify. Only necessary for developers"
echo " fierro Generates CMake files and builds Fierro only (none of the dependencies)."
echo " "
echo " --solver Builds the desired solver to run. The default action is 'explicit'"
Expand Down Expand Up @@ -64,7 +65,7 @@ heffte_build_type="fftw"
build_cores="1"

# Define arrays of valid options
valid_build_action=("full-app" "set-env" "install-trilinos" "install-hdf5" "install-heffte" "fierro")
valid_build_action=("full-app" "set-env" "install-trilinos" "install-hdf5" "install-heffte" "install-uncrustify" "fierro")
valid_solver=("all" "explicit" "explicit-evpfft" "explicit-ls-evpfft" "implicit")
valid_kokkos_build_types=("serial" "openmp" "pthreads" "cuda" "hip")
valid_heffte_build_types=("fftw" "cufft" "rocfft")
Expand Down Expand Up @@ -180,21 +181,9 @@ cd "$( dirname "${BASH_SOURCE[0]}" )"
# Always setup the environment
source setup-env.sh ${machine} ${kokkos_build_type} ${build_cores}

# Install Uncrustify
if [ -d "${UNCRUSTIFY_BUILD_DIR}" ]; then
cd ${topdir}
echo "Installing Uncrustify..."
cd ${UNCRUSTIFY_BUILD_DIR}
echo $(pwd)
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j ${build_cores}
cd ${topdir}
fi

cd "$( dirname "${BASH_SOURCE[0]}" )"

# Next, do action based on args
if [ "$build_action" = "full-app" ]; then
source uncrustify-install.sh
source trilinos-install.sh ${kokkos_build_type} ${machine}
if [ "$solver" = "explicit-evpfft" ] || [ "${solver}" = "explicit-ls-evpfft" ]; then
source hdf5-install.sh
Expand All @@ -207,6 +196,8 @@ elif [ "$build_action" = "install-hdf5" ]; then
source hdf5-install.sh
elif [ "$build_action" = "install-heffte" ]; then
source heffte-install.sh ${heffte_build_type} ${machine}
elif [ "$build_action" = "install-uncrustify" ]; then
source uncrustify-install.sh
elif [ "$build_action" = "fierro" ]; then
source cmake_build.sh ${solver} ${heffte_build_type} ${kokkos_build_type}
else
Expand Down
2 changes: 1 addition & 1 deletion scripts/cmake_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ kokkos_build_type="${3}"
if { [ ! -d "${ELEMENTS_SOURCE_DIR}/elements" ] || [ ! -d "${ELEMENTS_SOURCE_DIR}/matar/src" ] ;}
then
echo "Missing submodules, downloading them...."
git submodule update --init --recursive
git submodule update "${ELEMENTS_SOURCE_DIR}"
fi

if [ ! -d "${TRILINOS_INSTALL_DIR}/lib" ]; then
Expand Down
6 changes: 0 additions & 6 deletions scripts/setup-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ export installdir=${basedir}/install

export devutilsdir=${topdir}/dev-utils

if { [ ! -d "${devutilsdir}/uncrustify/build" ] ;}
then
echo "Missing uncrustify build directory, making it now "
mkdir ${devutilsdir}/uncrustify/build
fi

export UNCRUSTIFY_SOURCE_DIR=${devutilsdir}/uncrustify
export UNCRUSTIFY_BUILD_DIR=${devutilsdir}/uncrustify/build
export UNCRUSTIFY_INSTALL_DIR=${devutilsdir}/uncrustify/build
Expand Down
17 changes: 17 additions & 0 deletions scripts/uncrustify-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash -e

# Check if the uncrustify build directory exists and is not empty in the parent directory; if not, clone it

if [ ! -d "${UNCRUSTIFY_SOURCE_DIR}" ];
then
echo "Missing Uncrustify submodule, downloading...."
git submodule update ${UNCRUSTIFY_SOURCE_DIR}
fi

if [ ! -f "${UNCRUSTIFY_BUILD_DIR}/uncrustify" ]; then
echo "Uncrustify not built, installing..."
cmake -D CMAKE_BUILD_TYPE=Release -B "${UNCRUSTIFY_BUILD_DIR}" -S "${UNCRUSTIFY_SOURCE_DIR}"
make -C "${UNCRUSTIFY_BUILD_DIR}" -j${FIERRO_BUILD_CORES}
else
echo "Uncrustify already exists and has been built"
fi

0 comments on commit 5748d03

Please sign in to comment.