ESPResSo 3.2.0-11-g9950804-git
Extensible Simulation Package for Soft Matter Research
Functions
fft-common.c File Reference

Routines, row decomposition, data structures and communication for the 3D-FFT. More...

#include "fft-common.h"
#include <string.h>
#include <fftw3.h>
#include <mpi.h>
#include "utils.h"
#include "communication.h"
Include dependency graph for fft-common.c:

Go to the source code of this file.

Functions

void fft_common_pre_init (fft_data_struct *fft)
 Initialize FFT data structure.
void fft_pack_block (double *in, double *out, int start[3], int size[3], int dim[3], int element)
 pack a block (size[3] starting at start[3]) of an input 3d-grid with dimension dim[3] into an output 3d-block with dimension size[3].
void fft_pack_block_permute1 (double *in, double *out, int start[3], int size[3], int dim[3], int element)
 pack a block with dimensions (size[0] * size[1] * aize[2]) starting at start[3] of an input 3d-grid with dimension dim[3] into an output 3d-grid with dimensions (size[2] * size[0] * size[1]) with a simulatanous one-fold permutation of the indices.
void fft_pack_block_permute2 (double *in, double *out, int start[3], int size[3], int dim[3], int element)
 pack a block with dimensions (size[0] * size[1] * aize[2]) starting at start[3] of an input 3d-grid with dimension dim[3] into an output 3d-grid with dimensions (size[2] * size[0] * size[1]), this is a simulatanous two-fold permutation of the indices.
void fft_unpack_block (double *in, double *out, int start[3], int size[3], int dim[3], int element)
 unpack a 3d-grid input block (size[3]) into an output 3d-grid with dimension dim[3] at start position start[3].
int fft_find_comm_groups (int grid1[3], int grid2[3], int *node_list1, int *node_list2, int *group, int *pos, int *my_pos)
 This ugly function does the bookkepping which nodes have to communicate to each other, when you change the node grid.
int fft_calc_local_mesh (int n_pos[3], int n_grid[3], int mesh[3], double mesh_off[3], int loc_mesh[3], int start[3])
 Calculate the local fft mesh.
int fft_calc_send_block (int pos1[3], int grid1[3], int pos2[3], int grid2[3], int mesh[3], double mesh_off[3], int block[6])
 Calculate a send (or recv.) block for grid communication during a decomposition change.
void fft_print_fft_plan (fft_forw_plan pl)
 Debug function to print fft_forw_plan structure.
void fft_print_global_fft_mesh (fft_forw_plan plan, double *data, int element, int num)
 Debug function to print global fft mesh.

Detailed Description

Routines, row decomposition, data structures and communication for the 3D-FFT.

Definition in file fft-common.c.


Function Documentation

int fft_calc_local_mesh ( int  n_pos[3],
int  n_grid[3],
int  mesh[3],
double  mesh_off[3],
int  loc_mesh[3],
int  start[3] 
)

Calculate the local fft mesh.

Calculate the local mesh (loc_mesh) of a node at position (n_pos) in a node grid (n_grid) for a global mesh of size (mesh) and a mesh offset (mesh_off (in mesh units)) and store also the first point (start) of the local mesh.

Returns:
size number of mesh points in local mesh.
Parameters:
n_posPosition of the node in n_grid.
n_gridnode grid.
meshglobal mesh dimensions.
mesh_offglobal mesh offset (see p3m_data_struct).
loc_meshlocal mesh dimension (output).
startfirst point of local mesh in global mesh (output).

Definition at line 266 of file fft-common.c.

References i.

Referenced by dfft_init(), fft_calc_send_block(), and fft_init().

int fft_calc_send_block ( int  pos1[3],
int  grid1[3],
int  pos2[3],
int  grid2[3],
int  mesh[3],
double  mesh_off[3],
int  block[6] 
)

Calculate a send (or recv.) block for grid communication during a decomposition change.

Calculate the send block specification (block = lower left corner and upper right corner) which a node at position (pos1) in the actual node grid (grid1) has to send to another node at position (pos2) in the desired node grid (grid2). The global mesh, subject to communication, is specified via its size (mesh) and its mesh offset (mesh_off (in mesh units)).

For the calculation of a receive block you have to change the arguments in the following way:
pos1 - position of receiving node in the desired node grid.
grid1 - desired node grid.
pos2 - position of the node you intend to receive the data from in the actual node grid.
grid2 - actual node grid.

Returns:
size of the send block.
Parameters:
pos1Position of send node in grid1.
grid1node grid 1.
pos2Position of recv node in grid2.
grid2node grid 2.
meshglobal mesh dimensions.
mesh_offglobal mesh offset (see p3m_data_struct).
blocksend block specification.

Definition at line 284 of file fft-common.c.

References fft_calc_local_mesh(), i, imax(), and imin().

Referenced by dfft_init(), and fft_init().

void fft_common_pre_init ( fft_data_struct fft)
int fft_find_comm_groups ( int  grid1[3],
int  grid2[3],
int *  node_list1,
int *  node_list2,
int *  group,
int *  pos,
int *  my_pos 
)

This ugly function does the bookkepping which nodes have to communicate to each other, when you change the node grid.

Changing the domain decomposition requieres communication. This function finds (hopefully) the best way to do this. As input it needs the two grids (grid1, grid2) and a linear list (node_list1) with the node identities for grid1. The linear list (node_list2) for the second grid is calculated. For the communication group of the calling node it calculates a list (group) with the node identities and the positions (pos1, pos2) of that nodes in grid1 and grid2. The return value is the size of the communication group. It gives -1 if the two grids do not fit to each other (grid1 and grid2 have to be component wise multiples of each other. see e.g. calc_2d_grid in grid.c for how to do this.).

Parameters:
grid1The node grid you start with (Input).
grid2The node grid you want to have (Input).
node_list1Linear node index list for grid1 (Input).
node_list2Linear node index list for grid2 (Output).
groupcommunication group (node identity list) for the calling node (Output).
pospositions of the nodes in in grid2 (Output).
my_posposition of this_node in grid2.
Returns:
Size of the communication group (Output of course!).

Definition at line 185 of file fft-common.c.

References FFT_TRACE, get_linear_index(), i, and this_node.

Referenced by dfft_init(), and fft_init().

void fft_pack_block ( double *  in,
double *  out,
int  start[3],
int  size[3],
int  dim[3],
int  element 
)

pack a block (size[3] starting at start[3]) of an input 3d-grid with dimension dim[3] into an output 3d-block with dimension size[3].

The block with dimensions (size[0], size[1], size[2]) is stored in 'row-major-order' or 'C-order', that means the first index is changing slowest when running through the linear array. The element (i0 (slow), i1 (mid), i2 (fast)) has the linear index li = i2 + size[2] * (i1 + (size[1]*i0))

Parameters:
inpointer to input 3d-grid.
outpointer to output 3d-grid (block).
startstart index of the block in the in-grid.
sizesize of the block (=dimension of the out-grid).
dimsize of the in-grid.
elementsize of a grid element (e.g. 1 for Real, 2 for Complex).

Definition at line 56 of file fft-common.c.

Referenced by dfft_init(), dp3m_gather_fft_grid(), dp3m_spread_force_grid(), fft_init(), p3m_gather_fft_grid(), and p3m_spread_force_grid().

void fft_pack_block_permute1 ( double *  in,
double *  out,
int  start[3],
int  size[3],
int  dim[3],
int  element 
)

pack a block with dimensions (size[0] * size[1] * aize[2]) starting at start[3] of an input 3d-grid with dimension dim[3] into an output 3d-grid with dimensions (size[2] * size[0] * size[1]) with a simulatanous one-fold permutation of the indices.

The permutation is defined as: slow_in -> fast_out, mid_in ->slow_out, fast_in -> mid_out

An element (i0_in , i1_in , i2_in ) is then (i0_out = i1_in-start[1], i1_out = i2_in-start[2], i2_out = i0_in-start[0]) and for the linear indices we have:
li_in = i2_in + size[2] * (i1_in + (size[1]*i0_in))
li_out = i2_out + size[0] * (i1_out + (size[2]*i0_out))

For index definition see fft_pack_block.

Parameters:
inpointer to input 3d-grid.
outpointer to output 3d-grid (block).
startstart index of the block in the in-grid.
sizesize of the block (=dimension of the out-grid).
dimsize of the in-grid.
elementsize of a grid element (e.g. 1 for Real, 2 for Complex).

Definition at line 85 of file fft-common.c.

References element.

Referenced by dfft_init(), and fft_init().

void fft_pack_block_permute2 ( double *  in,
double *  out,
int  start[3],
int  size[3],
int  dim[3],
int  element 
)

pack a block with dimensions (size[0] * size[1] * aize[2]) starting at start[3] of an input 3d-grid with dimension dim[3] into an output 3d-grid with dimensions (size[2] * size[0] * size[1]), this is a simulatanous two-fold permutation of the indices.

The permutation is defined as: slow_in -> mid_out, mid_in ->fast_out, fast_in -> slow_out

An element (i0_in , i1_in , i2_in ) is then (i0_out = i2_in-start[2], i1_out = i0_in-start[0], i2_out = i1_in-start[1]) and for the linear indices we have:
li_in = i2_in + size[2] * (i1_in + (size[1]*i0_in))
li_out = i2_out + size[0] * (i1_out + (size[2]*i0_out))

For index definition see fft_pack_block.

Parameters:
inpointer to input 3d-grid.
outpointer to output 3d-grid (block).
startstart index of the block in the in-grid.
sizesize of the block (=dimension of the out-grid).
dimsize of the in-grid.
elementsize of a grid element (e.g. 1 for Real, 2 for Complex).

Definition at line 116 of file fft-common.c.

References element.

Referenced by dfft_init(), and fft_init().

void fft_print_fft_plan ( fft_forw_plan  pl)
void fft_print_global_fft_mesh ( fft_forw_plan  plan,
double *  data,
int  element,
int  num 
)

Debug function to print global fft mesh.

Print a globaly distributed mesh contained in data. Element size is element.

Parameters:
planfft/communication plan (see fft_forw_plan).
datamesh data.
elementelement size.
numelement index to print.

Definition at line 333 of file fft-common.c.

References comm_cart, imin(), MPI_Barrier(), n_nodes, fft_forw_plan::new_mesh, fft_forw_plan::start, and this_node.

void fft_unpack_block ( double *  in,
double *  out,
int  start[3],
int  size[3],
int  dim[3],
int  element 
)

unpack a 3d-grid input block (size[3]) into an output 3d-grid with dimension dim[3] at start position start[3].

see also fft_pack_block.

Parameters:
inpointer to input 3d-grid.
outpointer to output 3d-grid (block).
startstart index of the block in the in-grid.
sizesize of the block (=dimension of the out-grid).
dimsize of the in-grid.
elementsize of a grid element (e.g. 1 for Real, 2 for Complex).

Definition at line 150 of file fft-common.c.

Referenced by dfft_back_grid_comm(), dfft_forw_grid_comm(), dp3m_spread_force_grid(), fft_back_grid_comm(), fft_forw_grid_comm(), and p3m_spread_force_grid().