From 6325f6da678c54b3ec750f400474eed1e0d4413e Mon Sep 17 00:00:00 2001 From: William Throwe Date: Thu, 5 Dec 2024 15:06:06 -0500 Subject: [PATCH 1/3] Ignore external in various QA checks --- .github/workflows/Tests.yaml | 4 ++-- tools/Hooks/pre-commit.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/Tests.yaml b/.github/workflows/Tests.yaml index 052bad44bdf3..466a95769cda 100644 --- a/.github/workflows/Tests.yaml +++ b/.github/workflows/Tests.yaml @@ -152,9 +152,9 @@ jobs: run: | cd $GITHUB_WORKSPACE echo "Using 'black' to check Python formatting..." - black --check . + black --check --extend-exclude '/external/' . echo "Using 'isort' to check Python formatting..." - isort --check-only . + isort --check-only --extend-skip external . - name: Test script run: | cd $GITHUB_WORKSPACE diff --git a/tools/Hooks/pre-commit.sh b/tools/Hooks/pre-commit.sh index 0a36cb50472f..210b9494c860 100755 --- a/tools/Hooks/pre-commit.sh +++ b/tools/Hooks/pre-commit.sh @@ -9,7 +9,7 @@ # Get list of non-deleted file names, which we need below. commit_files=() while IFS= read -r -d '' file ; do - if [ -f "${file}" ]; then + if [ -f "${file}" ] && [[ ${file} != external/*/* ]] ; then commit_files+=("${file}") fi done < <(@GIT_EXECUTABLE@ diff --cached --name-only -z) From d0afa3a0025559c3aa406c04163fa173a0176fa5 Mon Sep 17 00:00:00 2001 From: William Throwe Date: Fri, 6 Dec 2024 15:55:41 -0500 Subject: [PATCH 2/3] Set clang FPE flags for C targets --- cmake/AddCxxFlag.cmake | 66 ++++++++++++++++++++++++++++++++------- cmake/SetupCxxFlags.cmake | 4 +++ 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/cmake/AddCxxFlag.cmake b/cmake/AddCxxFlag.cmake index 3273325ab828..36ebccef9020 100644 --- a/cmake/AddCxxFlag.cmake +++ b/cmake/AddCxxFlag.cmake @@ -1,40 +1,61 @@ # Distributed under the MIT License. # See LICENSE.txt for details. -# Checks if a CXX flag is supported by the compiler and creates the target +# Checks if a flag is supported by the compiler and creates the target # TARGET_NAME whose INTERFACE_COMPILE_OPTIONS are set to the FLAG_TO_CHECK +# - LANGUAGE: language to check, setting the compiler and generated property +# - XTYPE: language as passed to the -x compiler flag # - FLAG_TO_CHECK: the CXX flag to add if the compiler supports it # - TARGET_NAME: the name of the target whose INTERFACE_COMPILE_OPTIONS are # set -function(create_cxx_flag_target FLAG_TO_CHECK TARGET_NAME) +function(create_compile_flag_target LANGUAGE XTYPE FLAG_TO_CHECK TARGET_NAME) # In order to check for a -Wno-* flag in gcc, you have to check the # -W* version instead. See http://gcc.gnu.org/wiki/FAQ#wnowarning string(REGEX REPLACE ^-Wno- -W POSITIVE_FLAG_TO_CHECK ${FLAG_TO_CHECK}) execute_process( COMMAND bash -c - "LC_ALL=POSIX ${CMAKE_CXX_COMPILER} -Werror ${POSITIVE_FLAG_TO_CHECK} \ --x c++ -c - <<< \"\" -o /dev/null" + "LC_ALL=POSIX ${CMAKE_${LANGUAGE}_COMPILER} -Werror \ +${POSITIVE_FLAG_TO_CHECK} -x ${XTYPE} -c - <<< \"\" -o /dev/null" RESULT_VARIABLE RESULT ERROR_VARIABLE ERROR_FROM_COMPILATION OUTPUT_QUIET) - add_library(${TARGET_NAME} INTERFACE) + if(NOT TARGET ${TARGET_NAME}) + add_library(${TARGET_NAME} INTERFACE) + endif(NOT TARGET ${TARGET_NAME}) if(${RESULT} EQUAL 0) set_property(TARGET ${TARGET_NAME} APPEND PROPERTY - INTERFACE_COMPILE_OPTIONS $<$:${FLAG_TO_CHECK}>) + INTERFACE_COMPILE_OPTIONS + $<$:${FLAG_TO_CHECK}>) endif(${RESULT} EQUAL 0) endfunction() +# Checks if a CXX flag is supported by the compiler and creates the target +# TARGET_NAME whose INTERFACE_COMPILE_OPTIONS are set to the FLAG_TO_CHECK +# - FLAG_TO_CHECK: the CXX flag to add if the compiler supports it +# - TARGET_NAME: the name of the target whose INTERFACE_COMPILE_OPTIONS are +# set +function(create_cxx_flag_target FLAG_TO_CHECK TARGET_NAME) + create_compile_flag_target(CXX c++ "${FLAG_TO_CHECK}" "${TARGET_NAME}") +endfunction() + +# Same, but for C. +function(create_c_flag_target FLAG_TO_CHECK TARGET_NAME) + create_compile_flag_target(C c "${FLAG_TO_CHECK}" "${TARGET_NAME}") +endfunction() + # Checks which of the CXX FLAGS_TO_CHECK are supported by the compiler # and creates the target TARGET_NAME whose INTERFACE_COMPILE_OPTIONS # are set to the FLAGS_TO_CHECK that are supported. If adding many flags, # this will be much faster than calling create_cxx_flags_target multiple times. +# - LANGUAGE: language to check, setting the compiler and generated property +# - XTYPE: language as passed to the -x compiler flag # - FLAGS_TO_CHECK: a semicolon separated string of CXX flags to try to add # for compilation. # - TARGET_NAME: the name of the target whose INTERFACE_COMPILE_OPTIONS are # set -function(create_cxx_flags_target FLAGS_TO_CHECK TARGET_NAME) +function(create_compile_flags_target LANGUAGE XTYPE FLAGS_TO_CHECK TARGET_NAME) # In order to check for a -Wno-* flag in gcc, you have to check the # -W* version instead. See http://gcc.gnu.org/wiki/FAQ#wnowarning set(POSITIVE_FLAGS_TO_CHECK) @@ -47,17 +68,20 @@ function(create_cxx_flags_target FLAGS_TO_CHECK TARGET_NAME) execute_process( COMMAND bash -c - "LC_ALL=POSIX ${CMAKE_CXX_COMPILER} -Werror ${POSITIVE_FLAGS_WITH_SPACES} \ --x c++ -c - <<< \"\" -o /dev/null" + "LC_ALL=POSIX ${CMAKE_${LANGUAGE}_COMPILER} -Werror \ +${POSITIVE_FLAGS_WITH_SPACES} -x ${XTYPE} -c - <<< \"\" -o /dev/null" RESULT_VARIABLE RESULT ERROR_VARIABLE ERROR_FROM_COMPILATION OUTPUT_QUIET) - add_library(${TARGET_NAME} INTERFACE) + if(NOT TARGET ${TARGET_NAME}) + add_library(${TARGET_NAME} INTERFACE) + endif(NOT TARGET ${TARGET_NAME}) if(${RESULT} EQUAL 0) set_property(TARGET ${TARGET_NAME} APPEND PROPERTY - INTERFACE_COMPILE_OPTIONS $<$:${FLAGS_TO_CHECK}>) + INTERFACE_COMPILE_OPTIONS + $<$:${FLAGS_TO_CHECK}>) else(${RESULT} EQUAL 0) # Check each flag to see if it was marked as "invalid" in the output unset(FLAGS_TO_ADD) @@ -96,11 +120,29 @@ function(create_cxx_flags_target FLAGS_TO_CHECK TARGET_NAME) endforeach(FLAG ${FLAGS_TO_CHECK}) set_property(TARGET ${TARGET_NAME} APPEND PROPERTY - INTERFACE_COMPILE_OPTIONS $<$:${FLAGS_TO_ADD}>) + INTERFACE_COMPILE_OPTIONS + $<$:${FLAGS_TO_ADD}>) endif(${RESULT} EQUAL 0) endfunction() +# Checks which of the CXX FLAGS_TO_CHECK are supported by the compiler +# and creates the target TARGET_NAME whose INTERFACE_COMPILE_OPTIONS +# are set to the FLAGS_TO_CHECK that are supported. If adding many flags, +# this will be much faster than calling create_cxx_flags_target multiple times. +# - FLAGS_TO_CHECK: a semicolon separated string of CXX flags to try to add +# for compilation. +# - TARGET_NAME: the name of the target whose INTERFACE_COMPILE_OPTIONS are +# set +function(create_cxx_flags_target FLAGS_TO_CHECK TARGET_NAME) + create_compile_flags_target(CXX c++ "${FLAGS_TO_CHECK}" "${TARGET_NAME}") +endfunction() + +# Same, but for C. +function(create_c_flags_target FLAGS_TO_CHECK TARGET_NAME) + create_compile_flags_target(C c "${FLAGS_TO_CHECK}" "${TARGET_NAME}") +endfunction() + set(CMAKE_SUPPORTS_LINK_OPTIONS OFF) if(CMAKE_VERSION VERSION_EQUAL 3.13 OR CMAKE_VERSION VERSION_GREATER 3.13) set(CMAKE_SUPPORTS_LINK_OPTIONS ON) diff --git a/cmake/SetupCxxFlags.cmake b/cmake/SetupCxxFlags.cmake index 9a7f9b4c6838..0c44b581d873 100644 --- a/cmake/SetupCxxFlags.cmake +++ b/cmake/SetupCxxFlags.cmake @@ -153,6 +153,10 @@ set_property(TARGET SpectreFlags # floating point exceptions are ignored. # -fnon-call-exceptions - By default, GCC does not allow signal handlers to # throw exceptions. +create_c_flags_target( + "-ffp-exception-behavior=maytrap;-fnon-call-exceptions" + SpectreFpExceptions + ) create_cxx_flags_target( "-ffp-exception-behavior=maytrap;-fnon-call-exceptions" SpectreFpExceptions From 7a0d6b49c071c54286c23204b2812caf71dc0f6a Mon Sep 17 00:00:00 2001 From: William Throwe Date: Thu, 5 Dec 2024 15:09:13 -0500 Subject: [PATCH 3/3] Drop modifications to libsharp I do not believe we are allowed to integrate modified GPL code into the SpECTRE source. There may be an exception if the modified code could still be used separately, but the changes we made to libsharp did not allow that since we replaced its build system with SpECTRE's. This replaces the contents of the external/libsharp directory with the unmodified source, and builds it as an external project. --- docs/Installation/Installation.md | 1 + external/CMakeLists.txt | 102 +++++- external/libsharp/.gitignore | 17 + external/libsharp/CMakeLists.txt | 54 --- external/libsharp/LICENSE.txt | 339 ------------------ external/libsharp/Makefile | 80 +++++ external/libsharp/{README => README.md} | 46 --- external/libsharp/{ => c_utils}/c_utils.c | 0 external/libsharp/{ => c_utils}/c_utils.h | 0 external/libsharp/{ => c_utils}/memusage.c | 0 external/libsharp/{ => c_utils}/memusage.h | 0 external/libsharp/c_utils/planck.make | 18 + external/libsharp/{ => c_utils}/walltime_c.c | 0 external/libsharp/{ => c_utils}/walltime_c.h | 0 external/libsharp/config/config.auto.in | 12 + external/libsharp/config/rules.common | 33 ++ external/libsharp/configure.ac | 110 ++++++ external/libsharp/docsrc/c_utils.dox | 290 +++++++++++++++ external/libsharp/docsrc/footer.html | 5 + external/libsharp/docsrc/index_code.html | 15 + external/libsharp/docsrc/libfftpack.dox | 290 +++++++++++++++ external/libsharp/docsrc/libsharp.dox | 291 +++++++++++++++ external/libsharp/docsrc/planck.make | 20 ++ external/libsharp/fortran/sharp.f90 | 286 +++++++++++++++ external/libsharp/fortran/test_sharp.f90 | 84 +++++ external/libsharp/libfftpack/README | 34 ++ .../libsharp/{ => libfftpack}/bluestein.c | 0 .../libsharp/{ => libfftpack}/bluestein.h | 0 external/libsharp/{ => libfftpack}/fftpack.c | 0 external/libsharp/{ => libfftpack}/fftpack.h | 0 .../libsharp/{ => libfftpack}/fftpack_inc.c | 0 .../libsharp/{ => libfftpack}/libfftpack.dox | 0 external/libsharp/{ => libfftpack}/ls_fft.c | 0 external/libsharp/{ => libfftpack}/ls_fft.h | 0 external/libsharp/libfftpack/planck.make | 21 ++ external/libsharp/{ => libsharp}/libsharp.dox | 0 external/libsharp/libsharp/planck.make | 29 ++ external/libsharp/{ => libsharp}/sharp.c | 17 +- external/libsharp/{ => libsharp}/sharp.h | 0 .../{ => libsharp}/sharp_almhelpers.c | 0 .../{ => libsharp}/sharp_almhelpers.h | 0 .../libsharp/{ => libsharp}/sharp_announce.c | 0 .../libsharp/{ => libsharp}/sharp_announce.h | 0 .../{ => libsharp}/sharp_complex_hacks.h | 0 external/libsharp/{ => libsharp}/sharp_core.c | 0 external/libsharp/{ => libsharp}/sharp_core.h | 0 .../libsharp/{ => libsharp}/sharp_core_inc.c | 0 .../libsharp/{ => libsharp}/sharp_core_inc2.c | 0 .../{ => libsharp}/sharp_core_inchelper.c | 0 external/libsharp/{ => libsharp}/sharp_cxx.h | 0 .../{ => libsharp}/sharp_geomhelpers.c | 0 .../{ => libsharp}/sharp_geomhelpers.h | 0 .../libsharp/{ => libsharp}/sharp_internal.h | 0 .../libsharp/{ => libsharp}/sharp_legendre.c | 0 .../{ => libsharp}/sharp_legendre.c.in | 0 .../libsharp/{ => libsharp}/sharp_legendre.h | 0 .../{ => libsharp}/sharp_legendre_roots.c | 10 +- .../{ => libsharp}/sharp_legendre_roots.h | 0 .../{ => libsharp}/sharp_legendre_table.c | 0 .../{ => libsharp}/sharp_legendre_table.h | 0 .../libsharp/{ => libsharp}/sharp_lowlevel.h | 0 external/libsharp/{ => libsharp}/sharp_mpi.c | 0 external/libsharp/{ => libsharp}/sharp_mpi.h | 0 .../libsharp/{ => libsharp}/sharp_testsuite.c | 0 .../{ => libsharp}/sharp_vecsupport.h | 0 .../libsharp/{ => libsharp}/sharp_vecutil.h | 0 .../libsharp/{ => libsharp}/sharp_ylmgen_c.c | 12 +- .../libsharp/{ => libsharp}/sharp_ylmgen_c.h | 0 .../fake_pyrex/Pyrex/Distutils/__init__.py | 1 + .../fake_pyrex/Pyrex/Distutils/build_ext.py | 1 + .../python/fake_pyrex/Pyrex/__init__.py | 1 + external/libsharp/python/fake_pyrex/README | 2 + external/libsharp/python/libsharp/__init__.py | 1 + .../libsharp/python/libsharp/libsharp.pxd | 92 +++++ .../libsharp/python/libsharp/libsharp.pyx | 324 +++++++++++++++++ .../libsharp/python/libsharp/libsharp_mpi.pyx | 17 + .../python/libsharp/tests/__init__.py | 1 + .../python/libsharp/tests/test_legendre.py | 58 +++ .../libsharp/tests/test_legendre_table.py | 36 ++ .../python/libsharp/tests/test_sht.py | 32 ++ .../tests/test_smoothing_noise_pol_mpi.py | 137 +++++++ external/libsharp/python/setup.py | 83 +++++ external/libsharp/runjinja.py | 19 + 83 files changed, 2554 insertions(+), 467 deletions(-) create mode 100644 external/libsharp/.gitignore delete mode 100644 external/libsharp/CMakeLists.txt delete mode 100644 external/libsharp/LICENSE.txt create mode 100644 external/libsharp/Makefile rename external/libsharp/{README => README.md} (55%) rename external/libsharp/{ => c_utils}/c_utils.c (100%) rename external/libsharp/{ => c_utils}/c_utils.h (100%) rename external/libsharp/{ => c_utils}/memusage.c (100%) rename external/libsharp/{ => c_utils}/memusage.h (100%) create mode 100644 external/libsharp/c_utils/planck.make rename external/libsharp/{ => c_utils}/walltime_c.c (100%) rename external/libsharp/{ => c_utils}/walltime_c.h (100%) create mode 100644 external/libsharp/config/config.auto.in create mode 100644 external/libsharp/config/rules.common create mode 100644 external/libsharp/configure.ac create mode 100644 external/libsharp/docsrc/c_utils.dox create mode 100644 external/libsharp/docsrc/footer.html create mode 100644 external/libsharp/docsrc/index_code.html create mode 100644 external/libsharp/docsrc/libfftpack.dox create mode 100644 external/libsharp/docsrc/libsharp.dox create mode 100644 external/libsharp/docsrc/planck.make create mode 100644 external/libsharp/fortran/sharp.f90 create mode 100644 external/libsharp/fortran/test_sharp.f90 create mode 100644 external/libsharp/libfftpack/README rename external/libsharp/{ => libfftpack}/bluestein.c (100%) rename external/libsharp/{ => libfftpack}/bluestein.h (100%) rename external/libsharp/{ => libfftpack}/fftpack.c (100%) rename external/libsharp/{ => libfftpack}/fftpack.h (100%) rename external/libsharp/{ => libfftpack}/fftpack_inc.c (100%) rename external/libsharp/{ => libfftpack}/libfftpack.dox (100%) rename external/libsharp/{ => libfftpack}/ls_fft.c (100%) rename external/libsharp/{ => libfftpack}/ls_fft.h (100%) create mode 100644 external/libsharp/libfftpack/planck.make rename external/libsharp/{ => libsharp}/libsharp.dox (100%) create mode 100644 external/libsharp/libsharp/planck.make rename external/libsharp/{ => libsharp}/sharp.c (98%) rename external/libsharp/{ => libsharp}/sharp.h (100%) rename external/libsharp/{ => libsharp}/sharp_almhelpers.c (100%) rename external/libsharp/{ => libsharp}/sharp_almhelpers.h (100%) rename external/libsharp/{ => libsharp}/sharp_announce.c (100%) rename external/libsharp/{ => libsharp}/sharp_announce.h (100%) rename external/libsharp/{ => libsharp}/sharp_complex_hacks.h (100%) rename external/libsharp/{ => libsharp}/sharp_core.c (100%) rename external/libsharp/{ => libsharp}/sharp_core.h (100%) rename external/libsharp/{ => libsharp}/sharp_core_inc.c (100%) rename external/libsharp/{ => libsharp}/sharp_core_inc2.c (100%) rename external/libsharp/{ => libsharp}/sharp_core_inchelper.c (100%) rename external/libsharp/{ => libsharp}/sharp_cxx.h (100%) rename external/libsharp/{ => libsharp}/sharp_geomhelpers.c (100%) rename external/libsharp/{ => libsharp}/sharp_geomhelpers.h (100%) rename external/libsharp/{ => libsharp}/sharp_internal.h (100%) rename external/libsharp/{ => libsharp}/sharp_legendre.c (100%) rename external/libsharp/{ => libsharp}/sharp_legendre.c.in (100%) rename external/libsharp/{ => libsharp}/sharp_legendre.h (100%) rename external/libsharp/{ => libsharp}/sharp_legendre_roots.c (87%) rename external/libsharp/{ => libsharp}/sharp_legendre_roots.h (100%) rename external/libsharp/{ => libsharp}/sharp_legendre_table.c (100%) rename external/libsharp/{ => libsharp}/sharp_legendre_table.h (100%) rename external/libsharp/{ => libsharp}/sharp_lowlevel.h (100%) rename external/libsharp/{ => libsharp}/sharp_mpi.c (100%) rename external/libsharp/{ => libsharp}/sharp_mpi.h (100%) rename external/libsharp/{ => libsharp}/sharp_testsuite.c (100%) rename external/libsharp/{ => libsharp}/sharp_vecsupport.h (100%) rename external/libsharp/{ => libsharp}/sharp_vecutil.h (100%) rename external/libsharp/{ => libsharp}/sharp_ylmgen_c.c (94%) rename external/libsharp/{ => libsharp}/sharp_ylmgen_c.h (100%) create mode 100644 external/libsharp/python/fake_pyrex/Pyrex/Distutils/__init__.py create mode 100644 external/libsharp/python/fake_pyrex/Pyrex/Distutils/build_ext.py create mode 100644 external/libsharp/python/fake_pyrex/Pyrex/__init__.py create mode 100644 external/libsharp/python/fake_pyrex/README create mode 100644 external/libsharp/python/libsharp/__init__.py create mode 100644 external/libsharp/python/libsharp/libsharp.pxd create mode 100644 external/libsharp/python/libsharp/libsharp.pyx create mode 100644 external/libsharp/python/libsharp/libsharp_mpi.pyx create mode 100644 external/libsharp/python/libsharp/tests/__init__.py create mode 100644 external/libsharp/python/libsharp/tests/test_legendre.py create mode 100644 external/libsharp/python/libsharp/tests/test_legendre_table.py create mode 100644 external/libsharp/python/libsharp/tests/test_sht.py create mode 100644 external/libsharp/python/libsharp/tests/test_smoothing_noise_pol_mpi.py create mode 100644 external/libsharp/python/setup.py create mode 100755 external/libsharp/runjinja.py diff --git a/docs/Installation/Installation.md b/docs/Installation/Installation.md index e1e2044d4e75..a2a0c8043e48 100644 --- a/docs/Installation/Installation.md +++ b/docs/Installation/Installation.md @@ -191,6 +191,7 @@ apt), or AppleClang 13.0.0 or later * BLAS & LAPACK (e.g. [OpenBLAS](http://www.openblas.net)) * [Boost](http://www.boost.org/) 1.60.0 or later * [GSL](https://www.gnu.org/software/gsl/) \cite Gsl +* [GNU make](https://www.gnu.org/software/make/) * [HDF5](https://support.hdfgroup.org/HDF5/) (non-mpi version on macOS) \cite Hdf5 * [Python](https://www.python.org/) 3.8 or later. diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 61ff10c3087d..5eeb3676104c 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -2,5 +2,105 @@ # See LICENSE.txt for details. add_subdirectory(brigand) -add_subdirectory(libsharp) add_subdirectory(SPHEREPACK) + +set(LIBRARY Libsharp) +set(LIBSHARP_LIBDIR ${CMAKE_CURRENT_BINARY_DIR}/libsharp/auto/lib) +set(LIBSHARP_LIB_libsharp ${LIBSHARP_LIBDIR}/libsharp.a) +set(LIBSHARP_LIB_libfftpack ${LIBSHARP_LIBDIR}/libfftpack.a) +set(LIBSHARP_LIB_libc_utils ${LIBSHARP_LIBDIR}/libc_utils.a) +set(LIBSHARP_INCLUDE ${CMAKE_CURRENT_BINARY_DIR}/libsharp/auto/include) + +find_program(MAKE NAMES gmake make REQUIRED) +set(LIBSHARP_BUILD ${MAKE}) +# When using the Unix Makefile generator, verbosity is inherited from +# the main build and works acceptably well. There's no way to +# dynamically detect the verbosity with ninja, so silence it +# unconditionally because ninja is quieter than make. +if (NOT CMAKE_GENERATOR STREQUAL "Unix Makefiles") + list(APPEND LIBSHARP_BUILD > /dev/null) +endif() + +set(JOB_SERVER "") +if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.28) + set(JOB_SERVER BUILD_JOB_SERVER_AWARE TRUE) +endif() + +include(ExternalProject) +ExternalProject_Add( + Libsharp-external + PREFIX ${CMAKE_BINARY_DIR}/external/libsharp + SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/libsharp + DOWNLOAD_COMMAND + cp -r ${CMAKE_CURRENT_SOURCE_DIR}/libsharp ${CMAKE_CURRENT_BINARY_DIR} + # libsharp has an autoconf build system, but it doesn't do anything + # except set CFLAGS, so we can skip it to avoid depending on + # autoconf and set the flags below by manually writing config.auto. + CONFIGURE_COMMAND "" + # out-of-tree builds don't work + BUILD_IN_SOURCE TRUE + BUILD_COMMAND "${LIBSHARP_BUILD}" + ${JOB_SERVER} + BUILD_BYPRODUCTS + ${LIBSHARP_LIB_libsharp} + ${LIBSHARP_LIB_libfftpack} + ${LIBSHARP_LIB_libc_utils} + INSTALL_COMMAND "" +) + +# Always build libsharp with optimization, since there is a big speed +# difference and we're not interested in debugging it. +file( + GENERATE OUTPUT "libsharp/config/config.auto" + CONTENT + "CC=${CMAKE_C_COMPILER} +CL=\$(CC) +SPECTRE_FLAGS=\\ +\$(subst ;, ,$) +CCFLAGS=\$(SPECTRE_FLAGS) -fno-openmp -O3 -c +CLFLAGS=-L. -L\$(LIBDIR) \$(SPECTRE_FLAGS) -fno-openmp -O3 -lm +ARCREATE=ar cr" + CONDITION "$" +) + +add_library(Libsharp::libsharp STATIC IMPORTED GLOBAL) +set_target_properties( + Libsharp::libsharp + PROPERTIES + IMPORTED_LOCATION + ${LIBSHARP_LIB_libsharp} +) +add_library(Libsharp::libfftpack STATIC IMPORTED GLOBAL) +set_target_properties( + Libsharp::libfftpack + PROPERTIES + IMPORTED_LOCATION + ${LIBSHARP_LIB_libfftpack} +) +add_library(Libsharp::libc_utils STATIC IMPORTED GLOBAL) +set_target_properties( + Libsharp::libc_utils + PROPERTIES + IMPORTED_LOCATION + ${LIBSHARP_LIB_libc_utils} +) +add_library(Libsharp INTERFACE IMPORTED GLOBAL) +target_link_libraries( + ${LIBRARY} + INTERFACE + Libsharp::libsharp + Libsharp::libfftpack + Libsharp::libc_utils +) +# cmake issue #15052 +file(MAKE_DIRECTORY ${LIBSHARP_INCLUDE}) +target_include_directories( + ${LIBRARY} + SYSTEM + INTERFACE + ${LIBSHARP_INCLUDE} +) +add_dependencies( + ${LIBRARY} + Libsharp-external +) diff --git a/external/libsharp/.gitignore b/external/libsharp/.gitignore new file mode 100644 index 000000000000..4cde3defb0d1 --- /dev/null +++ b/external/libsharp/.gitignore @@ -0,0 +1,17 @@ +*.o +*.so +#* +*~ +*.pyc +*.pyo + +/auto +/autom4te.cache +/config.log +/config.status +/config/config.auto +/configure +/sharp_oracle.inc + +/python/libsharp/libsharp.c +/python/libsharp/libsharp_mpi.c diff --git a/external/libsharp/CMakeLists.txt b/external/libsharp/CMakeLists.txt deleted file mode 100644 index 1c82cc55d83c..000000000000 --- a/external/libsharp/CMakeLists.txt +++ /dev/null @@ -1,54 +0,0 @@ -# Distributed under the MIT License. -# See LICENSE.txt for details. - -set(LIBRARY Libsharp) - -set(LIBSHARP_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/external/libsharp/) - -# Note: -# - libsharp is configured a bit oddly compared to spectre. In particular, there -# are *_inc.c files that are included in other c files. These seem to be -# similar in spirit to our .tpp files. -# - We do not compile sharp_testsuite.c since we don't need or want to test it. -# - We do not compile sharp_mpi.c since we don't want MPI usage in libsharp. -# - OpenMP support is explicitly commented out of libsharp since we do our own -# threading in spectre. -# - We always build libsharp with -O3 so that everything runs fast. -set(LIBRARY_SOURCES - bluestein.c - c_utils.c - fftpack.c - ls_fft.c - memusage.c - sharp_almhelpers.c - sharp_announce.c - sharp.c - sharp_core.c - sharp_geomhelpers.c - sharp_legendre.c - sharp_legendre_roots.c - sharp_legendre_table.c - sharp_ylmgen_c.c - walltime_c.c -) - -add_library( - ${LIBRARY} - ${LIBRARY_SOURCES} -) - -target_link_libraries( - ${LIBRARY} - PRIVATE - SpectreFlags -) - -set_property(TARGET ${LIBRARY} - APPEND PROPERTY - COMPILE_OPTIONS - $<$:-O3 -g0> - $<$:-O3 -g0> - $<$:-O3 -g0> -) - -target_include_directories(${LIBRARY} SYSTEM INTERFACE ${LIBSHARP_INCLUDE_DIR}) diff --git a/external/libsharp/LICENSE.txt b/external/libsharp/LICENSE.txt deleted file mode 100644 index d159169d1050..000000000000 --- a/external/libsharp/LICENSE.txt +++ /dev/null @@ -1,339 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - 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 2 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, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. diff --git a/external/libsharp/Makefile b/external/libsharp/Makefile new file mode 100644 index 000000000000..5a3184cbec7b --- /dev/null +++ b/external/libsharp/Makefile @@ -0,0 +1,80 @@ +SHARP_TARGET?=auto +ifndef SHARP_TARGET + SHARP_TARGET:=$(error SHARP_TARGET undefined. Please see README.compilation for help)UNDEFINED +endif + +default: compile_all +SRCROOT:=$(shell pwd) +include $(SRCROOT)/config/config.$(SHARP_TARGET) +include $(SRCROOT)/config/rules.common + +all_hdr:= +all_lib:= +all_cbin:= + +FULL_INCLUDE:= + +include c_utils/planck.make +include libfftpack/planck.make +include libsharp/planck.make +include docsrc/planck.make + +CYTHON_MODULES=python/libsharp/libsharp.so $(if $(MPI_CFLAGS), python/libsharp/libsharp_mpi.so) + +$(all_lib): %: | $(LIBDIR)_mkdir + @echo "# creating library $*" + $(ARCREATE) $@ $^ + +$(all_cbin): %: | $(BINDIR)_mkdir + @echo "# linking C binary $*" + $(CL) -o $@ $^ $(CLFLAGS) + +compile_all: $(all_cbin) hdrcopy + +hdrclean: + @if [ -d $(INCDIR) ]; then rm -rf $(INCDIR)/* ; fi + +hdrcopy: | $(INCDIR)_mkdir + @if [ "$(all_hdr)" ]; then cp -p $(all_hdr) $(INCDIR); fi + +$(notdir $(all_cbin)) : % : $(BINDIR)/% + +test: compile_all + $(BINDIR)/sharp_testsuite acctest && \ + $(BINDIR)/sharp_testsuite test healpix 2048 -1 1024 -1 0 1 && \ + $(BINDIR)/sharp_testsuite test fejer1 2047 -1 -1 4096 2 1 && \ + $(BINDIR)/sharp_testsuite test gauss 2047 -1 -1 4096 0 2 + +perftest: compile_all + $(BINDIR)/sharp_testsuite test healpix 2048 -1 1024 -1 0 1 && \ + $(BINDIR)/sharp_testsuite test gauss 63 -1 -1 128 0 1 && \ + $(BINDIR)/sharp_testsuite test gauss 127 -1 -1 256 0 1 && \ + $(BINDIR)/sharp_testsuite test gauss 255 -1 -1 512 0 1 && \ + $(BINDIR)/sharp_testsuite test gauss 511 -1 -1 1024 0 1 && \ + $(BINDIR)/sharp_testsuite test gauss 1023 -1 -1 2048 0 1 && \ + $(BINDIR)/sharp_testsuite test gauss 2047 -1 -1 4096 0 1 && \ + $(BINDIR)/sharp_testsuite test gauss 4095 -1 -1 8192 0 1 && \ + $(BINDIR)/sharp_testsuite test gauss 8191 -1 -1 16384 0 1 + +%.c: %.c.in +# Only do this if the md5sum changed, in order to avoid Python and Jinja +# dependency when not modifying the c.in file + grep `md5sum $< | cut -d ' ' -f 1` $@ || ./runjinja.py < $< > $@ + +genclean: + rm libsharp/sharp_legendre.c || exit 0 + +$(CYTHON_MODULES): %.so: %.pyx +ifndef PIC_CFLAGS + $(error Python extension must be built using the --enable-pic configure option.) +endif + cython $< + $(CC) $(DEBUG_CFLAGS) $(OPENMP_CFLAGS) $(PIC_CFLAGS) `python-config --cflags` -I$(INCDIR) -o $(<:.pyx=.o) -c $(<:.pyx=.c) + $(CL) -shared $(<:.pyx=.o) $(OPENMP_CFLAGS) $(CYTHON_OBJ) -L$(LIBDIR) -lsharp -lfftpack -lc_utils -L`python-config --prefix`/lib `python-config --ldflags` -o $@ + +python: $(all_lib) hdrcopy $(CYTHON_MODULES) + +# the following test files are automatic; the sht wrapper test +# must be run manually and requires MPI at the moment.. +pytest: python + cd python && nosetests --nocapture libsharp/tests/test_legendre_table.py libsharp/tests/test_legendre.py diff --git a/external/libsharp/README b/external/libsharp/README.md similarity index 55% rename from external/libsharp/README rename to external/libsharp/README.md index 9b4b3e05f634..8fc389389d24 100644 --- a/external/libsharp/README +++ b/external/libsharp/README.md @@ -1,13 +1,3 @@ -# SpECTRE Copy - -Changes: -- Everything is put in one directory for easier compilation. -- pragma omp are commented out in sharp.c and sharp_legendre_roots.c -- Factor m=0 iteration out of loop in `if (spin==0)` of `sharp_Ylmgen_init` - in `sharp_ylmgen_c.c` in order to avoid FPE with Clang. Clang optimizes too - aggressively and always evaluates the `1./gen->root[m]` in the ternary - `(m==0) ? 0. : 1./gen->root[m];`. - # Development has moved This repository has been archived and is only kept so that packages depending on @@ -70,39 +60,3 @@ the compiler to crash during libsharp compilation. This appears to be fixed in the gcc 4.4.7 release. It is possible to work around this problem by adding the compiler flag "-fno-tree-fre" after the other optimization flags - the configure script should do this automatically. - - -ls_fft description: - -This package is intended to calculate one-dimensional real or complex FFTs -with high accuracy and good efficiency even for lengths containing large -prime factors. -The code is written in C, but a Fortran wrapper exists as well. - -Before any FFT is executed, a plan must be generated for it. Plan creation -is designed to be fast, so that there is no significant overhead if the -plan is only used once or a few times. - -The main component of the code is based on Paul N. Swarztrauber's FFTPACK in the -double precision incarnation by Hugh C. Pumphrey -(http://www.netlib.org/fftpack/dp.tgz). - -I replaced the iterative sine and cosine calculations in radfg() and radbg() -by an exact calculation, which slightly improves the transform accuracy for -real FFTs with lengths containing large prime factors. - -Since FFTPACK becomes quite slow for FFT lengths with large prime factors -(in the worst case of prime lengths it reaches O(n*n) complexity), I -implemented Bluestein's algorithm, which computes a FFT of length n by -several FFTs of length n2>=2*n-1 and a convolution. Since n2 can be chosen -to be highly composite, this algorithm is more efficient if n has large -prime factors. The longer FFTs themselves are then computed using the FFTPACK -routines. -Bluestein's algorithm was implemented according to the description at -http://en.wikipedia.org/wiki/Bluestein's_FFT_algorithm. - -Thread-safety: -All routines can be called concurrently; all information needed by ls_fft -is stored in the plan variable. However, using the same plan variable on -multiple threads simultaneously is not supported and will lead to data -corruption. diff --git a/external/libsharp/c_utils.c b/external/libsharp/c_utils/c_utils.c similarity index 100% rename from external/libsharp/c_utils.c rename to external/libsharp/c_utils/c_utils.c diff --git a/external/libsharp/c_utils.h b/external/libsharp/c_utils/c_utils.h similarity index 100% rename from external/libsharp/c_utils.h rename to external/libsharp/c_utils/c_utils.h diff --git a/external/libsharp/memusage.c b/external/libsharp/c_utils/memusage.c similarity index 100% rename from external/libsharp/memusage.c rename to external/libsharp/c_utils/memusage.c diff --git a/external/libsharp/memusage.h b/external/libsharp/c_utils/memusage.h similarity index 100% rename from external/libsharp/memusage.h rename to external/libsharp/c_utils/memusage.h diff --git a/external/libsharp/c_utils/planck.make b/external/libsharp/c_utils/planck.make new file mode 100644 index 000000000000..4f0ccb1d12c8 --- /dev/null +++ b/external/libsharp/c_utils/planck.make @@ -0,0 +1,18 @@ +PKG:=c_utils + +SD:=$(SRCROOT)/$(PKG) +OD:=$(BLDROOT)/$(PKG) + +FULL_INCLUDE+= -I$(SD) + +HDR_$(PKG):=$(SD)/*.h +LIB_$(PKG):=$(LIBDIR)/libc_utils.a + +OBJ:=c_utils.o walltime_c.o memusage.o +OBJ:=$(OBJ:%=$(OD)/%) + +$(OBJ): $(HDR_$(PKG)) | $(OD)_mkdir +$(LIB_$(PKG)): $(OBJ) + +all_hdr+=$(HDR_$(PKG)) +all_lib+=$(LIB_$(PKG)) diff --git a/external/libsharp/walltime_c.c b/external/libsharp/c_utils/walltime_c.c similarity index 100% rename from external/libsharp/walltime_c.c rename to external/libsharp/c_utils/walltime_c.c diff --git a/external/libsharp/walltime_c.h b/external/libsharp/c_utils/walltime_c.h similarity index 100% rename from external/libsharp/walltime_c.h rename to external/libsharp/c_utils/walltime_c.h diff --git a/external/libsharp/config/config.auto.in b/external/libsharp/config/config.auto.in new file mode 100644 index 000000000000..841cec085bc0 --- /dev/null +++ b/external/libsharp/config/config.auto.in @@ -0,0 +1,12 @@ +@SILENT_RULE@ + +CC=@CC@ +CL=@CC@ +CCFLAGS_NO_C=@CCFLAGS_NO_C@ +CCFLAGS=$(CCFLAGS_NO_C) -c +CLFLAGS=-L. -L$(LIBDIR) @LDCCFLAGS@ -lm +DEBUG_CFLAGS=@DEBUG_CFLAGS@ +MPI_CFLAGS=@MPI_CFLAGS@ +OPENMP_CFLAGS=@OPENMP_CFLAGS@ +PIC_CFLAGS=@PIC_CFLAGS@ +ARCREATE=@ARCREATE@ diff --git a/external/libsharp/config/rules.common b/external/libsharp/config/rules.common new file mode 100644 index 000000000000..bac2a2c705e0 --- /dev/null +++ b/external/libsharp/config/rules.common @@ -0,0 +1,33 @@ +BLDROOT = $(SRCROOT)/build.$(SHARP_TARGET) +PREFIX = $(SRCROOT)/$(SHARP_TARGET) +BINDIR = $(PREFIX)/bin +INCDIR = $(PREFIX)/include +LIBDIR = $(PREFIX)/lib +DOCDIR = $(SRCROOT)/doc +PYTHONDIR = $(SRCROOT)/python/libsharp + +# do not use any suffix rules +.SUFFIXES: +# do not use any default rules +.DEFAULT: + +echo_config: + @echo using configuration \'$(SHARP_TARGET)\' + +$(BLDROOT)/%.o : $(SRCROOT)/%.c | echo_config + @echo "# compiling $*.c" + cd $(@D) && $(CC) $(FULL_INCLUDE) -I$(BLDROOT) $(CCFLAGS) $< + +$(BLDROOT)/%.o : $(SRCROOT)/%.cc | echo_config + @echo "# compiling $*.cc" + cd $(@D) && $(CXX) $(FULL_INCLUDE) -I$(BLDROOT) $(CXXCFLAGS) $< + +%_mkdir: + @if [ ! -d $* ]; then mkdir -p $* ; fi + +clean: + rm -rf $(BLDROOT) $(PREFIX) $(DOCDIR) autom4te.cache/ config.log config.status + rm -rf $(PYTHONDIR)/*.c $(PYTHONDIR)/*.o $(PYTHONDIR)/*.so + +distclean: clean + rm -f config/config.auto diff --git a/external/libsharp/configure.ac b/external/libsharp/configure.ac new file mode 100644 index 000000000000..568b62607fbe --- /dev/null +++ b/external/libsharp/configure.ac @@ -0,0 +1,110 @@ +AC_INIT(config/config.auto.in) + +AC_CHECK_PROG([uname_found],[uname],[1],[0]) +if test $uname_found -eq 0 ; then + echo "No uname found; setting system type to unknown." + system="unknown" +else + system=`uname -s`-`uname -r` +fi +AC_LANG([C]) + +AC_TRY_COMPILE([], [@%:@ifndef __INTEL_COMPILER +choke me +@%:@endif], [ICC=[yes]], [ICC=[no]]) + +if test $ICC = yes; then GCC=no; fi +CCTYPE=unknown +if test $GCC = yes; then CCTYPE=gcc; fi +if test $ICC = yes; then CCTYPE=icc; fi +AC_OPENMP + +SILENT_RULE=".SILENT:" +AC_ARG_ENABLE(noisy-make, + [ --enable-noisy-make enable detailed make output], + [if test "$enableval" = yes; then + SILENT_RULE="" + fi]) + +ENABLE_MPI=no +AC_ARG_ENABLE(mpi, + [ --enable-mpi enable generation of MPI-parallel code], + [if test "$enableval" = yes; then + ENABLE_MPI=yes + fi]) + +ENABLE_DEBUG=no +AC_ARG_ENABLE(debug, + [ --enable-debug enable generation of debugging symbols], + [if test "$enableval" = yes; then + ENABLE_DEBUG=yes + fi]) + +ENABLE_PIC=no +AC_ARG_ENABLE(pic, + [ --enable-pic enable generation of position independent code], + [if test "$enableval" = yes; then + ENABLE_PIC=yes + fi]) + +case $CCTYPE in + gcc) + CCFLAGS="-O3 -fno-tree-vectorize -ffast-math -fomit-frame-pointer -std=c99 -pedantic -Wextra -Wall -Wno-unknown-pragmas -Wshadow -Wmissing-prototypes -Wfatal-errors -march=native" + GCCVERSION="`$CC -dumpversion 2>&1`" + echo "Using gcc version $GCCVERSION" + AC_SUBST(GCCVERSION) + changequote(,) + gcc43=`echo $GCCVERSION | grep -c '^4\.[3456789]'` + gcc44=`echo $GCCVERSION | grep -c '^4\.4'` + changequote([,]) + if test $gcc44 -gt 0; then + CCFLAGS="$CCFLAGS -fno-tree-fre" + fi + ;; + icc) + CCFLAGS="-O3 -xHOST -std=c99 -ip -Wbrief -Wall -vec-report0 -openmp-report0 -wd383,981,1419,1572" + ;; + *) + CCFLAGS="-O2" + # Don't do anything now + ;; +esac + +case $system in + Darwin-*) + ARCREATE="libtool -static -o" + ;; + *) + ARCREATE="ar cr" + ;; +esac + +if test $ENABLE_DEBUG = yes; then + DEBUG_CFLAGS="-g" +fi + +if test $ENABLE_PIC = yes; then + PIC_CFLAGS="-fPIC" +fi + +if test $ENABLE_MPI = yes; then + MPI_CFLAGS="-DUSE_MPI" +fi + +CCFLAGS="$CCFLAGS $DEBUG_CFLAGS $OPENMP_CFLAGS $PIC_CFLAGS $MPI_CFLAGS" + +CCFLAGS_NO_C="$CCFLAGS $CPPFLAGS" + +LDCCFLAGS="$LDFLAGS $CCFLAGS" + +AC_SUBST(SILENT_RULE) +AC_SUBST(CC) +AC_SUBST(CCFLAGS_NO_C) +AC_SUBST(LDCCFLAGS) +AC_SUBST(DEBUG_CFLAGS) +AC_SUBST(MPI_CFLAGS) +AC_SUBST(OPENMP_CFLAGS) +AC_SUBST(PIC_CFLAGS) +AC_SUBST(ARCREATE) + +AC_OUTPUT(config/config.auto) diff --git a/external/libsharp/docsrc/c_utils.dox b/external/libsharp/docsrc/c_utils.dox new file mode 100644 index 000000000000..daf432fe8b97 --- /dev/null +++ b/external/libsharp/docsrc/c_utils.dox @@ -0,0 +1,290 @@ +# Doxyfile 1.8.1 + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +DOXYFILE_ENCODING = UTF-8 +PROJECT_NAME = "LevelS C support library" +PROJECT_NUMBER = 0.1 +PROJECT_BRIEF = +PROJECT_LOGO = +OUTPUT_DIRECTORY = . +CREATE_SUBDIRS = NO +OUTPUT_LANGUAGE = English +BRIEF_MEMBER_DESC = NO +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = NO +STRIP_FROM_PATH = +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = NO +QT_AUTOBRIEF = NO +MULTILINE_CPP_IS_BRIEF = NO +INHERIT_DOCS = YES +SEPARATE_MEMBER_PAGES = NO +TAB_SIZE = 8 +ALIASES = +TCL_SUBST = +OPTIMIZE_OUTPUT_FOR_C = YES +OPTIMIZE_OUTPUT_JAVA = NO +OPTIMIZE_FOR_FORTRAN = NO +OPTIMIZE_OUTPUT_VHDL = NO +EXTENSION_MAPPING = +MARKDOWN_SUPPORT = YES +BUILTIN_STL_SUPPORT = NO +CPP_CLI_SUPPORT = NO +SIP_SUPPORT = NO +IDL_PROPERTY_SUPPORT = YES +DISTRIBUTE_GROUP_DOC = NO +SUBGROUPING = YES +INLINE_GROUPED_CLASSES = NO +INLINE_SIMPLE_STRUCTS = NO +TYPEDEF_HIDES_STRUCT = NO +SYMBOL_CACHE_SIZE = 0 +LOOKUP_CACHE_SIZE = 0 +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = NO +EXTRACT_PRIVATE = NO +EXTRACT_PACKAGE = NO +EXTRACT_STATIC = NO +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +EXTRACT_ANON_NSPACES = NO +HIDE_UNDOC_MEMBERS = YES +HIDE_UNDOC_CLASSES = YES +HIDE_FRIEND_COMPOUNDS = YES +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = YES +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +FORCE_LOCAL_INCLUDES = NO +INLINE_INFO = YES +SORT_MEMBER_DOCS = NO +SORT_BRIEF_DOCS = NO +SORT_MEMBERS_CTORS_1ST = NO +SORT_GROUP_NAMES = NO +SORT_BY_SCOPE_NAME = NO +STRICT_PROTO_MATCHING = NO +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +SHOW_FILES = YES +SHOW_NAMESPACES = YES +FILE_VERSION_FILTER = +LAYOUT_FILE = +CITE_BIB_FILES = +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = YES +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_IF_DOC_ERROR = YES +WARN_NO_PARAMDOC = NO +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = ../c_utils +INPUT_ENCODING = UTF-8 +FILE_PATTERNS = *.h \ + *.c \ + *.dox +RECURSIVE = YES +EXCLUDE = +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = +EXCLUDE_SYMBOLS = +EXAMPLE_PATH = +EXAMPLE_PATTERNS = +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = NO +FILTER_SOURCE_PATTERNS = +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = YES +INLINE_SOURCES = NO +STRIP_CODE_COMMENTS = NO +REFERENCED_BY_RELATION = NO +REFERENCES_RELATION = NO +REFERENCES_LINK_SOURCE = YES +USE_HTAGS = NO +VERBATIM_HEADERS = YES +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = YES +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = htmldoc +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = footer.html +HTML_STYLESHEET = +HTML_EXTRA_FILES = +HTML_COLORSTYLE_HUE = 220 +HTML_COLORSTYLE_SAT = 100 +HTML_COLORSTYLE_GAMMA = 80 +HTML_TIMESTAMP = YES +HTML_DYNAMIC_SECTIONS = NO +HTML_INDEX_NUM_ENTRIES = 100 +GENERATE_DOCSET = NO +DOCSET_FEEDNAME = "Doxygen generated docs" +DOCSET_BUNDLE_ID = org.doxygen.Project +DOCSET_PUBLISHER_ID = org.doxygen.Publisher +DOCSET_PUBLISHER_NAME = Publisher +GENERATE_HTMLHELP = NO +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = NO +CHM_INDEX_ENCODING = +BINARY_TOC = NO +TOC_EXPAND = NO +GENERATE_QHP = NO +QCH_FILE = +QHP_NAMESPACE = org.doxygen.Project +QHP_VIRTUAL_FOLDER = doc +QHP_CUST_FILTER_NAME = +QHP_CUST_FILTER_ATTRS = +QHP_SECT_FILTER_ATTRS = +QHG_LOCATION = +GENERATE_ECLIPSEHELP = NO +ECLIPSE_DOC_ID = org.doxygen.Project +DISABLE_INDEX = NO +GENERATE_TREEVIEW = NO +ENUM_VALUES_PER_LINE = 4 +TREEVIEW_WIDTH = 250 +EXT_LINKS_IN_WINDOW = NO +FORMULA_FONTSIZE = 10 +FORMULA_TRANSPARENT = YES +USE_MATHJAX = NO +MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest +MATHJAX_EXTENSIONS = +SEARCHENGINE = NO +SERVER_BASED_SEARCH = NO +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = NO +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = YES +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +LATEX_FOOTER = +PDF_HYPERLINKS = YES +USE_PDFLATEX = YES +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +LATEX_SOURCE_CODE = NO +LATEX_BIB_STYLE = plain +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = NO +MAN_OUTPUT = man +MAN_EXTENSION = .3 +MAN_LINKS = NO +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = NO +XML_OUTPUT = xml +XML_SCHEMA = +XML_DTD = +XML_PROGRAMLISTING = YES +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = NO +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = +PREDEFINED = +EXPAND_AS_DEFINED = +SKIP_FUNCTION_MACROS = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- +TAGFILES = +GENERATE_TAGFILE = c_utils.tag +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = /usr/bin/perl +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = YES +MSCGEN_PATH = +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = NO +DOT_NUM_THREADS = 0 +DOT_FONTNAME = FreeSans +DOT_FONTSIZE = 10 +DOT_FONTPATH = +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +GROUP_GRAPHS = YES +UML_LOOK = NO +UML_LIMIT_NUM_FIELDS = 10 +TEMPLATE_RELATIONS = YES +INCLUDE_GRAPH = NO +INCLUDED_BY_GRAPH = NO +CALL_GRAPH = NO +CALLER_GRAPH = NO +GRAPHICAL_HIERARCHY = NO +DIRECTORY_GRAPH = YES +DOT_IMAGE_FORMAT = png +INTERACTIVE_SVG = NO +DOT_PATH = +DOTFILE_DIRS = +MSCFILE_DIRS = +DOT_GRAPH_MAX_NODES = 50 +MAX_DOT_GRAPH_DEPTH = 0 +DOT_TRANSPARENT = NO +DOT_MULTI_TARGETS = NO +GENERATE_LEGEND = YES +DOT_CLEANUP = YES diff --git a/external/libsharp/docsrc/footer.html b/external/libsharp/docsrc/footer.html new file mode 100644 index 000000000000..6f5dbf01853f --- /dev/null +++ b/external/libsharp/docsrc/footer.html @@ -0,0 +1,5 @@ +
+Generated on $datetime for $projectname +
+ + diff --git a/external/libsharp/docsrc/index_code.html b/external/libsharp/docsrc/index_code.html new file mode 100644 index 000000000000..d8a001d5b3d3 --- /dev/null +++ b/external/libsharp/docsrc/index_code.html @@ -0,0 +1,15 @@ + + +Libsharp source code documentation + +

Libsharp source code documentation

+ +

C interfaces

+ + + + diff --git a/external/libsharp/docsrc/libfftpack.dox b/external/libsharp/docsrc/libfftpack.dox new file mode 100644 index 000000000000..7ff2c23a7b98 --- /dev/null +++ b/external/libsharp/docsrc/libfftpack.dox @@ -0,0 +1,290 @@ +# Doxyfile 1.8.1 + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +DOXYFILE_ENCODING = UTF-8 +PROJECT_NAME = "LevelS FFT library" +PROJECT_NUMBER = 0.1 +PROJECT_BRIEF = +PROJECT_LOGO = +OUTPUT_DIRECTORY = . +CREATE_SUBDIRS = NO +OUTPUT_LANGUAGE = English +BRIEF_MEMBER_DESC = NO +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = NO +STRIP_FROM_PATH = +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = NO +QT_AUTOBRIEF = NO +MULTILINE_CPP_IS_BRIEF = NO +INHERIT_DOCS = YES +SEPARATE_MEMBER_PAGES = NO +TAB_SIZE = 8 +ALIASES = +TCL_SUBST = +OPTIMIZE_OUTPUT_FOR_C = YES +OPTIMIZE_OUTPUT_JAVA = NO +OPTIMIZE_FOR_FORTRAN = NO +OPTIMIZE_OUTPUT_VHDL = NO +EXTENSION_MAPPING = +MARKDOWN_SUPPORT = YES +BUILTIN_STL_SUPPORT = NO +CPP_CLI_SUPPORT = NO +SIP_SUPPORT = NO +IDL_PROPERTY_SUPPORT = YES +DISTRIBUTE_GROUP_DOC = NO +SUBGROUPING = YES +INLINE_GROUPED_CLASSES = NO +INLINE_SIMPLE_STRUCTS = NO +TYPEDEF_HIDES_STRUCT = NO +SYMBOL_CACHE_SIZE = 0 +LOOKUP_CACHE_SIZE = 0 +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = NO +EXTRACT_PRIVATE = NO +EXTRACT_PACKAGE = NO +EXTRACT_STATIC = NO +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +EXTRACT_ANON_NSPACES = NO +HIDE_UNDOC_MEMBERS = YES +HIDE_UNDOC_CLASSES = YES +HIDE_FRIEND_COMPOUNDS = YES +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = YES +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +FORCE_LOCAL_INCLUDES = NO +INLINE_INFO = YES +SORT_MEMBER_DOCS = NO +SORT_BRIEF_DOCS = NO +SORT_MEMBERS_CTORS_1ST = NO +SORT_GROUP_NAMES = NO +SORT_BY_SCOPE_NAME = NO +STRICT_PROTO_MATCHING = NO +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +SHOW_FILES = YES +SHOW_NAMESPACES = YES +FILE_VERSION_FILTER = +LAYOUT_FILE = +CITE_BIB_FILES = +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = YES +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_IF_DOC_ERROR = YES +WARN_NO_PARAMDOC = NO +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = ../libfftpack +INPUT_ENCODING = UTF-8 +FILE_PATTERNS = *.h \ + *.c \ + *.dox +RECURSIVE = YES +EXCLUDE = +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = +EXCLUDE_SYMBOLS = +EXAMPLE_PATH = +EXAMPLE_PATTERNS = +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = NO +FILTER_SOURCE_PATTERNS = +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = YES +INLINE_SOURCES = NO +STRIP_CODE_COMMENTS = NO +REFERENCED_BY_RELATION = NO +REFERENCES_RELATION = NO +REFERENCES_LINK_SOURCE = YES +USE_HTAGS = NO +VERBATIM_HEADERS = YES +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = YES +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = htmldoc +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = footer.html +HTML_STYLESHEET = +HTML_EXTRA_FILES = +HTML_COLORSTYLE_HUE = 220 +HTML_COLORSTYLE_SAT = 100 +HTML_COLORSTYLE_GAMMA = 80 +HTML_TIMESTAMP = YES +HTML_DYNAMIC_SECTIONS = NO +HTML_INDEX_NUM_ENTRIES = 100 +GENERATE_DOCSET = NO +DOCSET_FEEDNAME = "Doxygen generated docs" +DOCSET_BUNDLE_ID = org.doxygen.Project +DOCSET_PUBLISHER_ID = org.doxygen.Publisher +DOCSET_PUBLISHER_NAME = Publisher +GENERATE_HTMLHELP = NO +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = NO +CHM_INDEX_ENCODING = +BINARY_TOC = NO +TOC_EXPAND = NO +GENERATE_QHP = NO +QCH_FILE = +QHP_NAMESPACE = org.doxygen.Project +QHP_VIRTUAL_FOLDER = doc +QHP_CUST_FILTER_NAME = +QHP_CUST_FILTER_ATTRS = +QHP_SECT_FILTER_ATTRS = +QHG_LOCATION = +GENERATE_ECLIPSEHELP = NO +ECLIPSE_DOC_ID = org.doxygen.Project +DISABLE_INDEX = NO +GENERATE_TREEVIEW = NO +ENUM_VALUES_PER_LINE = 4 +TREEVIEW_WIDTH = 250 +EXT_LINKS_IN_WINDOW = NO +FORMULA_FONTSIZE = 10 +FORMULA_TRANSPARENT = YES +USE_MATHJAX = NO +MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest +MATHJAX_EXTENSIONS = +SEARCHENGINE = NO +SERVER_BASED_SEARCH = NO +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = NO +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = YES +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +LATEX_FOOTER = +PDF_HYPERLINKS = YES +USE_PDFLATEX = YES +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +LATEX_SOURCE_CODE = NO +LATEX_BIB_STYLE = plain +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = NO +MAN_OUTPUT = man +MAN_EXTENSION = .3 +MAN_LINKS = NO +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = NO +XML_OUTPUT = xml +XML_SCHEMA = +XML_DTD = +XML_PROGRAMLISTING = YES +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = NO +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = +PREDEFINED = +EXPAND_AS_DEFINED = +SKIP_FUNCTION_MACROS = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- +TAGFILES = c_utils.tag=../c_utils +GENERATE_TAGFILE = libfftpack.tag +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = /usr/bin/perl +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = YES +MSCGEN_PATH = +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = NO +DOT_NUM_THREADS = 0 +DOT_FONTNAME = FreeSans +DOT_FONTSIZE = 10 +DOT_FONTPATH = +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +GROUP_GRAPHS = YES +UML_LOOK = NO +UML_LIMIT_NUM_FIELDS = 10 +TEMPLATE_RELATIONS = YES +INCLUDE_GRAPH = NO +INCLUDED_BY_GRAPH = NO +CALL_GRAPH = NO +CALLER_GRAPH = NO +GRAPHICAL_HIERARCHY = NO +DIRECTORY_GRAPH = YES +DOT_IMAGE_FORMAT = png +INTERACTIVE_SVG = NO +DOT_PATH = +DOTFILE_DIRS = +MSCFILE_DIRS = +DOT_GRAPH_MAX_NODES = 50 +MAX_DOT_GRAPH_DEPTH = 0 +DOT_TRANSPARENT = NO +DOT_MULTI_TARGETS = NO +GENERATE_LEGEND = YES +DOT_CLEANUP = YES diff --git a/external/libsharp/docsrc/libsharp.dox b/external/libsharp/docsrc/libsharp.dox new file mode 100644 index 000000000000..b476ab452ee2 --- /dev/null +++ b/external/libsharp/docsrc/libsharp.dox @@ -0,0 +1,291 @@ +# Doxyfile 1.8.1 + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +DOXYFILE_ENCODING = UTF-8 +PROJECT_NAME = "LevelS SHT library" +PROJECT_NUMBER = 0.1 +PROJECT_BRIEF = +PROJECT_LOGO = +OUTPUT_DIRECTORY = . +CREATE_SUBDIRS = NO +OUTPUT_LANGUAGE = English +BRIEF_MEMBER_DESC = NO +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = NO +STRIP_FROM_PATH = +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = NO +QT_AUTOBRIEF = NO +MULTILINE_CPP_IS_BRIEF = NO +INHERIT_DOCS = YES +SEPARATE_MEMBER_PAGES = NO +TAB_SIZE = 8 +ALIASES = +TCL_SUBST = +OPTIMIZE_OUTPUT_FOR_C = YES +OPTIMIZE_OUTPUT_JAVA = NO +OPTIMIZE_FOR_FORTRAN = NO +OPTIMIZE_OUTPUT_VHDL = NO +EXTENSION_MAPPING = +MARKDOWN_SUPPORT = YES +BUILTIN_STL_SUPPORT = NO +CPP_CLI_SUPPORT = NO +SIP_SUPPORT = NO +IDL_PROPERTY_SUPPORT = YES +DISTRIBUTE_GROUP_DOC = NO +SUBGROUPING = YES +INLINE_GROUPED_CLASSES = NO +INLINE_SIMPLE_STRUCTS = NO +TYPEDEF_HIDES_STRUCT = NO +SYMBOL_CACHE_SIZE = 0 +LOOKUP_CACHE_SIZE = 0 +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = NO +EXTRACT_PRIVATE = NO +EXTRACT_PACKAGE = NO +EXTRACT_STATIC = NO +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +EXTRACT_ANON_NSPACES = NO +HIDE_UNDOC_MEMBERS = YES +HIDE_UNDOC_CLASSES = YES +HIDE_FRIEND_COMPOUNDS = YES +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = YES +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +FORCE_LOCAL_INCLUDES = NO +INLINE_INFO = YES +SORT_MEMBER_DOCS = NO +SORT_BRIEF_DOCS = NO +SORT_MEMBERS_CTORS_1ST = NO +SORT_GROUP_NAMES = NO +SORT_BY_SCOPE_NAME = NO +STRICT_PROTO_MATCHING = NO +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +SHOW_FILES = YES +SHOW_NAMESPACES = YES +FILE_VERSION_FILTER = +LAYOUT_FILE = +CITE_BIB_FILES = +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = YES +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_IF_DOC_ERROR = YES +WARN_NO_PARAMDOC = NO +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = ../libsharp +INPUT_ENCODING = UTF-8 +FILE_PATTERNS = *.h \ + *.c \ + *.dox +RECURSIVE = YES +EXCLUDE = +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = +EXCLUDE_SYMBOLS = +EXAMPLE_PATH = +EXAMPLE_PATTERNS = +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = NO +FILTER_SOURCE_PATTERNS = +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = YES +INLINE_SOURCES = NO +STRIP_CODE_COMMENTS = NO +REFERENCED_BY_RELATION = NO +REFERENCES_RELATION = NO +REFERENCES_LINK_SOURCE = YES +USE_HTAGS = NO +VERBATIM_HEADERS = YES +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = YES +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = htmldoc +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = footer.html +HTML_STYLESHEET = +HTML_EXTRA_FILES = +HTML_COLORSTYLE_HUE = 220 +HTML_COLORSTYLE_SAT = 100 +HTML_COLORSTYLE_GAMMA = 80 +HTML_TIMESTAMP = YES +HTML_DYNAMIC_SECTIONS = NO +HTML_INDEX_NUM_ENTRIES = 100 +GENERATE_DOCSET = NO +DOCSET_FEEDNAME = "Doxygen generated docs" +DOCSET_BUNDLE_ID = org.doxygen.Project +DOCSET_PUBLISHER_ID = org.doxygen.Publisher +DOCSET_PUBLISHER_NAME = Publisher +GENERATE_HTMLHELP = NO +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = NO +CHM_INDEX_ENCODING = +BINARY_TOC = NO +TOC_EXPAND = NO +GENERATE_QHP = NO +QCH_FILE = +QHP_NAMESPACE = org.doxygen.Project +QHP_VIRTUAL_FOLDER = doc +QHP_CUST_FILTER_NAME = +QHP_CUST_FILTER_ATTRS = +QHP_SECT_FILTER_ATTRS = +QHG_LOCATION = +GENERATE_ECLIPSEHELP = NO +ECLIPSE_DOC_ID = org.doxygen.Project +DISABLE_INDEX = NO +GENERATE_TREEVIEW = NO +ENUM_VALUES_PER_LINE = 4 +TREEVIEW_WIDTH = 250 +EXT_LINKS_IN_WINDOW = NO +FORMULA_FONTSIZE = 10 +FORMULA_TRANSPARENT = YES +USE_MATHJAX = NO +MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest +MATHJAX_EXTENSIONS = +SEARCHENGINE = NO +SERVER_BASED_SEARCH = NO +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = NO +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = YES +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +LATEX_FOOTER = +PDF_HYPERLINKS = YES +USE_PDFLATEX = YES +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +LATEX_SOURCE_CODE = NO +LATEX_BIB_STYLE = plain +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = NO +MAN_OUTPUT = man +MAN_EXTENSION = .3 +MAN_LINKS = NO +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = NO +XML_OUTPUT = xml +XML_SCHEMA = +XML_DTD = +XML_PROGRAMLISTING = YES +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = NO +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = +PREDEFINED = +EXPAND_AS_DEFINED = +SKIP_FUNCTION_MACROS = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- +TAGFILES = libfftpack.tag=../libfftpack \ + c_utils.tag=../c_utils +GENERATE_TAGFILE = libsharp.tag +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = /usr/bin/perl +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = YES +MSCGEN_PATH = +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = NO +DOT_NUM_THREADS = 0 +DOT_FONTNAME = FreeSans +DOT_FONTSIZE = 10 +DOT_FONTPATH = +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +GROUP_GRAPHS = YES +UML_LOOK = NO +UML_LIMIT_NUM_FIELDS = 10 +TEMPLATE_RELATIONS = YES +INCLUDE_GRAPH = NO +INCLUDED_BY_GRAPH = NO +CALL_GRAPH = NO +CALLER_GRAPH = NO +GRAPHICAL_HIERARCHY = NO +DIRECTORY_GRAPH = YES +DOT_IMAGE_FORMAT = png +INTERACTIVE_SVG = NO +DOT_PATH = +DOTFILE_DIRS = +MSCFILE_DIRS = +DOT_GRAPH_MAX_NODES = 50 +MAX_DOT_GRAPH_DEPTH = 0 +DOT_TRANSPARENT = NO +DOT_MULTI_TARGETS = NO +GENERATE_LEGEND = YES +DOT_CLEANUP = YES diff --git a/external/libsharp/docsrc/planck.make b/external/libsharp/docsrc/planck.make new file mode 100644 index 000000000000..0d0a4621b9be --- /dev/null +++ b/external/libsharp/docsrc/planck.make @@ -0,0 +1,20 @@ +PKG:=docsrc + +docsrc_idx: $(DOCDIR)_mkdir + cp $(SRCROOT)/docsrc/index_code.html $(DOCDIR)/index.html + +docsrc_code_doc: $(DOCDIR)_mkdir docsrc_idx + cd $(SRCROOT)/docsrc; \ + for i in c_utils libfftpack libsharp; do \ + doxygen $${i}.dox; \ + rm -rf $(DOCDIR)/$${i}; mv htmldoc $(DOCDIR)/$${i}; \ + done; \ + rm *.tag; + +docsrc_clean: + cd $(SRCROOT)/docsrc; \ + rm -f *.tag + cd $(SRCROOT)/docsrc; \ + rm -rf htmldoc + +doc: docsrc_code_doc diff --git a/external/libsharp/fortran/sharp.f90 b/external/libsharp/fortran/sharp.f90 new file mode 100644 index 000000000000..36a1d11c70c2 --- /dev/null +++ b/external/libsharp/fortran/sharp.f90 @@ -0,0 +1,286 @@ +module sharp + use iso_c_binding + implicit none + ! alm_info flags + integer, parameter :: SHARP_PACKED = 1 + + ! sharp job types + enum, bind(c) + enumerator :: SHARP_YtW = 0 + enumerator :: SHARP_Y = 1 + enumerator :: SHARP_Yt = 2 + enumerator :: SHARP_WY = 3 + enumerator :: SHARP_ALM2MAP_DERIV1 = 4 + end enum + + ! sharp job flags + integer, parameter :: SHARP_DP = ISHFT(1, 4) + integer, parameter :: SHARP_ADD = ISHFT(1, 5) + integer, parameter :: SHARP_REAL_HARMONICS = ISHFT(1, 6) + integer, parameter :: SHARP_NO_FFT = ISHFT(1, 7) + + type sharp_geom_info + type(c_ptr) :: handle + integer(c_intptr_t) :: n_local + end type sharp_geom_info + + type sharp_alm_info + type(c_ptr) :: handle + integer(c_intptr_t) :: n_local + end type sharp_alm_info + + interface + + ! alm_info + subroutine sharp_make_general_alm_info( & + lmax, nm, stride, mval, mvstart, flags, alm_info) bind(c) + use iso_c_binding + integer(c_int), value, intent(in) :: lmax, nm, stride, flags + integer(c_int), intent(in) :: mval(nm) + integer(c_intptr_t), intent(in) :: mvstart(nm) + type(c_ptr), intent(out) :: alm_info + end subroutine sharp_make_general_alm_info + + subroutine c_sharp_make_mmajor_real_packed_alm_info( & + lmax, stride, nm, ms, alm_info) bind(c, name='sharp_make_mmajor_real_packed_alm_info') + use iso_c_binding + integer(c_int), value, intent(in) :: lmax, nm, stride + integer(c_int), intent(in), optional :: ms(nm) + type(c_ptr), intent(out) :: alm_info + end subroutine c_sharp_make_mmajor_real_packed_alm_info + + function c_sharp_alm_count(alm_info) bind(c, name='sharp_alm_count') + use iso_c_binding + integer(c_intptr_t) :: c_sharp_alm_count + type(c_ptr), value, intent(in) :: alm_info + end function c_sharp_alm_count + + subroutine c_sharp_destroy_alm_info(alm_info) bind(c, name='sharp_destroy_alm_info') + use iso_c_binding + type(c_ptr), value :: alm_info + end subroutine c_sharp_destroy_alm_info + + ! geom_info + subroutine sharp_make_subset_healpix_geom_info ( & + nside, stride, nrings, rings, weight, geom_info) bind(c) + use iso_c_binding + integer(c_int), value, intent(in) :: nside, stride, nrings + integer(c_int), intent(in), optional :: rings(nrings) + real(c_double), intent(in), optional :: weight(2 * nside) + type(c_ptr), intent(out) :: geom_info + end subroutine sharp_make_subset_healpix_geom_info + + subroutine c_sharp_destroy_geom_info(geom_info) bind(c, name='sharp_destroy_geom_info') + use iso_c_binding + type(c_ptr), value :: geom_info + end subroutine c_sharp_destroy_geom_info + + function c_sharp_map_size(info) bind(c, name='sharp_map_size') + use iso_c_binding + integer(c_intptr_t) :: c_sharp_map_size + type(c_ptr), value :: info + end function c_sharp_map_size + + + ! execute + subroutine c_sharp_execute(type, spin, alm, map, geom_info, alm_info, ntrans, & + flags, time, opcnt) bind(c, name='sharp_execute') + use iso_c_binding + integer(c_int), value :: type, spin, ntrans, flags + type(c_ptr), value :: alm_info, geom_info + real(c_double), intent(out), optional :: time + integer(c_long_long), intent(out), optional :: opcnt + type(c_ptr), intent(in) :: alm(*), map(*) + end subroutine c_sharp_execute + + subroutine c_sharp_execute_mpi(comm, type, spin, alm, map, geom_info, alm_info, ntrans, & + flags, time, opcnt) bind(c, name='sharp_execute_mpi_fortran') + use iso_c_binding + integer(c_int), value :: comm, type, spin, ntrans, flags + type(c_ptr), value :: alm_info, geom_info + real(c_double), intent(out), optional :: time + integer(c_long_long), intent(out), optional :: opcnt + type(c_ptr), intent(in) :: alm(*), map(*) + end subroutine c_sharp_execute_mpi + + ! Legendre transforms + subroutine c_sharp_legendre_transform(bl, recfac, lmax, x, out, nx) & + bind(c, name='sharp_legendre_transform') + use iso_c_binding + integer(c_intptr_t), value :: lmax, nx + real(c_double) :: bl(lmax + 1), x(nx), out(nx) + real(c_double), optional :: recfac(lmax + 1) + end subroutine c_sharp_legendre_transform + + subroutine c_sharp_legendre_transform_s(bl, recfac, lmax, x, out, nx) & + bind(c, name='sharp_legendre_transform_s') + use iso_c_binding + integer(c_intptr_t), value :: lmax, nx + real(c_float) :: bl(lmax + 1), x(nx), out(nx) + real(c_float), optional :: recfac(lmax + 1) + end subroutine c_sharp_legendre_transform_s + end interface + + interface sharp_execute + module procedure sharp_execute_d + end interface + + interface sharp_legendre_transform + module procedure sharp_legendre_transform_d, sharp_legendre_transform_s + end interface sharp_legendre_transform + +contains + ! alm info + + ! if ms is not passed, we default to using m=0..lmax. + subroutine sharp_make_mmajor_real_packed_alm_info(lmax, ms, alm_info) + use iso_c_binding + integer(c_int), value, intent(in) :: lmax + integer(c_int), intent(in), optional :: ms(:) + type(sharp_alm_info), intent(out) :: alm_info + !-- + integer(c_int), allocatable :: ms_copy(:) + integer(c_int) :: nm + + if (present(ms)) then + nm = size(ms) + allocate(ms_copy(nm)) + ms_copy = ms + call c_sharp_make_mmajor_real_packed_alm_info(lmax, 1, nm, ms_copy, alm_info=alm_info%handle) + deallocate(ms_copy) + else + call c_sharp_make_mmajor_real_packed_alm_info(lmax, 1, lmax + 1, alm_info=alm_info%handle) + end if + alm_info%n_local = c_sharp_alm_count(alm_info%handle) + end subroutine sharp_make_mmajor_real_packed_alm_info + + subroutine sharp_destroy_alm_info(alm_info) + use iso_c_binding + type(sharp_alm_info), intent(inout) :: alm_info + call c_sharp_destroy_alm_info(alm_info%handle) + alm_info%handle = c_null_ptr + end subroutine sharp_destroy_alm_info + + + ! geom info + subroutine sharp_make_healpix_geom_info(nside, rings, weight, geom_info) + integer(c_int), value :: nside + integer(c_int), optional :: rings(:) + real(c_double), intent(in), optional :: weight(2 * nside) + type(sharp_geom_info), intent(out) :: geom_info + !-- + integer(c_int) :: nrings + integer(c_int), allocatable :: rings_copy(:) + + if (present(rings)) then + nrings = size(rings) + allocate(rings_copy(nrings)) + rings_copy = rings + call sharp_make_subset_healpix_geom_info(nside, 1, nrings, rings_copy, & + weight, geom_info%handle) + deallocate(rings_copy) + else + call sharp_make_subset_healpix_geom_info(nside, 1, nrings=4 * nside - 1, & + weight=weight, geom_info=geom_info%handle) + end if + geom_info%n_local = c_sharp_map_size(geom_info%handle) + end subroutine sharp_make_healpix_geom_info + + subroutine sharp_destroy_geom_info(geom_info) + use iso_c_binding + type(sharp_geom_info), intent(inout) :: geom_info + call c_sharp_destroy_geom_info(geom_info%handle) + geom_info%handle = c_null_ptr + end subroutine sharp_destroy_geom_info + + + ! Currently the only mode supported is stacked (not interleaved) maps. + ! + ! Note that passing the exact dimension of alm/map is necesarry, it + ! prevents the caller from doing too crazy slicing prior to pass array + ! in... + ! + ! Usage: + ! + ! The alm array must have shape exactly alm(alm_info%n_local, nmaps) + ! The maps array must have shape exactly map(map_info%n_local, nmaps). + subroutine sharp_execute_d(type, spin, nmaps, alm, alm_info, map, geom_info, & + add, time, opcnt, comm) + use iso_c_binding + use mpi + implicit none + integer(c_int), value :: type, spin, nmaps + integer(c_int), optional :: comm + logical, value, optional :: add ! should add instead of replace out + + type(sharp_alm_info) :: alm_info + type(sharp_geom_info) :: geom_info + real(c_double), intent(out), optional :: time + integer(c_long_long), intent(out), optional :: opcnt + real(c_double), target, intent(inout) :: alm(0:alm_info%n_local - 1, 1:nmaps) + real(c_double), target, intent(inout) :: map(0:geom_info%n_local - 1, 1:nmaps) + !-- + integer(c_int) :: mod_flags, ntrans, k + type(c_ptr), target :: alm_ptr(nmaps) + type(c_ptr), target :: map_ptr(nmaps) + + mod_flags = SHARP_DP + if (present(add) .and. add) then + mod_flags = or(mod_flags, SHARP_ADD) + end if + + if (spin == 0) then + ntrans = nmaps + else + ntrans = nmaps / 2 + end if + + ! Set up pointer table to access maps + alm_ptr(:) = c_null_ptr + map_ptr(:) = c_null_ptr + do k = 1, nmaps + if (alm_info%n_local > 0) alm_ptr(k) = c_loc(alm(0, k)) + if (geom_info%n_local > 0) map_ptr(k) = c_loc(map(0, k)) + end do + + if (present(comm)) then + call c_sharp_execute_mpi(comm, type, spin, alm_ptr, map_ptr, & + geom_info=geom_info%handle, & + alm_info=alm_info%handle, & + ntrans=ntrans, & + flags=mod_flags, & + time=time, & + opcnt=opcnt) + else + call c_sharp_execute(type, spin, alm_ptr, map_ptr, & + geom_info=geom_info%handle, & + alm_info=alm_info%handle, & + ntrans=ntrans, & + flags=mod_flags, & + time=time, & + opcnt=opcnt) + end if + end subroutine sharp_execute_d + + subroutine sharp_legendre_transform_d(bl, x, out) + use iso_c_binding + real(c_double) :: bl(:) + real(c_double) :: x(:), out(size(x)) + !-- + integer(c_intptr_t) :: lmax, nx + call c_sharp_legendre_transform(bl, lmax=int(size(bl) - 1, c_intptr_t), & + x=x, out=out, nx=int(size(x), c_intptr_t)) + end subroutine sharp_legendre_transform_d + + subroutine sharp_legendre_transform_s(bl, x, out) + use iso_c_binding + real(c_float) :: bl(:) + real(c_float) :: x(:), out(size(x)) + !-- + integer(c_intptr_t) :: lmax, nx + call c_sharp_legendre_transform_s(bl, lmax=int(size(bl) - 1, c_intptr_t), & + x=x, out=out, nx=int(size(x), c_intptr_t)) + end subroutine sharp_legendre_transform_s + + +end module diff --git a/external/libsharp/fortran/test_sharp.f90 b/external/libsharp/fortran/test_sharp.f90 new file mode 100644 index 000000000000..0b7cce20fbaf --- /dev/null +++ b/external/libsharp/fortran/test_sharp.f90 @@ -0,0 +1,84 @@ +program test_sharp + use mpi + use sharp + use iso_c_binding, only : c_ptr, c_double + implicit none + + integer, parameter :: lmax = 2, nside = 2 + type(sharp_alm_info) :: alm_info + type(sharp_geom_info) :: geom_info + + real(c_double), dimension(0:(lmax + 1)**2 - 1, 1:1) :: alm + real(c_double), dimension(0:12*nside**2 - 1, 1:1) :: map + + integer(c_int), dimension(1:lmax + 1) :: ms + integer(c_int), dimension(1:4 * nside - 1) :: rings + integer(c_int) :: nm, m, nrings, iring + integer :: nodecount, rank, ierr + + call MPI_Init(ierr) + call MPI_Comm_size(MPI_COMM_WORLD, nodecount, ierr) + call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierr) + + nm = 0 + do m = rank, lmax, nodecount + nm = nm + 1 + ms(nm) = m + end do + + nrings = 0 + do iring = rank + 1, 4 * nside - 1, nodecount + nrings = nrings + 1 + rings(nrings) = iring + end do + + alm = 0 + map = 0 + if (rank == 0) then + alm(0, 1) = 1 + end if + + print *, ms(1:nm) + call sharp_make_mmajor_real_packed_alm_info(lmax, ms=ms(1:nm), alm_info=alm_info) + print *, 'alm_info%n_local', alm_info%n_local + call sharp_make_healpix_geom_info(nside, rings=rings(1:nrings), geom_info=geom_info) + print *, 'geom_info%n_local', geom_info%n_local + print *, 'execute' + call sharp_execute(SHARP_Y, 0, 1, alm, alm_info, map, geom_info, comm=MPI_COMM_WORLD) + + print *, alm + print *, map + + call sharp_destroy_alm_info(alm_info) + call sharp_destroy_geom_info(geom_info) + print *, 'DONE' + call MPI_Finalize(ierr) + + print *, 'LEGENDRE TRANSFORMS' + + call test_legendre_transforms() + +contains + subroutine test_legendre_transforms() + integer, parameter :: lmax = 20, nx=10 + real(c_double) :: bl(0:lmax) + real(c_double) :: x(nx), out(nx) + real(c_float) :: out_s(nx) + !-- + integer :: l, i + + do l = 0, lmax + bl(l) = 1.0 / real(l + 1, c_double) + end do + do i = 1, nx + x(i) = 1 / real(i, c_double) + end do + out = 0 + call sharp_legendre_transform(bl, x, out) + print *, out + call sharp_legendre_transform(real(bl, c_float), real(x, c_float), out_s) + print *, out_s + end subroutine test_legendre_transforms + + +end program test_sharp diff --git a/external/libsharp/libfftpack/README b/external/libsharp/libfftpack/README new file mode 100644 index 000000000000..2c7e7cb42454 --- /dev/null +++ b/external/libsharp/libfftpack/README @@ -0,0 +1,34 @@ +ls_fft description: + +This package is intended to calculate one-dimensional real or complex FFTs +with high accuracy and good efficiency even for lengths containing large +prime factors. +The code is written in C, but a Fortran wrapper exists as well. + +Before any FFT is executed, a plan must be generated for it. Plan creation +is designed to be fast, so that there is no significant overhead if the +plan is only used once or a few times. + +The main component of the code is based on Paul N. Swarztrauber's FFTPACK in the +double precision incarnation by Hugh C. Pumphrey +(http://www.netlib.org/fftpack/dp.tgz). + +I replaced the iterative sine and cosine calculations in radfg() and radbg() +by an exact calculation, which slightly improves the transform accuracy for +real FFTs with lengths containing large prime factors. + +Since FFTPACK becomes quite slow for FFT lengths with large prime factors +(in the worst case of prime lengths it reaches O(n*n) complexity), I +implemented Bluestein's algorithm, which computes a FFT of length n by +several FFTs of length n2>=2*n-1 and a convolution. Since n2 can be chosen +to be highly composite, this algorithm is more efficient if n has large +prime factors. The longer FFTs themselves are then computed using the FFTPACK +routines. +Bluestein's algorithm was implemented according to the description at +http://en.wikipedia.org/wiki/Bluestein's_FFT_algorithm. + +Thread-safety: +All routines can be called concurrently; all information needed by ls_fft +is stored in the plan variable. However, using the same plan variable on +multiple threads simultaneously is not supported and will lead to data +corruption. diff --git a/external/libsharp/bluestein.c b/external/libsharp/libfftpack/bluestein.c similarity index 100% rename from external/libsharp/bluestein.c rename to external/libsharp/libfftpack/bluestein.c diff --git a/external/libsharp/bluestein.h b/external/libsharp/libfftpack/bluestein.h similarity index 100% rename from external/libsharp/bluestein.h rename to external/libsharp/libfftpack/bluestein.h diff --git a/external/libsharp/fftpack.c b/external/libsharp/libfftpack/fftpack.c similarity index 100% rename from external/libsharp/fftpack.c rename to external/libsharp/libfftpack/fftpack.c diff --git a/external/libsharp/fftpack.h b/external/libsharp/libfftpack/fftpack.h similarity index 100% rename from external/libsharp/fftpack.h rename to external/libsharp/libfftpack/fftpack.h diff --git a/external/libsharp/fftpack_inc.c b/external/libsharp/libfftpack/fftpack_inc.c similarity index 100% rename from external/libsharp/fftpack_inc.c rename to external/libsharp/libfftpack/fftpack_inc.c diff --git a/external/libsharp/libfftpack.dox b/external/libsharp/libfftpack/libfftpack.dox similarity index 100% rename from external/libsharp/libfftpack.dox rename to external/libsharp/libfftpack/libfftpack.dox diff --git a/external/libsharp/ls_fft.c b/external/libsharp/libfftpack/ls_fft.c similarity index 100% rename from external/libsharp/ls_fft.c rename to external/libsharp/libfftpack/ls_fft.c diff --git a/external/libsharp/ls_fft.h b/external/libsharp/libfftpack/ls_fft.h similarity index 100% rename from external/libsharp/ls_fft.h rename to external/libsharp/libfftpack/ls_fft.h diff --git a/external/libsharp/libfftpack/planck.make b/external/libsharp/libfftpack/planck.make new file mode 100644 index 000000000000..c1713671cf75 --- /dev/null +++ b/external/libsharp/libfftpack/planck.make @@ -0,0 +1,21 @@ +PKG:=libfftpack + +SD:=$(SRCROOT)/$(PKG) +OD:=$(BLDROOT)/$(PKG) + +FULL_INCLUDE+= -I$(SD) + +HDR_$(PKG):=$(SD)/*.h +LIB_$(PKG):=$(LIBDIR)/libfftpack.a +OBJ:=fftpack.o bluestein.o ls_fft.o +OBJ:=$(OBJ:%=$(OD)/%) + +ODEP:=$(HDR_$(PKG)) $(HDR_c_utils) + +$(OD)/fftpack.o: $(SD)/fftpack_inc.c + +$(OBJ): $(ODEP) | $(OD)_mkdir +$(LIB_$(PKG)): $(OBJ) + +all_hdr+=$(HDR_$(PKG)) +all_lib+=$(LIB_$(PKG)) diff --git a/external/libsharp/libsharp.dox b/external/libsharp/libsharp/libsharp.dox similarity index 100% rename from external/libsharp/libsharp.dox rename to external/libsharp/libsharp/libsharp.dox diff --git a/external/libsharp/libsharp/planck.make b/external/libsharp/libsharp/planck.make new file mode 100644 index 000000000000..76d534f68000 --- /dev/null +++ b/external/libsharp/libsharp/planck.make @@ -0,0 +1,29 @@ +PKG:=libsharp + +SD:=$(SRCROOT)/$(PKG) +OD:=$(BLDROOT)/$(PKG) + +FULL_INCLUDE+= -I$(SD) + +HDR_$(PKG):=$(SD)/*.h +LIB_$(PKG):=$(LIBDIR)/libsharp.a +BIN:=sharp_testsuite +LIBOBJ:=sharp_ylmgen_c.o sharp.o sharp_announce.o sharp_geomhelpers.o sharp_almhelpers.o sharp_core.o sharp_legendre.o sharp_legendre_roots.o sharp_legendre_table.o +ALLOBJ:=$(LIBOBJ) sharp_testsuite.o +LIBOBJ:=$(LIBOBJ:%=$(OD)/%) +ALLOBJ:=$(ALLOBJ:%=$(OD)/%) + +ODEP:=$(HDR_$(PKG)) $(HDR_libfftpack) $(HDR_c_utils) +$(OD)/sharp_core.o: $(SD)/sharp_core_inchelper.c $(SD)/sharp_core_inc.c $(SD)/sharp_core_inc2.c +$(OD)/sharp.o: $(SD)/sharp_mpi.c +BDEP:=$(LIB_$(PKG)) $(LIB_libfftpack) $(LIB_c_utils) + +$(LIB_$(PKG)): $(LIBOBJ) + +$(ALLOBJ): $(ODEP) | $(OD)_mkdir +BIN:=$(BIN:%=$(BINDIR)/%) +$(BIN): $(BINDIR)/% : $(OD)/%.o $(BDEP) + +all_hdr+=$(HDR_$(PKG)) +all_lib+=$(LIB_$(PKG)) +all_cbin+=$(BIN) diff --git a/external/libsharp/sharp.c b/external/libsharp/libsharp/sharp.c similarity index 98% rename from external/libsharp/sharp.c rename to external/libsharp/libsharp/sharp.c index 931eedffed54..1eb88577158b 100644 --- a/external/libsharp/sharp.c +++ b/external/libsharp/libsharp/sharp.c @@ -27,9 +27,6 @@ * * Copyright (C) 2006-2013 Max-Planck-Society * \author Martin Reinecke \author Dag Sverre Seljebotn - * - * Changes by SXS Collaboration: - * 1. #pragma omp lines are commented out. */ #include @@ -713,13 +710,13 @@ static void map2phase (sharp_job *job, int mmax, int llim, int ulim) } else { -/* #pragma omp parallel if ((job->flags&SHARP_NO_OPENMP)==0) */ +#pragma omp parallel if ((job->flags&SHARP_NO_OPENMP)==0) { ringhelper helper; ringhelper_init(&helper); int rstride=job->ginfo->nphmax+2; double *ringtmp=RALLOC(double,job->ntrans*job->nmaps*rstride); -/* #pragma omp for schedule(dynamic,1) */ +#pragma omp for schedule(dynamic,1) for (int ith=llim; iths_th*(ith-llim); @@ -758,13 +755,13 @@ static void phase2map (sharp_job *job, int mmax, int llim, int ulim) } else { -/* #pragma omp parallel if ((job->flags&SHARP_NO_OPENMP)==0) */ +#pragma omp parallel if ((job->flags&SHARP_NO_OPENMP)==0) { ringhelper helper; ringhelper_init(&helper); int rstride=job->ginfo->nphmax+2; double *ringtmp=RALLOC(double,job->ntrans*job->nmaps*rstride); -/* #pragma omp for schedule(dynamic,1) */ +#pragma omp for schedule(dynamic,1) for (int ith=llim; iths_th*(ith-llim); @@ -823,7 +820,7 @@ static void sharp_execute_job (sharp_job *job) /* map->phase where necessary */ map2phase (job, mmax, llim, ulim); -/* #pragma omp parallel if ((job->flags&SHARP_NO_OPENMP)==0) */ +#pragma omp parallel if ((job->flags&SHARP_NO_OPENMP)==0) { sharp_job ljob = *job; ljob.opcnt=0; @@ -831,7 +828,7 @@ static void sharp_execute_job (sharp_job *job) sharp_Ylmgen_init (&generator,lmax,mmax,ljob.spin); alloc_almtmp(&ljob,lmax); -/* #pragma omp for schedule(dynamic,1) */ +#pragma omp for schedule(dynamic,1) for (int mi=0; miainfo->nm; ++mi) { /* alm->alm_tmp where necessary */ @@ -846,7 +843,7 @@ static void sharp_execute_job (sharp_job *job) sharp_Ylmgen_destroy(&generator); dealloc_almtmp(&ljob); -/* #pragma omp critical */ +#pragma omp critical job->opcnt+=ljob.opcnt; } /* end of parallel region */ diff --git a/external/libsharp/sharp.h b/external/libsharp/libsharp/sharp.h similarity index 100% rename from external/libsharp/sharp.h rename to external/libsharp/libsharp/sharp.h diff --git a/external/libsharp/sharp_almhelpers.c b/external/libsharp/libsharp/sharp_almhelpers.c similarity index 100% rename from external/libsharp/sharp_almhelpers.c rename to external/libsharp/libsharp/sharp_almhelpers.c diff --git a/external/libsharp/sharp_almhelpers.h b/external/libsharp/libsharp/sharp_almhelpers.h similarity index 100% rename from external/libsharp/sharp_almhelpers.h rename to external/libsharp/libsharp/sharp_almhelpers.h diff --git a/external/libsharp/sharp_announce.c b/external/libsharp/libsharp/sharp_announce.c similarity index 100% rename from external/libsharp/sharp_announce.c rename to external/libsharp/libsharp/sharp_announce.c diff --git a/external/libsharp/sharp_announce.h b/external/libsharp/libsharp/sharp_announce.h similarity index 100% rename from external/libsharp/sharp_announce.h rename to external/libsharp/libsharp/sharp_announce.h diff --git a/external/libsharp/sharp_complex_hacks.h b/external/libsharp/libsharp/sharp_complex_hacks.h similarity index 100% rename from external/libsharp/sharp_complex_hacks.h rename to external/libsharp/libsharp/sharp_complex_hacks.h diff --git a/external/libsharp/sharp_core.c b/external/libsharp/libsharp/sharp_core.c similarity index 100% rename from external/libsharp/sharp_core.c rename to external/libsharp/libsharp/sharp_core.c diff --git a/external/libsharp/sharp_core.h b/external/libsharp/libsharp/sharp_core.h similarity index 100% rename from external/libsharp/sharp_core.h rename to external/libsharp/libsharp/sharp_core.h diff --git a/external/libsharp/sharp_core_inc.c b/external/libsharp/libsharp/sharp_core_inc.c similarity index 100% rename from external/libsharp/sharp_core_inc.c rename to external/libsharp/libsharp/sharp_core_inc.c diff --git a/external/libsharp/sharp_core_inc2.c b/external/libsharp/libsharp/sharp_core_inc2.c similarity index 100% rename from external/libsharp/sharp_core_inc2.c rename to external/libsharp/libsharp/sharp_core_inc2.c diff --git a/external/libsharp/sharp_core_inchelper.c b/external/libsharp/libsharp/sharp_core_inchelper.c similarity index 100% rename from external/libsharp/sharp_core_inchelper.c rename to external/libsharp/libsharp/sharp_core_inchelper.c diff --git a/external/libsharp/sharp_cxx.h b/external/libsharp/libsharp/sharp_cxx.h similarity index 100% rename from external/libsharp/sharp_cxx.h rename to external/libsharp/libsharp/sharp_cxx.h diff --git a/external/libsharp/sharp_geomhelpers.c b/external/libsharp/libsharp/sharp_geomhelpers.c similarity index 100% rename from external/libsharp/sharp_geomhelpers.c rename to external/libsharp/libsharp/sharp_geomhelpers.c diff --git a/external/libsharp/sharp_geomhelpers.h b/external/libsharp/libsharp/sharp_geomhelpers.h similarity index 100% rename from external/libsharp/sharp_geomhelpers.h rename to external/libsharp/libsharp/sharp_geomhelpers.h diff --git a/external/libsharp/sharp_internal.h b/external/libsharp/libsharp/sharp_internal.h similarity index 100% rename from external/libsharp/sharp_internal.h rename to external/libsharp/libsharp/sharp_internal.h diff --git a/external/libsharp/sharp_legendre.c b/external/libsharp/libsharp/sharp_legendre.c similarity index 100% rename from external/libsharp/sharp_legendre.c rename to external/libsharp/libsharp/sharp_legendre.c diff --git a/external/libsharp/sharp_legendre.c.in b/external/libsharp/libsharp/sharp_legendre.c.in similarity index 100% rename from external/libsharp/sharp_legendre.c.in rename to external/libsharp/libsharp/sharp_legendre.c.in diff --git a/external/libsharp/sharp_legendre.h b/external/libsharp/libsharp/sharp_legendre.h similarity index 100% rename from external/libsharp/sharp_legendre.h rename to external/libsharp/libsharp/sharp_legendre.h diff --git a/external/libsharp/sharp_legendre_roots.c b/external/libsharp/libsharp/sharp_legendre_roots.c similarity index 87% rename from external/libsharp/sharp_legendre_roots.c rename to external/libsharp/libsharp/sharp_legendre_roots.c index 6495529a895b..44d850764931 100644 --- a/external/libsharp/sharp_legendre_roots.c +++ b/external/libsharp/libsharp/sharp_legendre_roots.c @@ -4,11 +4,7 @@ Adjustments by M. Reinecke - adjusted interface (keep epsilon internal, return full number of points) - removed precomputed tables - - tweaked Newton iteration to obtain higher accuracy - - Changes by SXS Collaboration: - 1. #pragma omp lines are commented out. - */ + - tweaked Newton iteration to obtain higher accuracy */ #include #include "sharp_legendre_roots.h" @@ -26,10 +22,10 @@ void sharp_legendre_roots(int n, double *x, double *w) double t0 = 1 - (1-1./n) / (8.*n*n); double t1 = 1./(4.*n+2.); -/* #pragma omp parallel */ +#pragma omp parallel { int i; -/* #pragma omp for schedule(dynamic,100) */ +#pragma omp for schedule(dynamic,100) for (i=1; i<=m; ++i) { double x0 = cos(pi * ((i<<2)-1) * t1) * t0; diff --git a/external/libsharp/sharp_legendre_roots.h b/external/libsharp/libsharp/sharp_legendre_roots.h similarity index 100% rename from external/libsharp/sharp_legendre_roots.h rename to external/libsharp/libsharp/sharp_legendre_roots.h diff --git a/external/libsharp/sharp_legendre_table.c b/external/libsharp/libsharp/sharp_legendre_table.c similarity index 100% rename from external/libsharp/sharp_legendre_table.c rename to external/libsharp/libsharp/sharp_legendre_table.c diff --git a/external/libsharp/sharp_legendre_table.h b/external/libsharp/libsharp/sharp_legendre_table.h similarity index 100% rename from external/libsharp/sharp_legendre_table.h rename to external/libsharp/libsharp/sharp_legendre_table.h diff --git a/external/libsharp/sharp_lowlevel.h b/external/libsharp/libsharp/sharp_lowlevel.h similarity index 100% rename from external/libsharp/sharp_lowlevel.h rename to external/libsharp/libsharp/sharp_lowlevel.h diff --git a/external/libsharp/sharp_mpi.c b/external/libsharp/libsharp/sharp_mpi.c similarity index 100% rename from external/libsharp/sharp_mpi.c rename to external/libsharp/libsharp/sharp_mpi.c diff --git a/external/libsharp/sharp_mpi.h b/external/libsharp/libsharp/sharp_mpi.h similarity index 100% rename from external/libsharp/sharp_mpi.h rename to external/libsharp/libsharp/sharp_mpi.h diff --git a/external/libsharp/sharp_testsuite.c b/external/libsharp/libsharp/sharp_testsuite.c similarity index 100% rename from external/libsharp/sharp_testsuite.c rename to external/libsharp/libsharp/sharp_testsuite.c diff --git a/external/libsharp/sharp_vecsupport.h b/external/libsharp/libsharp/sharp_vecsupport.h similarity index 100% rename from external/libsharp/sharp_vecsupport.h rename to external/libsharp/libsharp/sharp_vecsupport.h diff --git a/external/libsharp/sharp_vecutil.h b/external/libsharp/libsharp/sharp_vecutil.h similarity index 100% rename from external/libsharp/sharp_vecutil.h rename to external/libsharp/libsharp/sharp_vecutil.h diff --git a/external/libsharp/sharp_ylmgen_c.c b/external/libsharp/libsharp/sharp_ylmgen_c.c similarity index 94% rename from external/libsharp/sharp_ylmgen_c.c rename to external/libsharp/libsharp/sharp_ylmgen_c.c index b102b724e01a..6e8cee58b3d3 100644 --- a/external/libsharp/sharp_ylmgen_c.c +++ b/external/libsharp/libsharp/sharp_ylmgen_c.c @@ -27,12 +27,6 @@ * * Copyright (C) 2005-2014 Max-Planck-Society * Author: Martin Reinecke - * - * Changes by SXS Collaboration: - * 1. Factor m=0 iteration out of loop in `if (spin==0)` of `sharp_Ylmgen_init` - * in order to avoid FPE with Clang. Clang optimizes too aggressively and - * always evaluates the `1./gen->root[m]` in the ternary - * `(m==0) ? 0. : 1./gen->root[m];`. */ #include @@ -76,12 +70,10 @@ void sharp_Ylmgen_init (sharp_Ylmgen_C *gen, int l_max, int m_max, int spin) gen->mfac[m] = gen->mfac[m-1]*sqrt((2*m+1.)/(2*m)); gen->root = RALLOC(double,2*gen->lmax+5); gen->iroot = RALLOC(double,2*gen->lmax+5); - gen->root[0] = 0.; - gen->iroot[0] = 0.; - for (int m=1; m<2*gen->lmax+5; ++m) + for (int m=0; m<2*gen->lmax+5; ++m) { gen->root[m] = sqrt(m); - gen->iroot[m] = 1./gen->root[m]; + gen->iroot[m] = (m==0) ? 0. : 1./gen->root[m]; } } else diff --git a/external/libsharp/sharp_ylmgen_c.h b/external/libsharp/libsharp/sharp_ylmgen_c.h similarity index 100% rename from external/libsharp/sharp_ylmgen_c.h rename to external/libsharp/libsharp/sharp_ylmgen_c.h diff --git a/external/libsharp/python/fake_pyrex/Pyrex/Distutils/__init__.py b/external/libsharp/python/fake_pyrex/Pyrex/Distutils/__init__.py new file mode 100644 index 000000000000..51c8e16b8e54 --- /dev/null +++ b/external/libsharp/python/fake_pyrex/Pyrex/Distutils/__init__.py @@ -0,0 +1 @@ +# work around broken setuptools monkey patching diff --git a/external/libsharp/python/fake_pyrex/Pyrex/Distutils/build_ext.py b/external/libsharp/python/fake_pyrex/Pyrex/Distutils/build_ext.py new file mode 100644 index 000000000000..4f846f6282cb --- /dev/null +++ b/external/libsharp/python/fake_pyrex/Pyrex/Distutils/build_ext.py @@ -0,0 +1 @@ +build_ext = "yes, it's there!" diff --git a/external/libsharp/python/fake_pyrex/Pyrex/__init__.py b/external/libsharp/python/fake_pyrex/Pyrex/__init__.py new file mode 100644 index 000000000000..51c8e16b8e54 --- /dev/null +++ b/external/libsharp/python/fake_pyrex/Pyrex/__init__.py @@ -0,0 +1 @@ +# work around broken setuptools monkey patching diff --git a/external/libsharp/python/fake_pyrex/README b/external/libsharp/python/fake_pyrex/README new file mode 100644 index 000000000000..cf3f3ff2f1e9 --- /dev/null +++ b/external/libsharp/python/fake_pyrex/README @@ -0,0 +1,2 @@ +This directory is here to fool setuptools into building .pyx files +even if Pyrex is not installed. See ../setup.py. \ No newline at end of file diff --git a/external/libsharp/python/libsharp/__init__.py b/external/libsharp/python/libsharp/__init__.py new file mode 100644 index 000000000000..dd0fa4161cf7 --- /dev/null +++ b/external/libsharp/python/libsharp/__init__.py @@ -0,0 +1 @@ +from .libsharp import * diff --git a/external/libsharp/python/libsharp/libsharp.pxd b/external/libsharp/python/libsharp/libsharp.pxd new file mode 100644 index 000000000000..27a46082cac9 --- /dev/null +++ b/external/libsharp/python/libsharp/libsharp.pxd @@ -0,0 +1,92 @@ +cdef extern from "sharp.h": + + void sharp_legendre_transform_s(float *bl, float *recfac, ptrdiff_t lmax, float *x, + float *out, ptrdiff_t nx) + void sharp_legendre_transform(double *bl, double *recfac, ptrdiff_t lmax, double *x, + double *out, ptrdiff_t nx) + void sharp_legendre_transform_recfac(double *r, ptrdiff_t lmax) + void sharp_legendre_transform_recfac_s(float *r, ptrdiff_t lmax) + void sharp_legendre_roots(int n, double *x, double *w) + + # sharp_lowlevel.h + ctypedef struct sharp_alm_info: + # Maximum \a l index of the array + int lmax + # Number of different \a m values in this object + int nm + # Array with \a nm entries containing the individual m values + int *mval + # Combination of flags from sharp_almflags + int flags + # Array with \a nm entries containing the (hypothetical) indices of + # the coefficients with quantum numbers 0,\a mval[i] + long *mvstart + # Stride between a_lm and a_(l+1),m + long stride + + ctypedef struct sharp_geom_info: + pass + + void sharp_make_alm_info (int lmax, int mmax, int stride, + ptrdiff_t *mvstart, sharp_alm_info **alm_info) + + void sharp_make_geom_info (int nrings, int *nph, ptrdiff_t *ofs, + int *stride, double *phi0, double *theta, + double *wgt, sharp_geom_info **geom_info) + + void sharp_destroy_alm_info(sharp_alm_info *info) + void sharp_destroy_geom_info(sharp_geom_info *info) + + ptrdiff_t sharp_map_size(sharp_geom_info *info) + ptrdiff_t sharp_alm_count(sharp_alm_info *self) + + + ctypedef enum sharp_jobtype: + SHARP_YtW + SHARP_Yt + SHARP_WY + SHARP_Y + + ctypedef enum: + SHARP_DP + SHARP_ADD + + void sharp_execute(sharp_jobtype type_, + int spin, + void *alm, + void *map, + sharp_geom_info *geom_info, + sharp_alm_info *alm_info, + int ntrans, + int flags, + double *time, + unsigned long long *opcnt) nogil + + ctypedef enum: + SHARP_ERROR_NO_MPI + + int sharp_execute_mpi_maybe (void *pcomm, sharp_jobtype type, int spin, + void *alm, void *map, sharp_geom_info *geom_info, + sharp_alm_info *alm_info, int ntrans, int flags, double *time, + unsigned long long *opcnt) nogil + + void sharp_normalized_associated_legendre_table(int m, int spin, int lmax, int ntheta, + double *theta, int theta_stride, int l_stride, int spin_stride, double *out) nogil + + +cdef extern from "sharp_geomhelpers.h": + void sharp_make_subset_healpix_geom_info( + int nside, int stride, int nrings, + int *rings, double *weight, sharp_geom_info **geom_info) + void sharp_make_gauss_geom_info( + int nrings, int nphi, double phi0, + int stride_lon, int stride_lat, sharp_geom_info **geom_info) + +cdef extern from "sharp_almhelpers.h": + void sharp_make_triangular_alm_info (int lmax, int mmax, int stride, + sharp_alm_info **alm_info) + void sharp_make_rectangular_alm_info (int lmax, int mmax, int stride, + sharp_alm_info **alm_info) + void sharp_make_mmajor_real_packed_alm_info (int lmax, int stride, + int nm, const int *ms, sharp_alm_info **alm_info) + diff --git a/external/libsharp/python/libsharp/libsharp.pyx b/external/libsharp/python/libsharp/libsharp.pyx new file mode 100644 index 000000000000..dfefc93aa386 --- /dev/null +++ b/external/libsharp/python/libsharp/libsharp.pyx @@ -0,0 +1,324 @@ +import numpy as np +cimport numpy as np +cimport cython + +__all__ = ['legendre_transform', 'legendre_roots', 'sht', 'synthesis', 'adjoint_synthesis', + 'analysis', 'adjoint_analysis', 'healpix_grid', 'triangular_order', 'rectangular_order', + 'packed_real_order', 'normalized_associated_legendre_table'] + + +def legendre_transform(x, bl, out=None): + if out is None: + out = np.empty_like(x) + if out.shape[0] == 0: + return out + elif x.dtype == np.float64: + if bl.dtype != np.float64: + bl = bl.astype(np.float64) + return _legendre_transform(x, bl, out=out) + elif x.dtype == np.float32: + if bl.dtype != np.float32: + bl = bl.astype(np.float32) + return _legendre_transform_s(x, bl, out=out) + else: + raise ValueError("unsupported dtype") + + +def _legendre_transform(double[::1] x, double[::1] bl, double[::1] out): + if out.shape[0] != x.shape[0]: + raise ValueError('x and out must have same shape') + sharp_legendre_transform(&bl[0], NULL, bl.shape[0] - 1, &x[0], &out[0], x.shape[0]) + return np.asarray(out) + + +def _legendre_transform_s(float[::1] x, float[::1] bl, float[::1] out): + if out.shape[0] != x.shape[0]: + raise ValueError('x and out must have same shape') + sharp_legendre_transform_s(&bl[0], NULL, bl.shape[0] - 1, &x[0], &out[0], x.shape[0]) + return np.asarray(out) + + +def legendre_roots(n): + x = np.empty(n, np.double) + w = np.empty(n, np.double) + cdef double[::1] x_buf = x, w_buf = w + if not (x_buf.shape[0] == w_buf.shape[0] == n): + raise AssertionError() + if n > 0: + sharp_legendre_roots(n, &x_buf[0], &w_buf[0]) + return x, w + + +JOBTYPE_TO_CONST = { + 'Y': SHARP_Y, + 'Yt': SHARP_Yt, + 'WY': SHARP_WY, + 'YtW': SHARP_YtW +} + +def sht(jobtype, geom_info ginfo, alm_info ainfo, double[:, :, ::1] input, + int spin=0, comm=None, add=False): + cdef void *comm_ptr + cdef int flags = SHARP_DP | (SHARP_ADD if add else 0) + cdef int r + cdef sharp_jobtype jobtype_i + cdef double[:, :, ::1] output_buf + cdef int ntrans = input.shape[0] + cdef int ntotcomp = ntrans * input.shape[1] + cdef int i, j + + if spin == 0 and input.shape[1] != 1: + raise ValueError('For spin == 0, we need input.shape[1] == 1') + elif spin != 0 and input.shape[1] != 2: + raise ValueError('For spin != 0, we need input.shape[1] == 2') + + + cdef size_t[::1] ptrbuf = np.empty(2 * ntotcomp, dtype=np.uintp) + cdef double **alm_ptrs = &ptrbuf[0] + cdef double **map_ptrs = &ptrbuf[ntotcomp] + + try: + jobtype_i = JOBTYPE_TO_CONST[jobtype] + except KeyError: + raise ValueError('jobtype must be one of: %s' % ', '.join(sorted(JOBTYPE_TO_CONST.keys()))) + + if jobtype_i == SHARP_Y or jobtype_i == SHARP_WY: + output = np.empty((input.shape[0], input.shape[1], ginfo.local_size()), dtype=np.float64) + output_buf = output + for i in range(input.shape[0]): + for j in range(input.shape[1]): + alm_ptrs[i * input.shape[1] + j] = &input[i, j, 0] + map_ptrs[i * input.shape[1] + j] = &output_buf[i, j, 0] + else: + output = np.empty((input.shape[0], input.shape[1], ainfo.local_size()), dtype=np.float64) + output_buf = output + for i in range(input.shape[0]): + for j in range(input.shape[1]): + alm_ptrs[i * input.shape[1] + j] = &output_buf[i, j, 0] + map_ptrs[i * input.shape[1] + j] = &input[i, j, 0] + + if comm is None: + with nogil: + sharp_execute ( + jobtype_i, + geom_info=ginfo.ginfo, alm_info=ainfo.ainfo, + spin=spin, alm=alm_ptrs, map=map_ptrs, + ntrans=ntrans, flags=flags, time=NULL, opcnt=NULL) + else: + from mpi4py import MPI + if not isinstance(comm, MPI.Comm): + raise TypeError('comm must be an mpi4py communicator') + from .libsharp_mpi import _addressof + comm_ptr = _addressof(comm) + with nogil: + r = sharp_execute_mpi_maybe ( + comm_ptr, jobtype_i, + geom_info=ginfo.ginfo, alm_info=ainfo.ainfo, + spin=spin, alm=alm_ptrs, map=map_ptrs, + ntrans=ntrans, flags=flags, time=NULL, opcnt=NULL) + if r == SHARP_ERROR_NO_MPI: + raise Exception('MPI requested, but not available') + + return output + + +def synthesis(*args, **kw): + return sht('Y', *args, **kw) + +def adjoint_synthesis(*args, **kw): + return sht('Yt', *args, **kw) + +def analysis(*args, **kw): + return sht('YtW', *args, **kw) + +def adjoint_analysis(*args, **kw): + return sht('WY', *args, **kw) + + +# +# geom_info +# +class NotInitializedError(Exception): + pass + + +cdef class geom_info: + cdef sharp_geom_info *ginfo + + def __cinit__(self, *args, **kw): + self.ginfo = NULL + + def local_size(self): + if self.ginfo == NULL: + raise NotInitializedError() + return sharp_map_size(self.ginfo) + + def __dealloc__(self): + if self.ginfo != NULL: + sharp_destroy_geom_info(self.ginfo) + self.ginfo = NULL + + +cdef class healpix_grid(geom_info): + + _weight_cache = {} # { (nside, 'T'/'Q'/'U') -> numpy array of ring weights cached from file } + + def __init__(self, int nside, stride=1, int[::1] rings=None, double[::1] weights=None): + if weights is not None and weights.shape[0] != 2 * nside: + raise ValueError('weights must have length 2 * nside') + sharp_make_subset_healpix_geom_info(nside, stride, + nrings=4 * nside - 1 if rings is None else rings.shape[0], + rings=NULL if rings is None else &rings[0], + weight=NULL if weights is None else &weights[0], + geom_info=&self.ginfo) + + @classmethod + def load_ring_weights(cls, nside, fields): + """ + Loads HEALPix ring weights from file. The environment variable + HEALPIX should be set, and this routine will look in the `data` + subdirectory. + + Parameters + ---------- + + nside: int + HEALPix nside parameter + + fields: tuple of str + Which weights to extract; pass ('T',) to only get scalar + weights back, or ('T', 'Q', 'U') to get all the weights + + Returns + ------- + + List of NumPy arrays, according to fields parameter. + + """ + import os + from astropy.io import fits + data_path = os.path.join(os.environ['HEALPIX'], 'data') + fits_field_names = { + 'T': 'TEMPERATURE WEIGHTS', + 'Q': 'Q-POLARISATION WEIGHTS', + 'U': 'U-POLARISATION WEIGHTS'} + + must_load = [field for field in fields if (nside, field) not in cls._weight_cache] + + if must_load: + hdulist = fits.open(os.path.join(data_path, 'weight_ring_n%05d.fits' % nside)) + try: + for field in must_load: + w = hdulist[1].data.field(fits_field_names[field]).ravel().astype(np.double) + w += 1 + cls._weight_cache[nside, field] = w + finally: + hdulist.close() + return [cls._weight_cache[(nside, field)].copy() for field in fields] + +# +# alm_info +# + + +cdef class alm_info: + cdef sharp_alm_info *ainfo + + def __cinit__(self, *args, **kw): + self.ainfo = NULL + + def local_size(self): + if self.ainfo == NULL: + raise NotInitializedError() + return sharp_alm_count(self.ainfo) + + def mval(self): + if self.ainfo == NULL: + raise NotInitializedError() + return np.asarray( self.ainfo.mval) + + def mvstart(self): + if self.ainfo == NULL: + raise NotInitializedError() + return np.asarray( self.ainfo.mvstart) + + def __dealloc__(self): + if self.ainfo != NULL: + sharp_destroy_alm_info(self.ainfo) + self.ainfo = NULL + + @cython.boundscheck(False) + def almxfl(self, np.ndarray[double, ndim=3, mode='c'] alm, np.ndarray[double, ndim=2, mode='c'] fl): + """Multiply Alm by a Ell based array + + + Parameters + ---------- + alm : np.ndarray + input alm, 3 dimensions = (different signal x polarizations x lm-ordering) + fl : np.ndarray + either 1 dimension, e.g. gaussian beam, or 2 dimensions e.g. a polarized beam + + Returns + ------- + None, it modifies alms in-place + + """ + cdef int mvstart = 0 + cdef bint has_multiple_beams = alm.shape[2] > 1 and fl.shape[1] > 1 + cdef int f, i_m, m, num_ells, i_l, i_signal, i_pol, i_mv + + for i_m in range(self.ainfo.nm): + m = self.ainfo.mval[i_m] + f = 1 if (m==0) else 2 + num_ells = self.ainfo.lmax + 1 - m + + if not has_multiple_beams: + for i_signal in range(alm.shape[0]): + for i_pol in range(alm.shape[1]): + for i_l in range(num_ells): + l = m + i_l + for i_mv in range(mvstart + f*i_l, mvstart + f*i_l +f): + alm[i_signal, i_pol, i_mv] *= fl[l, 0] + else: + for i_signal in range(alm.shape[0]): + for i_pol in range(alm.shape[1]): + for i_l in range(num_ells): + l = m + i_l + for i_mv in range(mvstart + f*i_l, mvstart + f*i_l +f): + alm[i_signal, i_pol, i_mv] *= fl[l, i_pol] + mvstart += f * num_ells + +cdef class triangular_order(alm_info): + def __init__(self, int lmax, mmax=None, stride=1): + mmax = mmax if mmax is not None else lmax + sharp_make_triangular_alm_info(lmax, mmax, stride, &self.ainfo) + + +cdef class rectangular_order(alm_info): + def __init__(self, int lmax, mmax=None, stride=1): + mmax = mmax if mmax is not None else lmax + sharp_make_rectangular_alm_info(lmax, mmax, stride, &self.ainfo) + + +cdef class packed_real_order(alm_info): + def __init__(self, int lmax, stride=1, int[::1] ms=None): + sharp_make_mmajor_real_packed_alm_info(lmax=lmax, stride=stride, + nm=lmax + 1 if ms is None else ms.shape[0], + ms=NULL if ms is None else &ms[0], + alm_info=&self.ainfo) + +# +# +# + +@cython.boundscheck(False) +def normalized_associated_legendre_table(int lmax, int m, theta): + cdef double[::1] theta_ = np.ascontiguousarray(theta, dtype=np.double) + out = np.zeros((theta_.shape[0], lmax - m + 1), np.double) + cdef double[:, ::1] out_ = out + if lmax < m: + raise ValueError("lmax < m") + with nogil: + sharp_normalized_associated_legendre_table(m, 0, lmax, theta_.shape[0], &theta_[0], lmax - m + 1, 1, 1, &out_[0,0]) + return out diff --git a/external/libsharp/python/libsharp/libsharp_mpi.pyx b/external/libsharp/python/libsharp/libsharp_mpi.pyx new file mode 100644 index 000000000000..e819a7744ef5 --- /dev/null +++ b/external/libsharp/python/libsharp/libsharp_mpi.pyx @@ -0,0 +1,17 @@ +cdef extern from "mpi.h": + ctypedef void *MPI_Comm + +cdef extern from "Python.h": + object PyLong_FromVoidPtr(void*) + +cdef extern: + ctypedef class mpi4py.MPI.Comm [object PyMPICommObject]: + cdef MPI_Comm ob_mpi + cdef unsigned flags + +# For compatibility with mpi4py <= 1.3.1 +# Newer versions could use the MPI._addressof function +def _addressof(Comm comm): + cdef void *ptr = NULL + ptr = &comm.ob_mpi + return PyLong_FromVoidPtr(ptr) diff --git a/external/libsharp/python/libsharp/tests/__init__.py b/external/libsharp/python/libsharp/tests/__init__.py new file mode 100644 index 000000000000..1bb8bf6d7fd4 --- /dev/null +++ b/external/libsharp/python/libsharp/tests/__init__.py @@ -0,0 +1 @@ +# empty diff --git a/external/libsharp/python/libsharp/tests/test_legendre.py b/external/libsharp/python/libsharp/tests/test_legendre.py new file mode 100644 index 000000000000..0129b29c3c1d --- /dev/null +++ b/external/libsharp/python/libsharp/tests/test_legendre.py @@ -0,0 +1,58 @@ +import numpy as np +from scipy.special import legendre +from scipy.special import p_roots +import libsharp + +from numpy.testing import assert_allclose + + +def check_legendre_transform(lmax, ntheta): + l = np.arange(lmax + 1) + if lmax >= 1: + sigma = -np.log(1e-3) / lmax / (lmax + 1) + bl = np.exp(-sigma*l*(l+1)) + bl *= (2 * l + 1) + else: + bl = np.asarray([1], dtype=np.double) + + theta = np.linspace(0, np.pi, ntheta, endpoint=True) + x = np.cos(theta) + + # Compute truth using scipy.special.legendre + P = np.zeros((ntheta, lmax + 1)) + for l in range(lmax + 1): + P[:, l] = legendre(l)(x) + y0 = np.dot(P, bl) + + + # double-precision + y = libsharp.legendre_transform(x, bl) + + assert_allclose(y, y0, rtol=1e-12, atol=1e-12) + + # single-precision + y32 = libsharp.legendre_transform(x.astype(np.float32), bl) + assert_allclose(y, y0, rtol=1e-5, atol=1e-5) + + +def test_legendre_transform(): + nthetas_to_try = [0, 9, 17, 19] + list(np.random.randint(500, size=20)) + for ntheta in nthetas_to_try: + for lmax in [0, 1, 2, 3, 20] + list(np.random.randint(50, size=4)): + yield check_legendre_transform, lmax, ntheta + +def check_legendre_roots(n): + xs, ws = ([], []) if n == 0 else p_roots(n) # from SciPy + xl, wl = libsharp.legendre_roots(n) + assert_allclose(xs, xl, rtol=1e-14, atol=1e-14) + assert_allclose(ws, wl, rtol=1e-14, atol=1e-14) + +def test_legendre_roots(): + """ + Test the Legendre root-finding algorithm from libsharp by comparing it with + the SciPy version. + """ + yield check_legendre_roots, 0 + yield check_legendre_roots, 1 + yield check_legendre_roots, 32 + yield check_legendre_roots, 33 diff --git a/external/libsharp/python/libsharp/tests/test_legendre_table.py b/external/libsharp/python/libsharp/tests/test_legendre_table.py new file mode 100644 index 000000000000..eb02df289a20 --- /dev/null +++ b/external/libsharp/python/libsharp/tests/test_legendre_table.py @@ -0,0 +1,36 @@ +from __future__ import print_function +import numpy as np + +from numpy.testing import assert_almost_equal +from nose.tools import eq_, ok_ + +from libsharp import normalized_associated_legendre_table +from scipy.special import sph_harm, p_roots + +def test_compare_legendre_table_with_scipy(): + def test(theta, m, lmax): + Plm = normalized_associated_legendre_table(lmax, m, theta) + + Plm_p = sph_harm(m, np.arange(m, lmax + 1), 0, theta)[None, :] + if not np.allclose(Plm_p, Plm): + print(Plm_p) + print(Plm) + return ok_, np.allclose(Plm_p, Plm) + + yield test(np.pi/2, 0, 10) + yield test(np.pi/4, 0, 10) + yield test(3 * np.pi/4, 0, 10) + yield test(np.pi/4, 1, 4) + yield test(np.pi/4, 2, 4) + yield test(np.pi/4, 50, 50) + yield test(np.pi/2, 49, 50) + + +def test_legendre_table_wrapper_logic(): + # tests the SSE 2 logic in the high-level wrapper by using an odd number of thetas + theta = np.asarray([np.pi/2, np.pi/4, 3 * np.pi / 4]) + m = 3 + lmax = 10 + Plm = normalized_associated_legendre_table(lmax, m, theta) + assert np.allclose(Plm[1, :], normalized_associated_legendre_table(lmax, m, np.pi/4)[0, :]) + assert np.allclose(Plm[2, :], normalized_associated_legendre_table(lmax, m, 3 * np.pi/4)[0, :]) diff --git a/external/libsharp/python/libsharp/tests/test_sht.py b/external/libsharp/python/libsharp/tests/test_sht.py new file mode 100644 index 000000000000..63ccf2078251 --- /dev/null +++ b/external/libsharp/python/libsharp/tests/test_sht.py @@ -0,0 +1,32 @@ +import numpy as np +from numpy.testing import assert_allclose +import libsharp + +from mpi4py import MPI + + +def test_basic(): + lmax = 10 + nside = 8 + rank = MPI.COMM_WORLD.Get_rank() + ms = np.arange(rank, lmax + 1, MPI.COMM_WORLD.Get_size(), dtype=np.int32) + + order = libsharp.packed_real_order(lmax, ms=ms) + grid = libsharp.healpix_grid(nside) + + + alm = np.zeros(order.local_size()) + if rank == 0: + alm[0] = 1 + elif rank == 1: + alm[0] = 1 + + + map = libsharp.synthesis(grid, order, np.repeat(alm[None, None, :], 3, 0), comm=MPI.COMM_WORLD) + assert np.all(map[2, :] == map[1, :]) and np.all(map[1, :] == map[0, :]) + map = map[0, 0, :] + print(rank, "shape", map.shape) + print(rank, "mean", map.mean()) + +if __name__=="__main__": + test_basic() diff --git a/external/libsharp/python/libsharp/tests/test_smoothing_noise_pol_mpi.py b/external/libsharp/python/libsharp/tests/test_smoothing_noise_pol_mpi.py new file mode 100644 index 000000000000..2cdff951d014 --- /dev/null +++ b/external/libsharp/python/libsharp/tests/test_smoothing_noise_pol_mpi.py @@ -0,0 +1,137 @@ +# This test needs to be run with: + +# mpirun -np X python test_smoothing_noise_pol_mpi.py + +from mpi4py import MPI + +import numpy as np + +import healpy as hp + +import libsharp + +mpi = True +rank = MPI.COMM_WORLD.Get_rank() + +nside = 256 +npix = hp.nside2npix(nside) + +np.random.seed(100) +input_map = np.random.normal(size=(3, npix)) +fwhm_deg = 10 +lmax = 512 + +nrings = 4 * nside - 1 # four missing pixels + +if rank == 0: + print("total rings", nrings) + +n_mpi_processes = MPI.COMM_WORLD.Get_size() +rings_per_process = nrings // n_mpi_processes + 1 +# ring indices are 1-based + +ring_indices_emisphere = np.arange(2*nside, dtype=np.int32) + 1 +local_ring_indices = ring_indices_emisphere[rank::n_mpi_processes] + +# to improve performance, simmetric rings north/south need to be in the same rank +# therefore we use symmetry to create the full ring indexing + +if local_ring_indices[-1] == 2 * nside: + # has equator ring + local_ring_indices = np.concatenate( + [local_ring_indices[:-1], + nrings - local_ring_indices[::-1] + 1] + ) +else: + # does not have equator ring + local_ring_indices = np.concatenate( + [local_ring_indices, + nrings - local_ring_indices[::-1] + 1] + ) + +print("rank", rank, "n_rings", len(local_ring_indices)) + +if not mpi: + local_ring_indices = None +grid = libsharp.healpix_grid(nside, rings=local_ring_indices) + +# returns start index of the ring and number of pixels +startpix, ringpix, _, _, _ = hp.ringinfo(nside, local_ring_indices.astype(np.int64)) + +local_npix = grid.local_size() + +def expand_pix(startpix, ringpix, local_npix): + """Turn first pixel index and number of pixel in full array of pixels + + to be optimized with cython or numba + """ + local_pix = np.empty(local_npix, dtype=np.int64) + i = 0 + for start, num in zip(startpix, ringpix): + local_pix[i:i+num] = np.arange(start, start+num) + i += num + return local_pix + +local_pix = expand_pix(startpix, ringpix, local_npix) + +local_map = input_map[:, local_pix] + +local_hitmap = np.zeros(npix) +local_hitmap[local_pix] = 1 +hp.write_map("hitmap_{}.fits".format(rank), local_hitmap, overwrite=True) + +print("rank", rank, "npix", npix, "local_npix", local_npix, "local_map len", len(local_map), "unique pix", len(np.unique(local_pix))) + +local_m_indices = np.arange(rank, lmax + 1, MPI.COMM_WORLD.Get_size(), dtype=np.int32) +if not mpi: + local_m_indices = None + +order = libsharp.packed_real_order(lmax, ms=local_m_indices) +local_nl = order.local_size() +print("rank", rank, "local_nl", local_nl, "mval", order.mval()) + +mpi_comm = MPI.COMM_WORLD if mpi else None + +# map2alm +# maps in libsharp are 3D, 2nd dimension is IQU, 3rd is pixel + +alm_sharp_I = libsharp.analysis(grid, order, + np.ascontiguousarray(local_map[0].reshape((1, 1, -1))), + spin=0, comm=mpi_comm) +alm_sharp_P = libsharp.analysis(grid, order, + np.ascontiguousarray(local_map[1:].reshape((1, 2, -1))), + spin=2, comm=mpi_comm) + +beam = hp.gauss_beam(fwhm=np.radians(fwhm_deg), lmax=lmax, pol=True) + +print("Smooth") +# smooth in place (zonca implemented this function) +order.almxfl(alm_sharp_I, np.ascontiguousarray(beam[:, 0:1])) +order.almxfl(alm_sharp_P, np.ascontiguousarray(beam[:, (1, 2)])) + +# alm2map + +new_local_map_I = libsharp.synthesis(grid, order, alm_sharp_I, spin=0, comm=mpi_comm) +new_local_map_P = libsharp.synthesis(grid, order, alm_sharp_P, spin=2, comm=mpi_comm) + +# Transfer map to first process for writing + +local_full_map = np.zeros(input_map.shape, dtype=np.float64) +local_full_map[0, local_pix] = new_local_map_I +local_full_map[1:, local_pix] = new_local_map_P + +output_map = np.zeros(input_map.shape, dtype=np.float64) if rank == 0 else None +mpi_comm.Reduce(local_full_map, output_map, root=0, op=MPI.SUM) + +if rank == 0: + # hp.write_map("sharp_smoothed_map.fits", output_map, overwrite=True) + # hp_smoothed = hp.alm2map(hp.map2alm(input_map, lmax=lmax), nside=nside) # transform only + hp_smoothed = hp.smoothing(input_map, fwhm=np.radians(fwhm_deg), lmax=lmax) + std_diff = (hp_smoothed-output_map).std() + print("Std of difference between libsharp and healpy", std_diff) + # hp.write_map( + # "healpy_smoothed_map.fits", + # hp_smoothed, + # overwrite=True + # ) + assert std_diff < 1e-5 diff --git a/external/libsharp/python/setup.py b/external/libsharp/python/setup.py new file mode 100644 index 000000000000..788d7a607772 --- /dev/null +++ b/external/libsharp/python/setup.py @@ -0,0 +1,83 @@ +#! /usr/bin/env python + +descr = """Spherical Harmionic transforms package + +Python API for the libsharp spherical harmonic transforms library +""" + +import os +import sys + +DISTNAME = 'libsharp' +DESCRIPTION = 'libsharp library for fast Spherical Harmonic Transforms' +LONG_DESCRIPTION = descr +MAINTAINER = 'Dag Sverre Seljebotn', +MAINTAINER_EMAIL = 'd.s.seljebotn@astro.uio.no', +URL = 'http://sourceforge.net/projects/libsharp/' +LICENSE = 'GPL' +DOWNLOAD_URL = "http://sourceforge.net/projects/libsharp/" +VERSION = '0.1' + +# Add our fake Pyrex at the end of the Python search path +# in order to fool setuptools into allowing compilation of +# pyx files to C files. Importing Cython.Distutils then +# makes Cython the tool of choice for this rather than +# (the possibly nonexisting) Pyrex. +project_path = os.path.split(__file__)[0] +sys.path.append(os.path.join(project_path, 'fake_pyrex')) + +from setuptools import setup, find_packages, Extension +from Cython.Build import cythonize +import numpy as np + +libsharp = os.environ.get('LIBSHARP', None) +libsharp_include = os.environ.get('LIBSHARP_INCLUDE', libsharp and os.path.join(libsharp, 'include')) +libsharp_lib = os.environ.get('LIBSHARP_LIB', libsharp and os.path.join(libsharp, 'lib')) + +if libsharp_include is None or libsharp_lib is None: + sys.stderr.write('Please set LIBSHARP environment variable to the install directly of libsharp, ' + 'this script will refer to the lib and include sub-directories. Alternatively ' + 'set LIBSHARP_INCLUDE and LIBSHARP_LIB\n') + sys.exit(1) + +if __name__ == "__main__": + setup(install_requires = ['numpy'], + packages = find_packages(), + test_suite="nose.collector", + # Well, technically zipping the package will work, but since it's + # all compiled code it'll just get unzipped again at runtime, which + # is pointless: + zip_safe = False, + name = DISTNAME, + version = VERSION, + maintainer = MAINTAINER, + maintainer_email = MAINTAINER_EMAIL, + description = DESCRIPTION, + license = LICENSE, + url = URL, + download_url = DOWNLOAD_URL, + long_description = LONG_DESCRIPTION, + classifiers = + [ 'Development Status :: 3 - Alpha', + 'Environment :: Console', + 'Intended Audience :: Developers', + 'Intended Audience :: Science/Research', + 'License :: OSI Approved :: GNU General Public License (GPL)', + 'Topic :: Scientific/Engineering'], + ext_modules = cythonize([ + Extension("libsharp.libsharp", + ["libsharp/libsharp.pyx"], + libraries=["sharp", "fftpack", "c_utils"], + include_dirs=[libsharp_include, np.get_include()], + library_dirs=[libsharp_lib], + extra_link_args=["-fopenmp"], + ), + Extension("libsharp.libsharp_mpi", + ["libsharp/libsharp_mpi.pyx"], + libraries=["sharp", "fftpack", "c_utils"], + include_dirs=[libsharp_include, np.get_include()], + library_dirs=[libsharp_lib], + extra_link_args=["-fopenmp"], + ), + ]), + ) diff --git a/external/libsharp/runjinja.py b/external/libsharp/runjinja.py new file mode 100755 index 000000000000..fb06737d69b4 --- /dev/null +++ b/external/libsharp/runjinja.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python + +""" +Preprocesses foo.c.in to foo.c. Reads STDIN and writes STDOUT. +""" + +import sys +import hashlib +from jinja2 import Template, Environment + +env = Environment(block_start_string='/*{', + block_end_string='}*/', + variable_start_string='{{', + variable_end_string='}}') + +extra_vars = dict(len=len) +input = sys.stdin.read() +sys.stdout.write('/* DO NOT EDIT. md5sum of source: %s */' % hashlib.md5(input.encode()).hexdigest()) +sys.stdout.write(env.from_string(input).render(**extra_vars))