Skip to content

Commit

Permalink
Merge pull request #1255 from DLR-AMR/feature-fortran-interface
Browse files Browse the repository at this point in the history
Build Fortran interface: autotools & CMake
  • Loading branch information
Davknapp authored Oct 1, 2024
2 parents ab2e625 + 0304b62 commit d3d337d
Show file tree
Hide file tree
Showing 15 changed files with 661 additions and 8 deletions.
111 changes: 111 additions & 0 deletions .github/workflows/tests_cmake_t8code_api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: CMake tests t8code api


# This file is part of t8code.
# t8code is a C library to manage a collection (a forest) of multiple
# connected adaptive space-trees of general element types in parallel.
#
# Copyright (C) 2024 the developers
#
# t8code is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# t8code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with t8code; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

on:
workflow_call:
inputs:
MAKEFLAGS:
required: true
type: string
description: 'Make flags to use for compilation (like -j4)'
MPI:
required: true
type: string
description: 'Use MPI for compilation (ON/OFF)'
BUILD_TYPE:
required: true
type: string
description: 'Build type (Release/Debug)'
LESS_TESTS:
required: true
type: boolean
description: 'Enable less tests option for configuring'

jobs:
t8code_cmake_tests:
timeout-minutes: 30
runs-on: ubuntu-latest
container: dlramr/t8code-ubuntu:t8-dependencies
steps:
#
# Setup
#
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: SC_P4EST_MPI_${{ inputs.MPI }}
- name: untar artifact
run: tar -xf artifact.tar && rm artifact.tar
- name: Update packages
run: apt-get update && apt-get upgrade -y
# This seems to be necessary because of the docker container
- name: disable ownership checks
run: git config --global --add safe.directory '*'
- name: Get input vars
run: export MAKEFLAGS="${{ inputs.MAKEFLAGS }}"
&& export MPI="${{ inputs.MPI }}"
&& export BUILD_TYPE="${{ inputs.BUILD_TYPE }}"
&& export SC_PATH=$PWD/sc/build/$BUILD_TYPE
&& export P4EST_PATH=$PWD/p4est/build/$BUILD_TYPE
&& echo MAKEFLAGS="$MAKEFLAGS" >> $GITHUB_ENV
&& echo MPI="$MPI" >> $GITHUB_ENV
&& echo BUILD_TYPE="$BUILD_TYPE" >> $GITHUB_ENV
&& echo SC_PATH="$SC_PATH" >> $GITHUB_ENV
&& echo P4EST_PATH="$P4EST_PATH" >> $GITHUB_ENV
#
# T8CODE
#
#
# build config vars
- name: less-test option
if: ${{ inputs.LESS_TESTS }}
run: export LESS_TEST_OPTION="-DT8CODE_ENABLE_LESS_TESTS=ON"
&& echo LESS_TEST_OPTION="$LESS_TEST_OPTION" >> $GITHUB_ENV
- name: build config variables
run: export CONFIG_OPTIONS="${LESS_TEST_OPTION} -GNinja -DT8CODE_USE_SYSTEM_SC=ON -DT8CODE_USE_SYSTEM_P4EST=ON -DT8CODE_BUILD_PEDANTIC=ON -DT8CODE_ENABLE_MPI=$MPI -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DSC_DIR=$SC_PATH/install/cmake -DP4EST_DIR=$P4EST_PATH/install/cmake"
&& echo CONFIG_OPTIONS="$CONFIG_OPTIONS" >> $GITHUB_ENV
# cmake and test with fortran
- name: check fortran
run: echo "Checking fortran"
- name: echo cmake line
run: echo cmake ../ $CONFIG_OPTIONS -DT8CODE_BUILD_FORTRAN_INTERFACE=ON
- name: cmake MPI fortran debug
run: mkdir build_fortran && cd build_fortran && cmake ../ $CONFIG_OPTIONS -DT8CODE_ENABLE_FORTRAN=ON
- name: OnFailUploadLog
if: failure()
uses: actions/upload-artifact@v4
with:
name: cmake_${{ inputs.BUILD_TYPE }}_MPI_${{ inputs.MPI }}_fortran.log
path: build_fortran/CMakeFiles/CMakeOutput.log
- name: make
run: cd build_fortran && ninja $MAKEFLAGS
- name: ninja install
run: cd build_fortran && ninja install $MAKEFLAGS
- name: ninja test
run: cd build_fortran && ninja test
- name: OnFailUploadLog
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-suite_${{ inputs.BUILD_TYPE }}_MPI_${{ inputs.MPI }}_fortran.log
path: build_fortran/Testing/Temporary/LastTest.log
19 changes: 18 additions & 1 deletion .github/workflows/tests_cmake_testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,24 @@ jobs:
MPI: ${{ matrix.MPI }}
BUILD_TYPE: ${{ matrix.BUILD_TYPE }}
LESS_TESTS: ${{ github.event_name == 'pull_request' }}

# Run t8code linkage tests with and without MPI and in serial and debug mode
t8code_api_tests:
if: (github.event_name == 'schedule' && github.repository == 'DLR-AMR/t8code') || (github.event_name != 'schedule')
uses: ./.github/workflows/tests_cmake_t8code_api.yml
strategy:
fail-fast: false
matrix:
MPI: [ON] # For now the fortran API only supports building with MPI
BUILD_TYPE: [Debug, Release]
include:
- MAKEFLAGS: -j4
needs: preparation
with:
MAKEFLAGS: ${{ matrix.MAKEFLAGS }}
MPI: ${{ matrix.MPI }}
BUILD_TYPE: ${{ matrix.BUILD_TYPE }}
LESS_TESTS: ${{ github.event_name == 'pull_request' }}

# Run t8code tests with shipped submodules. This test is only for the build system, so only one config is tested.
t8code_w_shipped_submodules_tests:
Expand All @@ -123,4 +141,3 @@ jobs:
MPI: ON
BUILD_TYPE: Debug
LESS_TESTS: ${{ github.event_name == 'pull_request' }}

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ config.status
Doxyfile
doxygen/

CMakeCache.txt
CMakeFiles/

src/stamp-h1
src/t8_config.h
src/pre_config.h
Expand Down
21 changes: 18 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include(cmake/GitProjectVersion.cmake)

project( T8CODE
DESCRIPTION "Parallel algorithms and data structures for tree-based AMR with arbitrary element shapes."
LANGUAGES C CXX
LANGUAGES C CXX Fortran
VERSION "${T8CODE_VERSION_MAJOR}.${T8CODE_VERSION_MINOR}.${T8CODE_VERSION_PATCH}" )
include( CTest )

Expand All @@ -15,6 +15,7 @@ option( T8CODE_BUILD_TESTS "Build t8code's automated tests" ON )
option( T8CODE_BUILD_TUTORIALS "Build t8code's tutorials" ON )
option( T8CODE_BUILD_EXAMPLES "Build t8code's examples" ON )
option( T8CODE_BUILD_BENCHMARKS "Build t8code's benchmarks" ON )
option( T8CODE_BUILD_FORTRAN_INTERFACE "Build t8code's Fortran interface" OFF )
option( T8CODE_ENABLE_LESS_TESTS "Tests not as thoroughly to speed up the test suite. Tests the same functionality. (WARNING: Use with care.)" OFF )

option( T8CODE_ENABLE_MPI "Enable t8code's features which rely on MPI" ON )
Expand Down Expand Up @@ -56,7 +57,12 @@ set( CMAKE_CXX_EXTENSIONS OFF )
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})

if( T8CODE_ENABLE_MPI )
find_package( MPI COMPONENTS C REQUIRED )
if( T8CODE_BUILD_FORTRAN_INTERFACE )
find_package( MPI COMPONENTS C Fortran REQUIRED )
else()
find_package( MPI COMPONENTS C REQUIRED )
endif()

if( NOT MPIEXEC_EXECUTABLE )
message( FATAL_ERROR "MPIEXEC was not found" )
endif()
Expand Down Expand Up @@ -137,4 +143,13 @@ if ( T8CODE_BUILD_DOCUMENTATION )
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/doc )
endif()

include (cmake/CPackConfig.cmake)
if( T8CODE_BUILD_FORTRAN_INTERFACE )
enable_language( Fortran )
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/api/t8_fortran_interface )

if( NOT T8CODE_ENABLE_MPI )
message( FATAL_ERROR "Fortran API only available when MPI is enabled." )
endif()
endif()

include (cmake/CPackConfig.cmake)
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ dist_t8aclocal_DATA = config/t8_include.m4 \
config/t8_netcdf.m4 \
config/t8_vtk.m4 \
config/t8_occ.m4 \
config/t8_fortran.m4 \
config/t8_mpi.m4


Expand Down
18 changes: 17 additions & 1 deletion api/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,24 @@ libt8_installed_headers_fortran_interface = \

dist_fortraninterfaceinclude_HEADERS = $(libt8_installed_headers_fortran_interface)

# Save the module sources in a different variable for later use
t8_fortran_module_sources = api/t8_fortran_interface/t8_fortran_interface_mod.f90

# Add the Fortran sources to the lib
libt8_compiled_sources += $(t8_fortran_module_sources)

AM_FCFLAGS =
libt8_compiled_sources += \
api/t8_fortran_interface/t8_fortran_interface.c

AM_CPPFLAGS += -I@top_srcdir@/api
AM_CPPFLAGS += -I@top_srcdir@/api/t8_fortran_interface
MODSOURCES = $(t8_fortran_module_sources)

src_libt8_la_FCFLAGS = $(AM_FCFLAGS)
src_libt8_la_FFLAGS = $(FFLAGS)

# Include the Fortran specific variables and rules
include api/t8_fortran_interface/t8_fortran_specific.mk

# T8_ENABLE_FORTRAN
endif
18 changes: 18 additions & 0 deletions api/t8_fortran_interface/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Link in C-Fortran interface file into libt8.
target_sources( T8 PRIVATE t8_fortran_interface.c )
target_sources( T8 PRIVATE t8_fortran_interface_mod.f90 )

# Add this directory to header search path.
target_include_directories( T8 PRIVATE ${CMAKE_CURRENT_LIST_DIR} )

# Install header files.
install(
FILES ${CMAKE_CURRENT_LIST_DIR}/t8_fortran_interface.h
DESTINATION ${CMAKE_INSTALL_PREFIX}/include/t8_fortran_interface
)

# Install module files.
install(
FILES ${CMAKE_BINARY_DIR}/src/t8_fortran_interface_mod.mod
DESTINATION ${CMAKE_INSTALL_PREFIX}/include/t8_fortran_interface
)
2 changes: 1 addition & 1 deletion api/t8_fortran_interface/t8_fortran_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#include <api/t8_fortran_interface/t8_fortran_interface.h>
#include <t8_fortran_interface.h>
#include <t8_forest/t8_forest_general.h>
#include <t8_forest/t8_forest_geometrical.h>
#include <t8_cmesh/t8_cmesh_examples.h>
Expand Down
1 change: 1 addition & 0 deletions api/t8_fortran_interface/t8_fortran_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <t8.h>
#include <t8_cmesh.h>
#include <t8_forest/t8_forest_general.h>
#include <t8_forest/t8_forest_geometrical.h>

typedef int (*t8_fortran_adapt_coordinate_callback) (double x, double y, double z, int is_family);

Expand Down
Loading

0 comments on commit d3d337d

Please sign in to comment.