Code Monkey home page Code Monkey logo

fftwpp's Introduction

FFTW++

Library of Fast Fourier Transforms, Convolutions, and MPI Transposes built on FFTW3

Copyright © 2004-2024 by John C. Bowman, Malcolm Roberts, and Noel Murasko, University of Alberta http://fftwpp.sourceforge.net


FFTW++ is a C++ header/MPI transpose for Version 3 of the highly optimized FFTW Fourier Transform library. It provides a simple interface for 1D, 2D, and 3D complex-to-complex, real-to-complex, and complex-to-real Fast Fourier Transforms and convolutions. It takes care of the technical aspects of memory allocation, alignment, planning, wisdom, and communication on both serial and parallel (OpenMP/MPI) architectures. Wrappers for multiple 1D transforms are also provided. As with the FFTW3 library itself, both in-place and out-of-place transforms of arbitrary size are supported.

For reproducibility of Hybrid Dealiased Convolutions, see the test programs below.

Implicit dealiasing of standard and centered Hermitian convolutions is also implemented; in 2D and 3D implicit zero-padding substantially reduces memory usage and computation time. For more information, see

Convenient optional shift routines that place the Fourier origin in the logical center of the domain are provided for centered complex-to-real transforms in 2D and 3D; see fftw++.h for details.

FFTW++ supports multithreaded transforms and convolutions. The global variable fftw::maxthreads specifies the maximum number of threads to use. The constructors invoke a short timing test to check that using multiple threads is actually beneficial for the given problem size. Multithreading requires linking with a multithreaded FFTW implementation and can be disabled by adding -DFFTWPP_SINGLE_THREAD to CFLAGS.

FFTW++ can also exploit the high-performance Array class available here (version 1.58 or higher), designed for scientific computing. The arrays in that package do memory bounds checking in debugging mode, but can be optimized by specifying the -DNDEBUG compilation option (1D arrays optimize completely to pointer operations).

Detailed documentation is provided before each class in the fftw++.h header file. The included examples illustrate how easy it is to use FFTW in C++ with the FFTW++ header class. Use of the Array class is optional, but encouraged. If for some reason the Array class is not used, memory should be allocated with ComplexAlign (or doubleAlign) to ensure that the data is optimally aligned to sizeof(Complex), to enable the SIMD extensions. The optional alignment check in fftw++.h can be disabled with the -DNO_CHECK_ALIGN compiler option.

Examples

The following programs are provided in the examples directory:

  • 1D examples using ComplexAlign allocator:

    • example0.cc
    • example0r.cc
  • 1D examples using Array class:

    • example1.cc
    • example1r.cc
  • 2D examples using Array class:

    • example2.cc
    • example2r.cc
  • 3D examples using Array class:

    • example3.cc
    • example3r.cc
  • Examples of hybrid dealiased convolutions on complex data in 1, 2, and 3 dimensions:

    • exampleconv.cc
    • exampleconv2.cc
    • exampleconv3.cc
  • Examples of hybrid dealiased convolutions on complex Hermitian-symmetric centered data in 1, 2, and 3 dimensions:

    • exampleconvh.cc
    • exampleconvh2.cc
    • exampleconvh3.cc
  • Examples of hybrid dealiased convolutions on real data in 1, 2, and 3 dimensions:

    • exampleconvr.cc
    • exampleconvr2.cc
    • exampleconvr3.cc
  • Local transpose (in-place or out-of-place):

    • exampletranspose.cc

More general types of convolutions (for example, autoconvolutions) can be performed by defining a custom multiplier function.

Wrappers

Wrappers for the convolution routines are available for C, Fortran, and Python. Examples are given in the wrappers/ directory. The C wrapper may be found in cfftw++.h and cfftw++.cc, the Fortran wrapper in fftwpp.f90, and the Python wrapper in fftwpp.py. A unit-testing script, test.py, is also available. Results for the given input data are checked with a simple hash.

Compilation uses the environment variables CPLUS_INCLUDE_PATH to tell the compiler where to find fftw3.h, and FORTRAN_INCLUDE_PATH to indicate to the compiler the location of fftw3.f03 from FFTW.

In the wrappers directory are examples of calling multi-threaded 1D, 2D, and 3D complex or Hermitian-symmetric convolutions from Python: pexample.py

C: cexample.c

Fortan 90: fexample.f90

MPI

OpenMP/MPI versions of the convolution routines in 2 and 3 dimensions are available in the mpi/ directory. Parallelization is accomplished using the adaptive hybrid OpenMP/MPI transpose routine described in

  • Adaptive Matrix Transpose Algorithms for Distributed Multicore Processors, John C. Bowman and Malcolm Roberts. Interdisciplinary Topics in Applied Mathematics, Modeling and Computational Science, Springer Proceedings in Mathematics & Statistics 117, 97-103 (2015): http://www.math.ualberta.ca/~bowman/publications/transpose.pdf

Either a 1D ("slab") and 2D ("pencil") data decomposition is used for the three-dimensional convolutions, depending on the number of processors.

hybridconv2.cc and hybridconv3.cc demonstrate two- and three-dimensional complex convolutions.

hybridconvh2.cc and hybridconvh3.cc demonstrate two- and three-dimensional Hermitian-symmetric centered convolutions.

fft2.cc and fft2r.cc demonstrate two-dimensional MPI/OpenMP FFTs using a 1D data decomposition, for complex and real data, respectively.

fft3.cc and fft3r.cc demonstrate three-dimensional MPI/OpenMP FFTs for complex and real data, respectively.

timing.py is a script which performs timing tests for MPI-based convolutions.

The directory mpi/explicit is used for comparing our adaptive distributed transpose against FFTW's parallel MPI transpose.

Test Programs

The following programs are provided in tests/, along with various timing and error analysis scripts. Asymptote scripts are provided for visualizing the output. Passing the argument -h to each of these programs outputs usage information.

  • 1D complex convolution test: hybridconv

  • 1D Hermitian convolution test: hybridconvh

  • 1D real convolution test: hybridconvr

  • 2D complex convolution test: hybridconv2

  • 2D Hermitian convolution test: hybridconvh2

  • 2D real convolution test: hybridconvr2

  • 3D complex convolution test: hybridconv3

  • 3D Hermitian convolution test: hybridconvh3

  • 1D FFT: fft1

  • 1D real FFT: fft1r

  • 1D multiple FFT: mfft1

  • 1D multiple real FFT: mfft1r

  • 2D FFT: fft2

  • 2D real FFT: fft2r

  • 3D FFT: fft3

  • 3D real FFT: fft3r

Availability and License

To compile from Git developmental source code: git clone https://github.com/dealias/fftwpp

All source files in the FFTW++ project, unless explicitly noted otherwise, are released under version 3 (or later) of the GNU Lesser General Public License (see the files LICENSE.LESSER and LICENSE in the top-level source directory).


This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.


fftwpp's People

Contributors

egpbos avatar johncbowman avatar malcolmroberts avatar noelmurasko avatar outurnate avatar robertboy18 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fftwpp's Issues

Configuration fails since 'No fftw_malloc in -lfftw3'

I try to configure C code as follows:
./configure --with-fftw=/usr/local/fftw-3.3.6-pl2/
But I receive the error stated in the title.
I've tried adding the lib directory to the LD_LIBRARY_PATH and configure it with -L.

Thanks for the help

mpi test fails

Running the mpi unit tests, I had at least one failure using 68797f9. This is with fftw 3.3.6-pl2

Running the case

mpirun -n 8 ./conv3 -x2 -y2 -z2 -N1 -s1 -a1 -X0 -Y1 -Z1 -A2 -T3 -tq

fails with code 134, which is a memory corruption. This is reproducable on our cascade test machine.

clang-tidy warnings

clang-tidy is giving the following:

Array.h:192:5: warning: Call to virtual method 'array1::Dimension' during construction bypasses virtual dispatch [clang-analyzer-optin.cplusplus.VirtualCall]
    Dimension(nx0);
    ^
fftw++.cpp:22:19: note: Calling constructor for 'array1<std::complex<double>>'
  array1<Complex> f(n, align);
                  ^
Array.h:204:5: note: Calling 'array1::Allocate'
    Allocate(nx0,align);
    ^
Array.h:192:5: note: Call to virtual method 'array1::Dimension' during construction bypasses virtual dispatch
    Dimension(nx0);
    ^

What is the difference of array and Array.

I have noticed there are two kinds of array and Array. Could you please give me some suggestions about the differences between these two arries.
Can we set the storage format of the array. (c like or fortran like.)

FFTW in Qt

Hello,

someone could help me to link this libary in Qt?

MZ

FFTW Wisdom import/export functions missing

I'm trying to use this library in Qt, and i cannot find where functions like fftw_export_wisdom_to_string() are located, either in this codebase or any online. Where were these functions expected to be defined?

installing fftwpp on python

Hello John and/or Malcolm,

It's been a while. I have heard very good things about fftwpp recently and am very curious to try it out. I thought there was a wrapper for python. If yes do you have any advice on how one might set this up? If no maybe it's too much work.

Thanks for putting this together, it looks really great!

Francis

Unresolved external symbols in VS2019 build

I have a Visual Studio project using FFTWpp and I have run into the following build problem. I am getting errors of unresolved external symbols. I am using fftwpp from vcpkg but I obtained the same errors using the library directly. The errors arise in the obj file. The output is the following.

error LNK2019: unresolved external symbol "public: __cdecl fftwpp::ThreadBase::ThreadBase(void)" (??0ThreadBase@fftwpp@@qeaa@XZ) referenced in function "public: __cdecl fftwpp::fftw::fftw(unsigned int,int,unsigned int,unsigned int)" (??0fftw@fftwpp@@qeaa@IHII@Z)
error LNK2001: unresolved external symbol "char const * const fftwpp::inout" (?inout@fftwpp@@3PEBDEB)
error LNK2001: unresolved external symbol "public: static unsigned int fftwpp::fftw::effort" (?effort@fftw@fftwpp@@2ia)
error LNK2001: unresolved external symbol "public: static unsigned int fftwpp::fftw::maxthreads" (?maxthreads@fftw@fftwpp@@2ia)
error LNK2001: unresolved external symbol "public: static double fftwpp::fftw::testseconds" (?testseconds@fftw@fftwpp@@2NA)
error LNK2001: unresolved external symbol "public: static struct fftw_plan_s * (__cdecl* fftwpp::fftw::planner)(class fftwpp::fftw *,class std::complex *,class std::complex *)" (?planner@fftw@fftwpp@@2P6APEAUfftw_plan_s@@PEAV12@PEAV?$complex@N@std@@1@ZEA)

Do you have any ideas on how to fix this?

convolution segmentation fault

I run into segmentation faults when running the tests (conv2 and conv3, all others seem ok).

I'm using clang, and to get convolution.cc to compile (non-POD variable-length arrays are not suported), I modified ImplicitHConvolution::convolve as follows

void ImplicitHConvolution::convolve(Complex **F, 
                                    realmultiplier *pmult, unsigned int offset)

475- Complex c1c[C] ;
475+ Complex * c1c = new Complex[C];
...
515- Complex S[B];
515+ Complex * S = new Complex[B]
...

601+ delete[] c1c;
602+ delete[] S;

The tests (conv2/conv3) give a segmentation fault when running

void ImplicitConvolution::convolve(Complex **F,
                                   multiplier *pmult, unsigned int offset)

at the point where premult is called (more specifically at line 249)

213 void ImplicitHConvolution::premult(Complex ** F,
                   unsigned int offset,
                   Complex* f1c){
...
if(even) {
   ...
    for(unsigned int i=0; i < A; ++i) {
     ...
249      STORE(f1c+i,CONJ(A+B)); //segmentation fault
    }
  }
}

I haven't tested with any other compilers. I was wondering if this is due to the changes I made, a clang issue, or something else?
Thanks for the help.

Just in case, this is the output

$ ./conv2
min padded buffer=10
min padded buffer=10
nx=16, ny=16
mx=4, my=4
N=39062
threads=1

Segmentation fault: 11

$ ./conv3
min padded buffer=10
min padded buffer=10
min padded buffer=10
nx=16, ny=16, nz=16
mx=4, my=4, mz=4
N=2441
threads=1

Segmentation fault: 11

Compilation fails if using CImg in the same project.

Error:

~/fftw++-2.02/Complex.h:31:7: error: expected identifier before numeric constant
 class Complex
       ^
~/fftw++-2.02/Complex.h:31:7: error: expected unqualified-id before numeric constant

Used compiler: g++-4.8.5 and g++-5.3.0

'Cannot open source file fftw3.h'

When compiling my code with fftw++, a bunch of errors popped up. After fixing my own, it looked like most of them were the result of a missing file in fftw++.h . I checked the folders I'd downloaded (and I downloaded fftw++ at most four days ago) and there is no fftw3.h in the folders. I also tried dropping one in from FFTW (one of the other problem areas was line extern "C" fftw_plan Planner(fftw *F, Complex *in, Complex *out);), but that didn't work either... which seems to indicate that the file was excluded on purpose but a number of parts weren't removed from the code. Okay.

If someone could reply soon, that would be great; I'm doing some time-sensitive stuff. If not... well, at least this stuff will be fixed for the next person.

MPI_(I)alltoall

With OpenMPI 1.6.5 / gcc 4.9.3
I have:

vhuber@machine: mpirun -npernode 16 ./cconv2 -i -S-1 -T1 -m64
Configuration: 16 nodes X 1 threads/node
Using MPI VERSION 2
N=244
A=2
mx=64, my=64
[irma-atlas:19263] *** An error occurred in MPI_Alltoall
[irma-atlas:19263] *** on communicator MPI COMMUNICATOR 4 SPLIT FROM 3
[irma-atlas:19263] *** MPI_ERR_ARG: invalid argument of some other kind
[irma-atlas:19263] *** MPI_ERRORS_ARE_FATAL: your MPI job will now abort
--------------------------------------------------------------------------
mpirun has exited due to process rank 13 with PID 19270 on
node irma-atlas exiting improperly. There are two reasons this could occur:

1. this process did not call "init" before exiting, but others in
the job did. This can cause a job to hang indefinitely while it waits
for all processes to call "init". By rule, if one process calls "init",
then ALL processes must call "init" prior to termination.

2. this process called "init", but exited without calling "finalize".
By rule, all processes that call "init" MUST call "finalize" prior to
exiting or it will be considered an "abnormal termination"

This may have caused other processes in the application to be
terminated by signals sent by mpirun (as reported here).
--------------------------------------------------------------------------
[irma-atlas:19229] 15 more processes have sent help message help-mpi-errors.txt / mpi_errors_are_fatal
[irma-atlas:19229] Set MCA parameter "orte_base_help_aggregate" to 0 to see all help / error messages

Whith OpenMpi 1.10.3 / gcc 4.9.0

mpirun -np 4 ./cconv2 -i -S-1 -T1 -m64
Configuration: 4 nodes X 1 threads/node
Using MPI VERSION 3
N=244
A=2
mx=64, my=64
[irma-atlas:47509] *** An error occurred in MPI_Ialltoall
[irma-atlas:47509] *** reported by process [1019478017,0]
[irma-atlas:47509] *** on communicator MPI_COMM_WORLD
[irma-atlas:47509] *** MPI_ERR_INTERN: internal error
[irma-atlas:47509] *** MPI_ERRORS_ARE_FATAL (processes in this communicator will now abort,
[irma-atlas:47509] ***    and potentially your MPI job)

Looking into the code, it appears that this fails when using MPI_IN_PLACE

I though that was linked to open-mpi/ompi#1023

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.