SHAFFT 1.1.0-alpha
A Scalable High-dimensional Accelerated FFT Library
Loading...
Searching...
No Matches
shafft::FFT1D Class Reference

1-dimensional distributed FFT plan with RAII semantics. More...

#include <shafft.hpp>

Public Member Functions

 FFT1D () noexcept=default
 Default constructor (uninitialized).
 
 ~FFT1D () noexcept override
 Destructor.
 
void release () noexcept override
 Release all internal resources.
 
 FFT1D (FFT1D &&other) noexcept
 Move constructor.
 
FFT1Doperator= (FFT1D &&other) noexcept
 Move assignment operator.
 
 FFT1D (const FFT1D &)=delete
 
FFT1Doperator= (const FFT1D &)=delete
 
int init (size_t globalN, size_t localN, size_t localStart, FFTType precision, MPI_Comm comm) noexcept
 Initialize plan.
 
int plan () noexcept override
 Create backend FFT plans.
 
int setBuffers (complexf *data, complexf *work) noexcept
 Attach data and work buffers.
 
int setBuffers (complexd *data, complexd *work) noexcept
 
int getBuffers (complexf **data, complexf **work) noexcept
 Retrieve current buffer pointers.
 
int getBuffers (complexd **data, complexd **work) noexcept
 Retrieve current buffer pointers (double precision).
 
int execute (FFTDirection direction) noexcept override
 Execute the transform.
 
int normalize () noexcept override
 Apply symmetric normalization (1/sqrt(N) per transform).
 
std::vector< size_t > globalShape () const noexcept
 Get global shape as length-1 vector.
 
size_t globalSize () const noexcept override
 Get global FFT size.
 
int ndim () const noexcept override
 Get number of dimensions (always 1).
 
FFTType fftType () const noexcept override
 Get FFT precision (C2C or Z2Z).
 
size_t localSize () const noexcept
 Get local element count (before padding).
 
size_t allocSize () const noexcept override
 Get required buffer size in complex elements.
 
int getLayout (std::vector< size_t > &localShape, std::vector< size_t > &offset, TensorLayout layout=TensorLayout::CURRENT) const noexcept
 Query local layout.
 
int getAxes (std::vector< int > &ca, std::vector< int > &da, TensorLayout layout=TensorLayout::CURRENT) const noexcept
 Query axis distribution.
 
bool isActive () const noexcept override
 Check if this rank participates in computation.
 
int setBuffersRaw (void *data, void *work) noexcept override
 Attach buffers (type-erased).
 
int getBuffersRaw (void **data, void **work) noexcept override
 Retrieve current buffer pointers (type-erased).
 
int getCommunicator (MPI_Comm *outComm) const noexcept
 Get a duplicated communicator from this plan.
 
int init (shafft_1d_config_t &cfg) noexcept
 Initialize plan from a resolved 1-D config object.
 
- Public Member Functions inherited from shafft::FFT
 operator bool () const noexcept
 Check if the plan is valid (alias for isConfigured).
 
PlanState state () const noexcept
 Get the current plan state.
 
bool isConfigured () const noexcept
 Check if the plan is at least configured (init() succeeded).
 
bool isPlanned () const noexcept
 Check if the plan is fully planned and ready for execution.
 
 FFT (const FFT &)=delete
 
FFToperator= (const FFT &)=delete
 

Detailed Description

Uses block distribution: rank r owns [localStart, localStart + localN). allocSize() may exceed localN due to padding.

Note
Typical usage flow:
  1. Call configuration1D() to compute local layout
  2. Construct FFT1D and call init() with the computed parameters
  3. Allocate buffers using allocSize() and call setBuffers()
  4. Call plan() to create backend FFT plans
  5. Call execute() for forward/backward transforms
  6. Call normalize() after a forward-backward pair to restore scale
Examples
example_FFT1D.cpp.

Constructor & Destructor Documentation

◆ FFT1D() [1/3]

shafft::FFT1D::FFT1D ( )
defaultnoexcept

◆ ~FFT1D()

shafft::FFT1D::~FFT1D ( )
overridenoexcept

◆ FFT1D() [2/3]

shafft::FFT1D::FFT1D ( FFT1D &&  other)
noexcept

Transfers ownership of backend resources from other. The moved-from plan becomes uninitialized.

Parameters
otherPlan to move from.

◆ FFT1D() [3/3]

shafft::FFT1D::FFT1D ( const FFT1D )
delete

Member Function Documentation

◆ release()

void shafft::FFT1D::release ( )
overridevirtualnoexcept

Call before MPI_Finalize() if the plan outlives MPI.

Implements shafft::FFT.

Examples
example_FFT1D.cpp.

◆ operator=() [1/2]

FFT1D & shafft::FFT1D::operator= ( FFT1D &&  other)
noexcept

Releases current resources and takes ownership from other. The moved-from plan becomes uninitialized.

Parameters
otherPlan to move from.
Returns
Reference to this plan.

◆ operator=() [2/2]

FFT1D & shafft::FFT1D::operator= ( const FFT1D )
delete

◆ init() [1/2]

int shafft::FFT1D::init ( size_t  globalN,
size_t  localN,
size_t  localStart,
FFTType  precision,
MPI_Comm  comm 
)
noexcept

Call configuration1D() first to compute layout parameters.

Parameters
globalNGlobal FFT size.
localNLocal element count for this rank.
localStartThis rank's offset in global array.
precisionFFT precision (C2C or Z2Z).
commMPI communicator.
Returns
0 on success, non-zero on error.
Examples
example_FFT1D.cpp.

◆ plan()

int shafft::FFT1D::plan ( )
overridevirtualnoexcept

Must be called after init(). For FFTW, buffers may be set later; dummy buffers are used for planning. Calling plan() more than once is an error.

Returns
0 on success, non-zero on error.

Implements shafft::FFT.

Examples
example_FFT1D.cpp.

◆ setBuffers() [1/2]

int shafft::FFT1D::setBuffers ( complexf data,
complexf work 
)
noexcept

Buffers must be allocated and have at least allocSize() elements.

Parameters
dataInput buffer (allocSize() elements).
workOutput buffer (allocSize() elements).
Returns
0 on success, non-zero on error.
Examples
example_FFT1D.cpp.

◆ setBuffers() [2/2]

int shafft::FFT1D::setBuffers ( complexd data,
complexd work 
)
noexcept

◆ getBuffers() [1/2]

int shafft::FFT1D::getBuffers ( complexf **  data,
complexf **  work 
)
noexcept
Parameters
[out]dataCurrent data buffer.
[out]workCurrent work buffer.
Returns
0 on success, non-zero on error.
Examples
example_FFT1D.cpp.

◆ getBuffers() [2/2]

int shafft::FFT1D::getBuffers ( complexd **  data,
complexd **  work 
)
noexcept
Parameters
[out]dataCurrent data buffer.
[out]workCurrent work buffer.
Returns
0 on success, non-zero on error.

◆ execute()

int shafft::FFT1D::execute ( FFTDirection  direction)
overridevirtualnoexcept
Parameters
directionFORWARD or BACKWARD.
Returns
0 on success, non-zero on error.

Implements shafft::FFT.

Examples
example_FFT1D.cpp.

◆ normalize()

int shafft::FFT1D::normalize ( )
overridevirtualnoexcept

After a forward-backward pair, calling normalize() restores original scale.

Returns
0 on success, non-zero on error.

Implements shafft::FFT.

Examples
example_FFT1D.cpp.

◆ globalShape()

std::vector< size_t > shafft::FFT1D::globalShape ( ) const
noexcept

◆ globalSize()

size_t shafft::FFT1D::globalSize ( ) const
overridevirtualnoexcept

Implements shafft::FFT.

◆ ndim()

int shafft::FFT1D::ndim ( ) const
overridevirtualnoexcept

Implements shafft::FFT.

◆ fftType()

FFTType shafft::FFT1D::fftType ( ) const
overridevirtualnoexcept

Implements shafft::FFT.

◆ localSize()

size_t shafft::FFT1D::localSize ( ) const
noexcept

◆ allocSize()

size_t shafft::FFT1D::allocSize ( ) const
overridevirtualnoexcept

May exceed localSize() due to padding.

Implements shafft::FFT.

Examples
example_FFT1D.cpp.

◆ getLayout()

int shafft::FFT1D::getLayout ( std::vector< size_t > &  localShape,
std::vector< size_t > &  offset,
TensorLayout  layout = TensorLayout::CURRENT 
) const
noexcept
Parameters
[out]localShapeLocal size as length-1 vector.
[out]offsetLocal offset as length-1 vector.
layoutCURRENT, INITIAL, or REDISTRIBUTED.
Returns
0 on success, non-zero on error.

◆ getAxes()

int shafft::FFT1D::getAxes ( std::vector< int > &  ca,
std::vector< int > &  da,
TensorLayout  layout = TensorLayout::CURRENT 
) const
noexcept

Returns ca={} and da={0} (the single axis is distributed).

Parameters
[out]caContiguous axes (empty).
[out]daDistributed axes ({0}).
layoutCURRENT, INITIAL, or REDISTRIBUTED.
Returns
0 on success, non-zero on error.

◆ isActive()

bool shafft::FFT1D::isActive ( ) const
overridevirtualnoexcept

Implements shafft::FFT.

◆ setBuffersRaw()

int shafft::FFT1D::setBuffersRaw ( void *  data,
void *  work 
)
overridevirtualnoexcept
Parameters
dataData buffer.
workWork buffer.
Returns
0 on success, non-zero on error.

Implements shafft::FFT.

◆ getBuffersRaw()

int shafft::FFT1D::getBuffersRaw ( void **  data,
void **  work 
)
overridevirtualnoexcept
Parameters
[out]dataCurrent data buffer.
[out]workCurrent work buffer.
Returns
0 on success, non-zero on error.

Implements shafft::FFT.

◆ getCommunicator()

int shafft::FFT1D::getCommunicator ( MPI_Comm *  outComm) const
noexcept

Returns MPI_COMM_NULL for inactive ranks. The caller must call MPI_Comm_free() on the returned communicator when done.

Parameters
[out]outCommReceives duplicated communicator.
Returns
0 on success, non-zero on error.

◆ init() [2/2]

int shafft::FFT1D::init ( shafft_1d_config_t cfg)
noexcept

Auto-resolves if SHAFFT_CONFIG_RESOLVED is not set. Communicator is read from the config struct (worldComm).

Parameters
cfgConfig struct (resolved or will be auto-resolved).
Returns
0 on success, non-zero on error.

The documentation for this class was generated from the following file: