Skip to content

Commit

Permalink
Merge pull request #4 from cindytsai/cmake
Browse files Browse the repository at this point in the history
Support CMake
  • Loading branch information
cindytsai authored Nov 16, 2023
2 parents f25c196 + 9b3f37d commit e3c93c0
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 79 deletions.
107 changes: 107 additions & 0 deletions .github/workflows/cmake-build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Test if it can run on multiplatform and both in serial (gcc) and parallel (openmpi)

name: CMake Build Test

on:
push:
branches: [ main ]
paths-ignore:
- 'doc/**'
- '**.md'
pull_request:
branches: [ main ]
paths-ignore:
- 'doc/**'
- '**.md'
workflow_dispatch:

jobs:
cmake-build-test:
runs-on: ${{ matrix.platform.os }}
strategy:
fail-fast: false
matrix:
platform:
- os: ubuntu-latest
mpi: 'openmpi'
- os: macos-latest
mpi: 'mpich'
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- name: Checkout libyt repo
uses: actions/checkout@v3

- name: CMake Version
run: cmake --version

- name: Setup Python ${{ matrix.python-version }} environment
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: 'x64'
cache: 'pip'
- run: |
python -m pip install --upgrade pip
pip install -r ${{ github.workspace }}/.github/tools/requirements.txt
- name: Setup MPI environment
uses: mpi4py/setup-mpi@v1
with:
mpi: ${{ matrix.platform.mpi }}

- name: Install yt, mpi4py, and yt_libyt
run: |
pip install mpi4py yt
cd ${{ github.workspace }}
cd ..
git clone --depth 1 -b libyt-dev --single-branch "https://github.com/cindytsai/yt_libyt.git" yt_libyt
cd yt_libyt
pip install .
- name: Update GitHub Environment Variables
run: |
echo "LIBYT_PARALLEL_INSTALL_PATH=${{ github.workspace }}/libyt_parallel" >> $GITHUB_ENV
echo "LIBYT_SERIAL_INSTALL_PATH=${{ github.workspace }}/libyt_serial" >> $GITHUB_ENV
- name: Build libyt -- Parallel (MPI)
run: |
cd ${{ github.workspace }}
rm -rf build
cmake -B build -S .
cmake --build build
cmake --install build --prefix "${{ env.LIBYT_PARALLEL_INSTALL_PATH }}"
- name: Build libyt -- Serial (GCC)
run: |
cd ${{ github.workspace }}
rm -rf build-serial
cmake -B build-serial -S . -DSERIAL_MODE=ON
cmake --build build-serial
cmake --install build-serial --prefix "${{ env.LIBYT_SERIAL_INSTALL_PATH }}"
- name: Prepare Test
run: |
cd ${{ github.workspace }}/example
cp ${{ github.workspace }}/.github/tests/test-DataIO/DataIOTest.py .
- name: Generate Density Data for Testing
run: |
cd ${{ github.workspace }}/example
cp ${{ github.workspace }}/.github/tools/generate_density_data.cpp .
g++ -o generate_density_data generate_density_data.cpp
./generate_density_data
- name: Test Run and DataIO Test - example - Serial
run: |
cd ${{ github.workspace }}/example
make clean
make OPTIONS=-DSERIAL_MODE LIBYT_PATH="${{ env.LIBYT_SERIAL_INSTALL_PATH }}"
./example DataIOTest.py
- name: Test Run and DataIO Test - example - Parallel (MPI 3)
run: |
cd ${{ github.workspace }}/example
make clean
make LIBYT_PATH="${{ env.LIBYT_PARALLEL_INSTALL_PATH }}"
OMPI_MCA_osc=sm,pt2pt mpirun -np 3 ./example DataIOTest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Test: 1. If project can build successfully with different version of Python or not.
# 2. Can the example run in serial and in parallel.

name: build-test
name: GNU Make Build Test

on:
# Triggers the workflow on push or pull request events but only for the master branch
Expand All @@ -21,12 +21,12 @@ on:

jobs:
# Job name: "python-build-test"
python-build-test:
make-build-test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- name: Checkout libyt repo
Expand All @@ -40,7 +40,7 @@ jobs:
cache: 'pip'
- run: |
python -m pip install --upgrade pip
pip install -r $GITHUB_WORKSPACE/.github/tools/requirements.txt
pip install -r ${{ github.workspace}}/.github/tools/requirements.txt
- name: Setup MPI environment
uses: mpi4py/setup-mpi@v1
Expand All @@ -50,7 +50,7 @@ jobs:
- name: Install yt, mpi4py, and yt_libyt
run: |
pip install mpi4py yt
cd $GITHUB_WORKSPACE
cd ${{ github.workspace}}
cd ..
git clone --depth 1 -b libyt-dev --single-branch "https://github.com/cindytsai/yt_libyt.git" yt_libyt
cd yt_libyt
Expand All @@ -60,65 +60,62 @@ jobs:
run: |
echo "PYTHON_PATH=${{ env.pythonLocation }}" >> $GITHUB_ENV
echo "NUMPY_PATH=${{ env.pythonLocation }}/lib/python${{ matrix.python-version }}/site-packages/numpy" >> $GITHUB_ENV
echo "MPI_PATH=/usr" >> $GITHUB_ENV
echo "LIBYT_PARALLEL_INSTALL_PATH=$GITHUB_WORKSPACE/libyt_parallel" >> $GITHUB_ENV
echo "LIBYT_SERIAL_INSTALL_PATH=$GITHUB_WORKSPACE/libyt_serial" >> $GITHUB_ENV
echo "LIBYT_PARALLEL_INSTALL_PATH=${{ github.workspace }}/libyt_parallel" >> $GITHUB_ENV
echo "LIBYT_SERIAL_INSTALL_PATH=${{ github.workspace }}/libyt_serial" >> $GITHUB_ENV
# setup-python has python3.7m only, idk why.
# So split building libyt into two.
- name: Set PYTHON_PATH, PYTHON_VERSION, NUMPY_PATH
if: ${{ matrix.python-version == '3.7'}}
run: |
cd $GITHUB_WORKSPACE/src
cd ${{ github.workspace}}/src
sed -i 's@$(YOUR_PYTHON_PATH)@"${{ env.PYTHON_PATH }}"@' Makefile
sed -i 's@$(YOUR_NUMPY_PATH)@"${{ env.NUMPY_PATH }}"@' Makefile
sed -i 's@$(YOUR_PYTHON_VERSION)@"${{ matrix.python-version }}m"@' Makefile
- name: Set PYTHON_PATH, PYTHON_VERSION, NUMPY_PATH
if: ${{ matrix.python-version != '3.7' }}
run: |
cd $GITHUB_WORKSPACE/src
cd ${{ github.workspace}}/src
sed -i 's@$(YOUR_PYTHON_PATH)@"${{ env.PYTHON_PATH }}"@' Makefile
sed -i 's@$(YOUR_NUMPY_PATH)@"${{ env.NUMPY_PATH }}"@' Makefile
sed -i 's@$(YOUR_PYTHON_VERSION)@"${{ matrix.python-version }}"@' Makefile
- name: Build libyt -- Parallel (MPI)
run: |
cd $GITHUB_WORKSPACE/src
cd ${{ github.workspace}}/src
make clean
make MPI_PATH="${{ env.MPI_PATH }}"
make INSTALL_PREFIX="${{ env.LIBYT_PARALLEL_INSTALL_PATH }}" install
- name: Build libyt -- Serial (GCC)
run: |
cd $GITHUB_WORKSPACE/src
cd ${{ github.workspace}}/src
make clean
make OPTIONS="-DSERIAL_MODE"
make INSTALL_PREFIX="${{ env.LIBYT_SERIAL_INSTALL_PATH }}" install
- name: Prepare Test
run: |
cd $GITHUB_WORKSPACE/example
cp $GITHUB_WORKSPACE/.github/tests/test-DataIO/DataIOTest.py .
sed -i 's/inline_script/DataIOTest/' example.cpp
cd ${{ github.workspace}}/example
cp ${{ github.workspace}}/.github/tests/test-DataIO/DataIOTest.py .
- name: Generate Density Data for Testing
run: |
cd $GITHUB_WORKSPACE/example
cp $GITHUB_WORKSPACE/.github/tools/generate_density_data.cpp .
cd ${{ github.workspace}}/example
cp ${{ github.workspace}}/.github/tools/generate_density_data.cpp .
g++ -o generate_density_data generate_density_data.cpp
./generate_density_data
- name: Test Run and DataIO Test - example - Serial
run: |
cd $GITHUB_WORKSPACE/example
cd ${{ github.workspace}}/example
make clean
make OPTIONS=-DSERIAL_MODE LIBYT_PATH="${{ env.LIBYT_SERIAL_INSTALL_PATH }}"
./example
./example DataIOTest.py
- name: Test Run and DataIO Test - example - Parallel (MPI 3)
run: |
cd $GITHUB_WORKSPACE/example
cd ${{ github.workspace}}/example
make clean
make LIBYT_PATH="${{ env.LIBYT_PARALLEL_INSTALL_PATH }}" MPI_PATH="${{ env.MPI_PATH }}"
OMPI_MCA_osc=sm,pt2pt mpirun -np 3 ./example
make LIBYT_PATH="${{ env.LIBYT_PARALLEL_INSTALL_PATH }}"
OMPI_MCA_osc=sm,pt2pt mpirun -np 3 ./example DataIOTest.py
48 changes: 23 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
cmake_minimum_required(VERSION 3.15)

### PROJECT Info ###
project(LIBYT_PROJECT VERSION 0.1 DESCRIPTION "In situ Python analysis tool using yt")
###### PROJECT Info ####################################################################################################
project(LIBYT_PROJECT VERSION 0.1.0 DESCRIPTION "In situ Python analysis tool using yt and Python")

# set option
## set options ##
option(SERIAL_MODE "Compile library for serial process" OFF)
option(INTERACTIVE_MODE "Use interactive mode" OFF)
option(SUPPORT_TIMER "Support timer" OFF)
option(BUILD_SHARED_LIBS "Building using shared libraries" ON )

# set path
set(PYTHON_PATH "")
set(MPI_PATH "")
set(GCC_PATH "")
set(READLINE_PATH "")
## set paths ##
set(PYTHON_PATH "" CACHE PATH "Path to Python installation prefix")
set(MPI_PATH "" CACHE PATH "Path to MPI installation prefix")
set(READLINE_PATH "" CACHE PATH "Path to Readline installation prefix")

###### COMPILATION (DO NOT TOUCH) ######################################################################################
## build static/shared library ##
option(BUILD_SHARED_LIBS "Building using shared libraries" ON )

### FIND DEPENDENCIES ###
## find dependencies ##
if (NOT SERIAL_MODE)
set(MPI_HOME ${MPI_PATH})
find_package(MPI REQUIRED)
else ()
# TODO: Find GCC Package if GCC_PATH is empty
endif ()

set(Python_ROOT_DIR ${PYTHON_PATH})
find_package(Python COMPONENTS Development NumPy REQUIRED)

### COMPILATION ###
## sub directory ##
add_subdirectory(src) # for library
#add_subdirectory(example) # for example exe
#configure_file(libyt.pc.in libyt.pc @ONLY) # for pkgconfig

### MyLib PACKAGING ###
# Only packaging library works
include(InstallRequiredSystemLibraries)
set(MYPROJECT_SRC "${CMAKE_CURRENT_SOURCE_DIR}")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") # set license
set(CPACK_PACKAGE_VERSION_MAJOR "${LIBYT_PROJECT_VERSION_MAJOR}") # major version
set(CPACK_PACKAGE_VERSION_MINOR "${LIBYT_PROJECT_VERSION_MINOR}") # minor version
set(CPACK_SOURCE_GENERATOR "TGZ") # packed format

include(CPack)

### libyt PACKAGING ###
#include(InstallRequiredSystemLibraries)
#set(MYPROJECT_SRC "${CMAKE_CURRENT_SOURCE_DIR}")
#set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") # set license
#set(CPACK_PACKAGE_VERSION_MAJOR "${LIBYT_PROJECT_VERSION_MAJOR}") # major version
#set(CPACK_PACKAGE_VERSION_MINOR "${LIBYT_PROJECT_VERSION_MINOR}") # minor version
#set(CPACK_SOURCE_GENERATOR "TGZ") # packed format
#
#include(CPack)
Loading

0 comments on commit e3c93c0

Please sign in to comment.