Skip to content

Commit

Permalink
Merge pull request #1055 from perazz/hdf5_metapackage
Browse files Browse the repository at this point in the history
Metapackages: `pkg_config` backend support; HDF5
  • Loading branch information
henilp105 authored Aug 19, 2024
2 parents 1559b60 + 00aef12 commit 4030a8a
Show file tree
Hide file tree
Showing 14 changed files with 875 additions and 143 deletions.
37 changes: 28 additions & 9 deletions .github/workflows/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ jobs:
wget
unzip
curl
hdf5
- name: (Windows) Setup VS Build environment
if: contains(matrix.os,'windows') && contains(matrix.mpi,'intel')
Expand All @@ -93,12 +94,12 @@ jobs:
- name: (Ubuntu) Install OpenMPI
if: contains(matrix.os,'ubuntu') && contains(matrix.mpi,'openmpi')
run: |
sudo apt install -y -q openmpi-bin libopenmpi-dev
sudo apt install -y -q openmpi-bin libopenmpi-dev hwloc fabric libhdf5-dev libhdf5-fortran-102
- name: (Ubuntu) Install MPICH
if: contains(matrix.os,'ubuntu') && contains(matrix.mpi,'mpich')
run: |
sudo apt install -y -q mpich
sudo apt install -y -q mpich hwloc fabric libhdf5-dev libhdf5-fortran-102
- name: (Ubuntu) Retrieve Intel toolchain
if: contains(matrix.os,'ubuntu') && contains(matrix.mpi,'intel')
Expand All @@ -110,14 +111,27 @@ jobs:
- name: (Ubuntu) Install Intel oneAPI
if: contains(matrix.os,'ubuntu') && contains(matrix.mpi,'intel')
timeout-minutes: 15
run: sudo apt-get install intel-oneapi-compiler-dpcpp-cpp-2023.1.0 intel-oneapi-compiler-fortran-2023.1.0 intel-oneapi-mpi-devel ninja-build
uses: fortran-lang/[email protected]
id: setup-fortran
with:
compiler: intel
version: 2024.1.0

- name: (Ubuntu) Setup Intel oneAPI environment
- name: (Ubuntu) finalize oneAPI environment
if: contains(matrix.os,'ubuntu') && contains(matrix.mpi,'intel')
run: |
source /opt/intel/oneapi/setvars.sh
printenv >> $GITHUB_ENV
# Install MPI
sudo apt-get install -y -q intel-oneapi-mpi-devel ninja-build cmake
source /opt/intel/oneapi/setvars.sh --force
printenv >> $GITHUB_ENV
# To run HDF5 with oneAPI, we need to build it from source. Use CMake to generate pkg-config info
curl -O -L https://github.com/HDFGroup/hdf5/archive/refs/tags/snapshot-1.14.tar.gz
tar zxf snapshot-1.14.tar.gz
cd hdf5-snapshot-1.14
cmake -B build -DCMAKE_Fortran_COMPILER=ifx -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DHDF5_BUILD_FORTRAN=ON -DCMAKE_INSTALL_PREFIX=/usr
cd build
make -j
sudo make install
- name: (Windows) Put MSYS2_MinGW64 on PATH
if: contains(matrix.os,'windows') && (!contains(matrix.mpi,'intel'))
Expand Down Expand Up @@ -197,6 +211,11 @@ jobs:
run: |
brew install openmpi #--cc=gcc-${{ env.GCC_V }} openmpi
- name: (macOS) Install homebrew HDF5
if: contains(matrix.os,'macos')
run: |
brew install hdf5
# Phase 1: Bootstrap fpm with existing version
- name: Install fpm
uses: fortran-lang/setup-fpm@v5
Expand All @@ -209,8 +228,8 @@ jobs:
mv $(which fpm) fpm-bootstrap${{ matrix.exe }}
echo "BOOTSTRAP=$PWD/fpm-bootstrap" >> $GITHUB_ENV
- name: (macOS) Use gcc/g++ instead of Clang for C/C++
if: contains(matrix.os,'macOS')
- name: (macOS/Ubuntu) Use gcc/g++ instead of Clang for C/C++ / ifx to build fpm
if: contains(matrix.os,'macOS') || contains(matrix.os,'ubuntu')
shell: bash
run: |
echo "FPM_FC=gfortran-${{ env.GCC_V }}" >> $GITHUB_ENV
Expand Down
5 changes: 5 additions & 0 deletions ci/meta_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,10 @@ pushd metapackage_mpi_c
"$fpm" run --verbose
popd

pushd metapackage_hdf5
"$fpm" build --verbose
"$fpm" run --verbose
popd

# Cleanup
rm -rf ./*/build
15 changes: 15 additions & 0 deletions example_packages/metapackage_hdf5/app/main.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
program metapackage_hdf5
use hdf5
implicit none

integer :: error

call h5open_f(error)
if (error/=0) stop -1

call h5close_f(error)
if (error/=0) stop -2

stop 0

end program metapackage_hdf5
2 changes: 2 additions & 0 deletions example_packages/metapackage_hdf5/fpm.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = "metapackage_hdf5"
dependencies.hdf5="*"
8 changes: 7 additions & 1 deletion src/fpm/manifest/meta.f90
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ module fpm_manifest_metapackages

!> fortran-lang minpack
type(metapackage_request_t) :: minpack

!> HDF5
type(metapackage_request_t) :: hdf5

end type metapackage_config_t

Expand Down Expand Up @@ -196,6 +199,9 @@ subroutine new_meta_config(self, table, meta_allowed, error)

call new_meta_request(self%mpi, "mpi", table, meta_allowed, error)
if (allocated(error)) return

call new_meta_request(self%hdf5, "hdf5", table, meta_allowed, error)
if (allocated(error)) return

end subroutine new_meta_config

Expand All @@ -208,7 +214,7 @@ logical function is_meta_package(key)
select case (key)

!> Supported metapackages
case ("openmp","stdlib","mpi","minpack")
case ("openmp","stdlib","mpi","minpack","hdf5")
is_meta_package = .true.

case default
Expand Down
18 changes: 9 additions & 9 deletions src/fpm/manifest/profiles.f90
Original file line number Diff line number Diff line change
Expand Up @@ -749,25 +749,25 @@ function get_default_profiles(error) result(default_profiles)
& 'ifort', &
& OS_ALL, &
& flags = ' -fp-model precise -pc64 -align all -error-limit 1 -reentrancy&
& threaded -nogen-interfaces -assume byterecl -standard-semantics', &
& threaded -nogen-interfaces -assume byterecl', &
& is_built_in=.true.), &
& new_profile('release', &
& 'ifort', &
& OS_WINDOWS, &
& flags = ' /fp:precise /align:all /error-limit:1 /reentrancy:threaded&
& /nogen-interfaces /assume:byterecl /standard-semantics', &
& /nogen-interfaces /assume:byterecl', &
& is_built_in=.true.), &
& new_profile('release', &
& 'ifx', &
& OS_ALL, &
& flags = ' -fp-model=precise -pc64 -align all -error-limit 1 -reentrancy&
& threaded -nogen-interfaces -assume byterecl -standard-semantics', &
& threaded -nogen-interfaces -assume byterecl', &
& is_built_in=.true.), &
& new_profile('release', &
& 'ifx', &
& OS_WINDOWS, &
& flags = ' /fp:precise /align:all /error-limit:1 /reentrancy:threaded&
& /nogen-interfaces /assume:byterecl /standard-semantics', &
& /nogen-interfaces /assume:byterecl', &
& is_built_in=.true.), &
& new_profile('release', &
&'nagfor', &
Expand Down Expand Up @@ -805,28 +805,28 @@ function get_default_profiles(error) result(default_profiles)
& new_profile('debug', &
& 'ifort', &
& OS_ALL, &
& flags = ' -warn all -check all -error-limit 1 -O0 -g -assume byterecl -standard-semantics -traceback', &
& flags = ' -warn all -check all -error-limit 1 -O0 -g -assume byterecl -traceback', &
& is_built_in=.true.), &
& new_profile('debug', &
& 'ifort', &
& OS_WINDOWS, &
& flags = ' /warn:all /check:all /error-limit:1&
& /Od /Z7 /assume:byterecl /standard-semantics /traceback', &
& /Od /Z7 /assume:byterecl /traceback', &
& is_built_in=.true.), &
& new_profile('debug', &
& 'ifx', &
& OS_ALL, &
& flags = ' -warn all -check all -error-limit 1 -O0 -g -assume byterecl -standard-semantics -traceback', &
& flags = ' -warn all -check all -error-limit 1 -O0 -g -assume byterecl -traceback', &
& is_built_in=.true.), &
& new_profile('debug', &
& 'ifx', &
& OS_WINDOWS, &
& flags = ' /warn:all /check:all /error-limit:1 /Od /Z7 /assume:byterecl /standard-semantics', &
& flags = ' /warn:all /check:all /error-limit:1 /Od /Z7 /assume:byterecl', &
& is_built_in=.true.), &
& new_profile('debug', &
& 'ifx', &
& OS_WINDOWS, &
& flags = ' /warn:all /check:all /error-limit:1 /Od /Z7 /assume:byterecl /standard-semantics', &
& flags = ' /warn:all /check:all /error-limit:1 /Od /Z7 /assume:byterecl', &
& is_built_in=.true.), &
& new_profile('debug', &
& 'lfortran', &
Expand Down
22 changes: 6 additions & 16 deletions src/fpm_compiler.F90
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,7 @@ subroutine get_release_compile_flags(id, flags)
flag_intel_limit//&
flag_intel_pthread//&
flag_intel_nogen//&
flag_intel_byterecl//&
flag_intel_standard_compliance
flag_intel_byterecl

case(id_intel_classic_mac)
flags = &
Expand All @@ -320,8 +319,7 @@ subroutine get_release_compile_flags(id, flags)
flag_intel_limit//&
flag_intel_pthread//&
flag_intel_nogen//&
flag_intel_byterecl//&
flag_intel_standard_compliance
flag_intel_byterecl

case(id_intel_classic_windows)
flags = &
Expand All @@ -331,8 +329,7 @@ subroutine get_release_compile_flags(id, flags)
flag_intel_limit_win//&
flag_intel_pthread_win//&
flag_intel_nogen_win//&
flag_intel_byterecl_win//&
flag_intel_standard_compliance_win
flag_intel_byterecl_win

case(id_intel_llvm_nix)
flags = &
Expand All @@ -342,8 +339,7 @@ subroutine get_release_compile_flags(id, flags)
flag_intel_limit//&
flag_intel_pthread//&
flag_intel_nogen//&
flag_intel_byterecl//&
flag_intel_standard_compliance
flag_intel_byterecl

case(id_intel_llvm_windows)
flags = &
Expand All @@ -353,8 +349,7 @@ subroutine get_release_compile_flags(id, flags)
flag_intel_limit_win//&
flag_intel_pthread_win//&
flag_intel_nogen_win//&
flag_intel_byterecl_win//&
flag_intel_standard_compliance_win
flag_intel_byterecl_win

case(id_nag)
flags = &
Expand Down Expand Up @@ -418,7 +413,6 @@ subroutine get_debug_compile_flags(id, flags)
flag_intel_limit//&
flag_intel_debug//&
flag_intel_byterecl//&
flag_intel_standard_compliance//&
flag_intel_backtrace

case(id_intel_classic_mac)
Expand All @@ -428,7 +422,6 @@ subroutine get_debug_compile_flags(id, flags)
flag_intel_limit//&
flag_intel_debug//&
flag_intel_byterecl//&
flag_intel_standard_compliance//&
flag_intel_backtrace
case(id_intel_classic_windows)
flags = &
Expand All @@ -437,7 +430,6 @@ subroutine get_debug_compile_flags(id, flags)
flag_intel_limit_win//&
flag_intel_debug_win//&
flag_intel_byterecl_win//&
flag_intel_standard_compliance_win//&
flag_intel_backtrace_win
case(id_intel_llvm_nix)
flags = &
Expand All @@ -446,16 +438,14 @@ subroutine get_debug_compile_flags(id, flags)
flag_intel_limit//&
flag_intel_debug//&
flag_intel_byterecl//&
flag_intel_standard_compliance//&
flag_intel_backtrace
case(id_intel_llvm_windows)
flags = &
flag_intel_warn_win//&
flag_intel_check_win//&
flag_intel_limit_win//&
flag_intel_debug_win//&
flag_intel_byterecl_win//&
flag_intel_standard_compliance_win
flag_intel_byterecl_win
case(id_nag)
flags = &
flag_nag_debug//&
Expand Down
38 changes: 38 additions & 0 deletions src/fpm_environment.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <stdlib.h>
#include <stdio.h>

/// @brief Set environment variable using the C standard library
/// @param envname: points to a string containing the name of an environment variable to be added or altered.
/// @param envval: points to the value the environment variable is set to
/// @param overwrite: flag to determine whether an old value should be overwritten
/// @return success flag, 0 on successful execution
int c_setenv(const char *envname, const char *envval, int overwrite) {
#ifndef _WIN32
return setenv(envname, envval, overwrite);
#else
int errcode = 0;
if(!overwrite) {
size_t envsize = 0;
errcode = getenv_s(&envsize, NULL, 0, envname);
if (errcode || envsize) return errcode;
}
return _putenv_s(envname, envval);
#endif
}

/// @brief Delete environment variable using the C standard library
/// @param envname: points to a string containing the name of an environment variable.
/// @return success flag, 0 on successful execution
int c_unsetenv(const char *envname) {
#ifndef _WIN32
return unsetenv(envname);
#else
char* str = malloc(64*sizeof(char));
*str = '\0';
int errcode = _putenv_s(envname,str);
// Windows returns a non-0 code when setting empty variable
if (errcode==-1) errcode=0;
free(str);
return errcode;
#endif
}
Loading

0 comments on commit 4030a8a

Please sign in to comment.