diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 37f4487f..42b94020 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,7 +18,7 @@ jobs: QUAD_P: ${{ matrix.enable_quad_precision }} steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: submodules: recursive - name: Configure diff --git a/configure.ac b/configure.ac index 483fa679..a932a204 100644 --- a/configure.ac +++ b/configure.ac @@ -87,9 +87,15 @@ AM_CONDITIONAL([WITH_MPI_TESTS], [test x"$build_mpi" = x"yes" -a -z "$SKIP_MPI_T #Build with OpenACC suport. Default is 'no' AC_ARG_ENABLE([acc], - [AS_HELP_STRING([--enable-acc], [Build with OpenACC support. Defaults to 'no'])] ) -AS_IF([test ${enable_acc:-no} = "yes"], [enable_acc=yes], [enable_acc=no]) -AM_CONDITIONAL([ENABLE_ACC], [test $enable_acc = "yes"]) + [AS_HELP_STRING([--enable-acc], + [Builds with OpenACC. This will result in a second executable for fregrid, fregrid_gpu.(default no)])]) +AS_IF([test ${enable_acc:-no} = yes], + [enable_acc=yes], + [enable_acc=no]) +# check compile flags +AS_IF([test ${enable_acc} = yes], + [GX_OPENACC_FLAGS()]) +AM_CONDITIONAL([ENABLE_ACC], [test "$enable_acc" = "yes"]) AC_CHECK_FUNCS(gettid, [], []) @@ -123,7 +129,7 @@ AC_CHECK_PROGS(PROVE, [prove]) AM_CONDITIONAL([WITH_CHECK_PROGS], [test -n "$PROVE" -a -n "$BATS"]) # Check if openacc.h exists -if test $enable_acc = yes ; then +if test "$enable_acc" = yes ; then AC_CHECK_HEADERS([openacc.h], [], [AC_MSG_ERROR(["Cannot find OpenACC header file"])] ) AC_MSG_WARN(Currently only NVIDIA compilers are supported to compile with OpenACC in FRE-NCTOOLS) fi diff --git a/m4/gx_openacc_flags.m4 b/m4/gx_openacc_flags.m4 new file mode 100644 index 00000000..2a58c894 --- /dev/null +++ b/m4/gx_openacc_flags.m4 @@ -0,0 +1,74 @@ +# =========================================================================== +# +# SYNOPSIS +# +# GX_OPENACC_FLAGS() +# +# DESCRIPTION +# +# Checks C compiler flags for openacc support. +# +# LICENSE +# +# Copyright (c) 2024 Ryan Mulhall +# +# This program 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 3 of the License, or (at your +# option) any later version. +# +# This program 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 this program. If not, see . +# +# As a special exception, the respective Autoconf Macro's copyright owner +# gives unlimited permission to copy, distribute and modify the configure +# scripts that are the output of Autoconf when processing the Macro. You +# need not follow the terms of the GNU General Public License when using +# or distributing such scripts, even though portions of the text of the +# Macro appear in them. The GNU General Public License (GPL) does govern +# all other use of the material that constitutes the Autoconf Macro. + +# ---------------------------------------------------------------------- +# +# Will set OPENACC_CFLAGS to openacc flags for a given compiler if accepted. +# +# Mainly for nvhpc, offloading with gcc is not currently supported, +# although the build will still work. +# +AC_DEFUN([GX_OPENACC_FLAGS],[ +AC_CACHE_CHECK([whether C compiler accepts OpenACC flags], [gx_cv_openacc_flags],[ + +AC_LANG_ASSERT(C) +gx_cv_openacc_flags=unknown +gx_openacc_flags_CFLAGS_save=$CFLAGS + +dnl check for base openacc flag +for ac_flag in '-acc' \ + '-fopenacc'; do + AC_LINK_IFELSE([AC_LANG_SOURCE( + extern int acc_get_device_type(); + int main(int argc, char** argv){ + acc_get_device_type(); + return 0; + })], + [gx_cv_openacc_flags="$gx_openacc_flags_CFLAGS_save ${ac_flag}"]; break) +done +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext + +CFLAGS="$gx_openacc_flags_CFLAGS_save" + +if test "x$gx_cv_openacc_flags" = xunknown; then + m4_default([$2], + [AC_MSG_ERROR([no])]) +else + OPENACC_CFLAGS="${gx_cv_openacc_flags}" + AC_MSG_RESULT([yes]) +fi +], +AC_SUBST([OPENACC_CFLAGS]) +)]) diff --git a/tools/fregrid_acc/Makefile.am b/tools/fregrid_acc/Makefile.am index fdbc7101..83fa30d3 100644 --- a/tools/fregrid_acc/Makefile.am +++ b/tools/fregrid_acc/Makefile.am @@ -21,7 +21,8 @@ bin_PROGRAMS = fregrid_acc AM_CFLAGS = -I$(top_srcdir)/tools/libfrencutils $(NETCDF_CFLAGS) \ -I$(top_srcdir)/tools/libfrencutils_acc \ - -I$(top_srcdir)/tools/fregrid -acc + -I$(top_srcdir)/tools/fregrid \ + $(OPENACC_CFLAGS) LDADD = $(NETCDF_LDFLAGS) $(NETCDF_LIBS) $(RPATH_FLAGS) fregrid_acc_SOURCES = conserve_interp_acc.c \ diff --git a/tools/libfrencutils_acc/Makefile.am b/tools/libfrencutils_acc/Makefile.am index 7bafc27f..2ae3aafa 100644 --- a/tools/libfrencutils_acc/Makefile.am +++ b/tools/libfrencutils_acc/Makefile.am @@ -19,7 +19,7 @@ #*********************************************************************** noinst_LIBRARIES = libfrencutils_acc.a -AM_CFLAGS = $(NETCDF_CFLAGS) -I$(top_srcdir)/tools/libfrencutils -acc +AM_CFLAGS = $(NETCDF_CFLAGS) $(OPENACC_CFLAGS) -I$(top_srcdir)/tools/libfrencutils libfrencutils_acc_a_SOURCES = create_xgrid_acc.c \ create_xgrid_acc.h diff --git a/tools/mppncscatter/mppncscatter.c b/tools/mppncscatter/mppncscatter.c index dc2bb96b..0ad2aa81 100644 --- a/tools/mppncscatter/mppncscatter.c +++ b/tools/mppncscatter/mppncscatter.c @@ -44,6 +44,8 @@ #define CHECK_NC_ERRSTAT(ierr) check_error(ierr,__FILE__,__LINE__) +void check_error(int ierr, const char* file, int line); + /*-------------------------------------------------------------------*/ void printsizetarray(size_t *a, int n) { int i=0;