Skip to content

Commit

Permalink
Merge pull request #95 from cindytsai/cmake
Browse files Browse the repository at this point in the history
Support CMake
  • Loading branch information
cindytsai authored Nov 29, 2023
2 parents bf0cd16 + d1aa4d7 commit 0557d5c
Show file tree
Hide file tree
Showing 9 changed files with 357 additions and 54 deletions.
103 changes: 103 additions & 0 deletions .github/workflows/cmake-build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# 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
pip install yt-libyt
- 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,75 +50,68 @@ jobs:
- name: Install yt, mpi4py, and yt_libyt
run: |
pip install mpi4py yt
cd $GITHUB_WORKSPACE
cd ..
git clone https://github.com/data-exp-lab/yt_libyt.git
cd yt_libyt
pip install .
pip install yt-libyt
- name: Update GitHub Environment Variables
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
41 changes: 41 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
cmake_minimum_required(VERSION 3.15)

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

## set options ##
option(SERIAL_MODE "Compile library for serial process" OFF)
option(INTERACTIVE_MODE "Use interactive mode" OFF)
option(SUPPORT_TIMER "Support timer" OFF)

## 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 ##
if (NOT SERIAL_MODE)
set(MPI_HOME ${MPI_PATH})
find_package(MPI REQUIRED)
endif ()

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

## sub directory ##
add_subdirectory(src) # for library
#add_subdirectory(example) # for example exe

### 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)
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# libyt
[![build-test](https://github.com/yt-project/libyt/actions/workflows/build-test.yml/badge.svg)](https://github.com/yt-project/libyt/actions/workflows/build-test.yml)
[![CMake Build Test](https://github.com/yt-project/libyt/actions/workflows/cmake-build-test.yml/badge.svg)](https://github.com/yt-project/libyt/actions/workflows/cmake-build-test.yml)
[![GNU Make Build Test](https://github.com/yt-project/libyt/actions/workflows/make-build-test.yml/badge.svg)](https://github.com/yt-project/libyt/actions/workflows/make-build-test.yml)


`libyt` is an open source C library for simulation, that allows researchers to analyze and visualize data using [`yt`](https://yt-project.org/) or other Python packages in parallel during simulation runtime. In this way, we can skip the step of writing data to local disk before doing analysis using Python. This greatly reduce the disk usage, and increase the temporal resolution.
Expand Down
Loading

0 comments on commit 0557d5c

Please sign in to comment.