Skip to content

Commit

Permalink
simplify OpenMP support
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Pippig committed May 5, 2015
2 parents ad98d63 + d51ff30 commit bb2e9f1
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 86 deletions.
35 changes: 8 additions & 27 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -28,50 +28,31 @@ endif

EXTRA_DIST = bootstrap.sh CONVENTIONS pfft.pc.in

LIBPFFT_OMP_LA =
if ENABLE_OPENMP
LIBPFFT_OMP_LA += lib@PFFT_PREFIX@pfft@PREC_SUFFIX@_omp.la
endif

# Libraries that are built and installed.
# set library name according to precision
if ENABLE_LIBRARY_INSTALL
lib_LTLIBRARIES = lib@PFFT_PREFIX@pfft@PREC_SUFFIX@.la $(LIBPFFT_OMP_LA)
lib_LTLIBRARIES = lib@PFFT_PREFIX@pfft@PREC_SUFFIX@@OPENMP_SUFFIX@.la
else
noinst_LTLIBRARIES = lib@PFFT_PREFIX@pfft@PREC_SUFFIX@.la $(LIBPFFT_OMP_LA)
noinst_LTLIBRARIES = lib@PFFT_PREFIX@pfft@PREC_SUFFIX@@OPENMP_SUFFIX@.la
endif


# Libtool convenience libraries.
lib@PFFT_PREFIX@pfft@PREC_SUFFIX@_la_SOURCES =
lib@PFFT_PREFIX@pfft@PREC_SUFFIX@_la_LIBADD = \
lib@PFFT_PREFIX@pfft@PREC_SUFFIX@@OPENMP_SUFFIX@_la_SOURCES =
lib@PFFT_PREFIX@pfft@PREC_SUFFIX@@OPENMP_SUFFIX@_la_LIBADD = \
kernel/libkernel.la \
util/libutil.la \
api/libapi.la \
gcell/libgcell.la

lib@PFFT_PREFIX@pfft@PREC_SUFFIX@_la_LDFLAGS = -no-undefined -version-info @SHARED_VERSION_INFO@


if ENABLE_OPENMP
# Libtool convenience libraries.
lib@PFFT_PREFIX@pfft@PREC_SUFFIX@_omp_la_SOURCES =
lib@PFFT_PREFIX@pfft@PREC_SUFFIX@_omp_la_LIBADD = \
kernel/libkernel.la \
util/libutil.la \
api/libapi_omp.la \
gcell/libgcell.la

lib@PFFT_PREFIX@pfft@PREC_SUFFIX@_omp_la_LDFLAGS = -no-undefined -version-info @SHARED_VERSION_INFO@
lib@PFFT_PREFIX@pfft@PREC_SUFFIX@_omp_la_CFLAGS = $(OPENMP_CFLAGS)
endif

lib@PFFT_PREFIX@pfft@PREC_SUFFIX@@OPENMP_SUFFIX@_la_LDFLAGS = -no-undefined -version-info @SHARED_VERSION_INFO@
lib@PFFT_PREFIX@pfft@PREC_SUFFIX@@OPENMP_SUFFIX@_la_CFLAGS = $(OPENMP_CFLAGS)

# Get Fortran compile rules that include preprocessing.
include $(top_srcdir)/build-aux/fortran-rules.am

pfft1@PREC_SUFFIX@.pc: pfft.pc
cp -f pfft.pc pfft1@PREC_SUFFIX@.pc
pfft1@PREC_SUFFIX@@OPENMP_SUFFIX@.pc: pfft.pc
cp -f pfft.pc pfft1@PREC_SUFFIX@@OPENMP_SUFFIX@.pc


#################################################################
Expand Down
27 changes: 5 additions & 22 deletions api/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ AM_CPPFLAGS = -I$(top_srcdir)/kernel
# Directory of util.h
AM_CPPFLAGS += -I$(top_srcdir)/util

# OpenMP support
AM_CFLAGS = $(OPENMP_CFLAGS)
AM_CPPFLAGS += $(OPENMP_CFLAGS)

# Headers that are installed.
if ENABLE_HEADER_INSTALL
include_HEADERS = pfft.h
Expand All @@ -13,12 +17,7 @@ else
noinst_HEADERS = pfft.h
endif

LIBAPI_OMP_LA =
if ENABLE_OPENMP
LIBAPI_OMP_LA += libapi_omp.la
endif

noinst_LTLIBRARIES = libapi.la $(LIBAPI_OMP_LA)
noinst_LTLIBRARIES = libapi.la

EXTRA_DIST = f03-api.sh f03-wrap.sh genf03-api.pl genf03-wrap.pl build-f03-api.sh

Expand All @@ -35,19 +34,3 @@ libapi_la_SOURCES = \
pfftl.f03.in \
f03-wrap.c

if ENABLE_OPENMP
libapi_omp_la_CFLAGS = $(OPENMP_CFLAGS)

# Group local sources into convenience lib.
libapi_omp_la_SOURCES = \
api-basic.c \
api-adv.c \
pfft.f.in \
fortran-api.c \
fortran-mangling.h \
fortran-prototypes.h \
fortran-wrappers.h \
pfft.f03.in \
pfftl.f03.in \
f03-wrap.c
endif
35 changes: 26 additions & 9 deletions api/api-basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,39 @@ static R check_array(



#ifdef _OPENMP
#include <omp.h>
static int _nthreads;
#endif

void PX(plan_with_nthreads) (int nthreads){
#ifdef _OPENMP
_nthreads = nthreads;
X(plan_with_nthreads)(nthreads);
#endif
}

int PX(get_nthreads)() {
#ifdef _OPENMP
return _nthreads;
#else
return 1;
#endif
}

/* wrappers for fftw init and cleanup */
void PX(init) (void){
#ifdef _OPENMP
X(init_threads)();
PX(plan_with_nthreads)(omp_get_max_threads());
#endif
XM(init)();
}

void PX(cleanup) (void){
#ifdef _OPENMP
X(cleanup_threads());
#endif
XM(cleanup)();
}

Expand Down Expand Up @@ -1277,12 +1303,3 @@ static void execute_transposed(
PFFT_FINISH_TIMING(timer_trafo[t]);
}

#if _OPENMP
void PX(plan_with_nthreads)(
int nthreads
)
{
X(plan_with_nthreads)(nthreads);
}
#endif

4 changes: 2 additions & 2 deletions api/pfft.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ BEGIN_C_DECLS
\
PFFT_EXTERN void PX(init)(void); \
PFFT_EXTERN void PX(cleanup)(void); \
PFFT_EXTERN void PX(plan_with_nthreads)(int nthreads); \
PFFT_EXTERN int PX(get_nthreads)(void); \
\
PFFT_EXTERN void *PX(malloc)(size_t n); \
PFFT_EXTERN R *PX(alloc_real)(size_t n); \
Expand Down Expand Up @@ -380,8 +382,6 @@ BEGIN_C_DECLS
int neededArgs, unsigned type, \
void *parameter); \
\
PFFT_EXTERN void PX(plan_with_nthreads)(int nthreads); \
\
\
PFFT_EXTERN void PX(reset_timer)( \
PX(plan) ths); \
Expand Down
47 changes: 28 additions & 19 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@ AM_INIT_AUTOMAKE([1.9.6 foreign])
# options for customizing the build process
################################################################################

# multithreaded code
AC_ARG_ENABLE(threads,
[AS_HELP_STRING([--enable-threads], [enable multithreaded code])],
enable_threads=$enableval, enable_threads=no)
AM_CONDITIONAL([HAVE_THREADS], [test "x$enable_threads" = "xyes"])

# debug mode
AC_ARG_ENABLE(debug,
[AS_HELP_STRING([--enable-debug], [compile with extra runtime checks for debugging])],
Expand Down Expand Up @@ -229,6 +223,27 @@ fi
AC_LANG_POP([Fortran])


################################################################################
# Parallel characteristics
################################################################################

# disable OpenMP on default as long as it does not work perfectly
: ${enable_openmp=no}
AC_OPENMP

if test "$enable_openmp" = "yes"; then
OPENMP_SUFFIX="_omp"
else
OPENMP_SUFFIX=
fi
AC_SUBST(OPENMP_SUFFIX) # append _omp to library pfft name
AM_CONDITIONAL(ENABLE_OPENMP, test "x$enable_openmp" = "xyes")

AC_LANG_PUSH([Fortran])
: ${enable_openmp=no}
AC_OPENMP
AC_LANG_POP([Fortran])

################################################################################
# Libtool initialization
################################################################################
Expand Down Expand Up @@ -265,15 +280,6 @@ AC_SUBST(SHARED_VERSION_INFO)
# May need sincos from libm.
AC_CHECK_LIB([m], [sincos])

# Check for OpenMP.
AC_ARG_ENABLE(openmp, [AS_HELP_STRING([--enable-openmp],[use OpenMP directives for parallelism])],
[enable_openmp=$enableval], [enable_openmp=no])
if test "$enable_openmp" = "yes"; then
AX_OPENMP([],[AC_MSG_ERROR([Do not know how to enable OpenMP])])
fi
AM_CONDITIONAL(ENABLE_OPENMP, test "x$enable_openmp" = "xyes")
AC_SUBST(OPENMP_CFLAGS)

# Check for FFTW3, MPI FFTW and threaded FFTW.
if test "x$PRECISION" = "xs" ; then
AX_LIB_FFTW3F
Expand All @@ -284,8 +290,8 @@ else
fi

if test "x$ax_lib_fftw3" = "xno"; then
AC_MSG_ERROR([You do not seem to have the FFTW-3.3 library installed. You can ]
[download it from http://www.fftw.org. If you have installed FFTW-3.3, ]
AC_MSG_ERROR([You do not seem to have the FFTW-3.3 library installed.]
[You can download it from http://www.fftw.org. If you have installed FFTW-3.3, ]
[make sure that this configure script can find it. See ./configure ]
[--help for more information.])
fi
Expand All @@ -297,8 +303,11 @@ if test "x$ax_lib_fftw3_mpi" = "xno"; then
[for more information.])
fi

if test "x$enable_threads" = "xyes" -a "x$ax_lib_fftw3_threads" = "xno"; then
AC_MSG_ERROR([You do not seem to have the threaded FFTW-3.3 library installed.])
if test "x$enable_openmp" = "xyes" -a "x$ax_lib_fftw3_openmp" = "xno"; then
AC_MSG_ERROR([You do not seem to have the OpenMP part of the FFTW-3.3 library installed.]
[You can download it from http://www.fftw.org. If you have installed FFTW-3.3, ]
[make sure that this configure script can find it. See ./configure --help]
[for more information.])
fi


Expand Down
6 changes: 4 additions & 2 deletions m4/ax_lib_fftw3.m4
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ AC_DEFUN([_AX_LIB_FFTW3_CHECK],[
fftw3_LDFLAGS=
fftw3_PREFIX=
fftw3_LIBS=
fftw3_openmp_LIBS=
fftw3_threads_LIBS=
fftw3_mpi_LIBS=
Expand Down Expand Up @@ -169,6 +170,7 @@ AC_DEFUN([_AX_LIB_FFTW3_CHECK],[
ax_lib_fftw3=no
ax_lib_fftw3_threads=no
ax_lib_fftw3_openmp=no
ax_lib_fftw3_mpi=no
fftw3_PREFIX="$ax_with_fftw3_prefix"
Expand All @@ -190,11 +192,11 @@ AC_DEFUN([_AX_LIB_FFTW3_CHECK],[
ax_lib_fftw3_threads=no
;;
esac
ax_lib_fftw3_openmp=yes
case $ac_configure_args in
*--enable-openmp*)
fftw3_openmp_LIBS="-l${ax_with_fftw3_prefix}fftw3${ax_type_suffix}_omp"
fftw3_threads_LIBS="-l${ax_with_fftw3_prefix}fftw3${ax_type_suffix}_omp"
;;
*)
ax_lib_fftw3_openmp=no
Expand Down
5 changes: 4 additions & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ AM_CPPFLAGS = -I$(top_srcdir)/kernel
# Directory of pfft.h
AM_CPPFLAGS += -I$(top_srcdir)/api

# OpenMP support
AM_CFLAGS = $(OPENMP_CFLAGS)

# Libraries to add to all programs that are built.
LDADD = $(top_builddir)/lib@PFFT_PREFIX@pfft@PREC_SUFFIX@.la $(fftw3_mpi_LIBS) $(fftw3_LIBS)
LDADD = $(top_builddir)/lib@PFFT_PREFIX@pfft@PREC_SUFFIX@@OPENMP_SUFFIX@.la $(fftw3_openmp_LIBS) $(fftw3_mpi_LIBS) $(fftw3_LIBS)


EXTRA_DIST = \
Expand Down
3 changes: 3 additions & 0 deletions tests/bench_c2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ static void init_parameters(

pfft_printf(MPI_COMM_WORLD, "******************************************************************************************************\n");
pfft_printf(MPI_COMM_WORLD, "* Computation of loops=%d parallel forward and backward FFTs (change with -pfft_loops *)\n", *loops);
#ifdef _OPENMP
pfft_printf(MPI_COMM_WORLD, "* of with %d threads per process (change with OMP_NUM_THREADS=* before the command line) \n", pfft_get_nthreads());
#endif
pfft_printf(MPI_COMM_WORLD, "* for n[0] x n[1] x n[2] = %td x %td x %td Fourier coefficients (change with -pfft_n * * *)\n", n[0], n[1], n[2]);
pfft_printf(MPI_COMM_WORLD, "* on np[0] x np[1] x np[2] = %td x %td x %td processes (change with -pfft_np * * *)\n", np[0], np[1], np[2]);

Expand Down
5 changes: 4 additions & 1 deletion tests/f03/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ include $(top_srcdir)/build-aux/fortran-rules.am
# Directory of pnfft.f (which is build first)
AM_FCCPPFLAGS = -I$(top_builddir)/api

# OpenMP support
AM_FCFLAGS = $(OPENMP_FCFLAGS)

# Libraries to add to all programs that are built.
LDADD = $(top_builddir)/lib@PFFT_PREFIX@pfft@PREC_SUFFIX@.la $(fftw3_mpi_LIBS) $(fftw3_LIBS)
LDADD = $(top_builddir)/lib@PFFT_PREFIX@pfft@PREC_SUFFIX@@OPENMP_SUFFIX@.la $(fftw3_openmp_LIBS) $(fftw3_mpi_LIBS) $(fftw3_LIBS)

# noinst_LTLIBRARIES = libtests.la

Expand Down
5 changes: 4 additions & 1 deletion tests/fortran/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ include $(top_srcdir)/build-aux/fortran-rules.am
# Directory of pfft.f (which is build first)
AM_FCCPPFLAGS = -I$(top_builddir)/api

# OpenMP support
AM_FCFLAGS = $(OPENMP_FCFLAGS)

# Libraries to add to all programs that are built.
LDADD = $(top_builddir)/lib@PFFT_PREFIX@pfft@PREC_SUFFIX@.la $(fftw3_mpi_LIBS) $(fftw3_LIBS)
LDADD = $(top_builddir)/lib@PFFT_PREFIX@pfft@PREC_SUFFIX@@OPENMP_SUFFIX@.la $(fftw3_openmp_LIBS) $(fftw3_mpi_LIBS) $(fftw3_LIBS)

# noinst_LTLIBRARIES = libtests.la

Expand Down
5 changes: 3 additions & 2 deletions tests/openmp/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ AM_CPPFLAGS = -I$(top_srcdir)/kernel
# Directory of pfft.h
AM_CPPFLAGS += -I$(top_srcdir)/api

# OpenMP support
AM_CFLAGS = $(OPENMP_CFLAGS)

# Libraries to add to all programs that are built.
LDADD = $(top_builddir)/lib@PFFT_PREFIX@pfft@PREC_SUFFIX@_omp.la $(fftw3_openmp_LIBS) $(fftw3_mpi_LIBS) $(fftw3_LIBS)

AM_CFLAGS = $(OPENMP_CFLAGS)

# These programs are built by 'make check' and may be tested afterwards.
check_PROGRAMS = \
simple_check_c2c simple_check_c2c_transposed\
Expand Down

0 comments on commit bb2e9f1

Please sign in to comment.