STARS-H
Software for Testing Accuracy, Reliability and Scalability of Hierarchical computations

Template for particle-to-particle interactions. More...

Collaboration diagram for N-body:

Data Structures

struct  starsh_particles
 Structure for general N-body problems. More...
 

Typedefs

typedef struct starsh_particles STARSH_particles
 Structure for general N-body problems.
 

Enumerations

enum  STARSH_PARTICLES_PLACEMENT {
  STARSH_PARTICLES_RAND = 1, STARSH_PARTICLES_UNIFORM = 3, STARSH_PARTICLES_RANDGRID = 4, STARSH_PARTICLES_QUASIUNIFORM1 = 6,
  STARSH_PARTICLES_QUASIUNIFORM2 = 7, STARSH_PARTICLES_OBSOLETE1 = -1, STARSH_PARTICLES_OBSOLETE2 = -2, STARSH_PARTICLES_OBSOLETE3 = -3,
  STARSH_PARTICLES_OBSOLETE4 = -4
}
 Distribution of particles for starsh_particles_generate(). More...
 

Functions

int starsh_particles_new (STARSH_particles **data, STARSH_int count, int ndim)
 Allocate memory for STARSH_particles object. More...
 
int starsh_particles_init (STARSH_particles **data, STARSH_int count, int ndim, double *point)
 Initialize STARSH_particles object by given data. More...
 
void starsh_particles_free (STARSH_particles *data)
 Free memory of STARSH_particles object. More...
 
int starsh_particles_generate (STARSH_particles **data, STARSH_int count, int ndim, enum STARSH_PARTICLES_PLACEMENT ptype)
 Generate STARSH_particles with required distribution. More...
 
int starsh_particles_generate_rand (STARSH_particles **data, STARSH_int count, int ndim)
 Generate particles with [0,1] uniform random distribution. More...
 
int starsh_particles_generate_randgrid (STARSH_particles **data, STARSH_int count, int ndim)
 Generate a grid on randomly distributed grid coordinates. More...
 
int starsh_particles_generate_uniform (STARSH_particles **data, STARSH_int count, int ndim)
 Generate a uniform grid of particles. More...
 
int starsh_particles_generate_quasiuniform1 (STARSH_particles **data, STARSH_int count, int ndim)
 Generate a uniform grid of particles with random shift of each particle. More...
 
int starsh_particles_generate_quasiuniform2 (STARSH_particles **data, STARSH_int count, int ndim)
 Generate a uniform grid of particles with random shift of grid coordinates. More...
 
int starsh_particles_generate_obsolete1 (STARSH_particles **data, STARSH_int count, int ndim)
 Generate a uniform grid of particles with random shift of each particle. More...
 
int starsh_particles_generate_obsolete2 (STARSH_particles **data, STARSH_int count, int ndim)
 Generate a uniform grid of particles with random shift of grid coordinates. More...
 
int starsh_particles_generate_obsolete3 (STARSH_particles **data, STARSH_int count, int ndim)
 Generate a uniform grid of particles with random shift of each particle. More...
 
int starsh_particles_generate_obsolete4 (STARSH_particles **data, STARSH_int count, int ndim)
 Generate a uniform grid of particles with random shift of each particle. More...
 
int starsh_particles_read_from_file (STARSH_particles **data, const char *fname, const enum STARSH_FILE_TYPE ftype)
 Read STARSH_particles object from file. More...
 
int starsh_particles_read_from_file_pointer (STARSH_particles **data, FILE *fp, const enum STARSH_FILE_TYPE ftype)
 Read STARSH_particles object from file pointer. More...
 
int starsh_particles_read_from_file_pointer_ascii (STARSH_particles **data, FILE *fp)
 Read STARSH_particles object from file pointer in ASCII format. More...
 
int starsh_particles_read_from_file_pointer_binary (STARSH_particles **data, FILE *fp)
 Read STARSH_particles object from file pointer in binary format. More...
 
int starsh_particles_write_to_file (const STARSH_particles *data, const char *fname, const enum STARSH_FILE_TYPE ftype)
 Write STARSH_particles object to file. More...
 
int starsh_particles_write_to_file_pointer (const STARSH_particles *data, FILE *fp, const enum STARSH_FILE_TYPE ftype)
 Write STARSH_particles object to file pointer. More...
 
int starsh_particles_write_to_file_pointer_ascii (const STARSH_particles *data, FILE *fp)
 Write STARSH_particles object to file pointer in ASCII format. More...
 
int starsh_particles_write_to_file_pointer_binary (const STARSH_particles *data, FILE *fp)
 Write STARSH_particles object to file pointer in binary format. More...
 
int starsh_particles_zsort_inplace (STARSH_particles *data)
 Sort particles in Z-order (Morton order). More...
 

Detailed Description

Template for particle-to-particle interactions.

STARSH_particles holds all the necessary data, which can be generated in different ways by starsh_particles_generate(), read from file by starsh_particles_read_from_file(), set as needed after allocating memory by starsh_particles_new() or set by given coordinates by starsh_particles_init().

Enumeration Type Documentation

◆ STARSH_PARTICLES_PLACEMENT

Distribution of particles for starsh_particles_generate().

Enumerator
STARSH_PARTICLES_RAND 

Uniform random distribution in [0,1] range.

STARSH_PARTICLES_UNIFORM 

Uniform in [0,1] grid.

STARSH_PARTICLES_RANDGRID 

Grid, based on uniform in [0,1] distribution of coordinates.

STARSH_PARTICLES_QUASIUNIFORM1 

Uniform in [0,1] grid, but each particle is slightly shifted.

STARSH_PARTICLES_QUASIUNIFORM2 

Uniform in [0,1] grid, but each grid coordinate is slightly shifted.

STARSH_PARTICLES_OBSOLETE1 

Old version of STARSH_PARTICLES_QUASIUNIFORM1 (for compatibility).

STARSH_PARTICLES_OBSOLETE2 

Old version of STARSH_PARTICLES_QUASIUNIFORM2 (for compatibility).

STARSH_PARTICLES_OBSOLETE3 

Uniform in [0,1] grid, but each grid coordinate is slightly shifted.

STARSH_PARTICLES_OBSOLETE4 

Uniform in [0,1] grid, but each grid coordinate is slightly shifted.

Function Documentation

◆ starsh_particles_free()

void starsh_particles_free ( STARSH_particles data)

◆ starsh_particles_generate()

int starsh_particles_generate ( STARSH_particles **  data,
STARSH_int  count,
int  ndim,
enum STARSH_PARTICLES_PLACEMENT  ptype 
)

Generate STARSH_particles with required distribution.

Parameters
[out]dataAddress of pointer to STARSH_particles object.
[in]countAmount of particles to generate.
[in]ndimDimensionality of space.
[in]ptypeHow to place particles. For more info look at STARSH_PARTICLES_PLACEMENT.
Returns
Error code STARSH_ERRNO.
See also
starsh_particles_generate_rand(), starsh_particles_generate_uniform(), starsh_particles_generate_randgrid(), starsh_particles_generate_quasiuniform1(), starsh_particles_generate_quasiuniform2(), starsh_particles_generate_obsolete1(), starsh_particles_generate_obsolete2().

◆ starsh_particles_generate_obsolete1()

int starsh_particles_generate_obsolete1 ( STARSH_particles **  data,
STARSH_int  count,
int  ndim 
)

Generate a uniform grid of particles with random shift of each particle.

Similar to starsh_particles_generate_quasiuniform1(), but works only for 1D, 2D and 3D. Parameter count must be square of integer if ndim=2 and cube if integer if ndim=3.

Parameters
[out]dataAddress of pointer to STARSH_particles object.
[in]countAmount of particles to generate.
[in]ndimDimensionality of space.
Returns
Error code STARSH_ERRNO.
See also
starsh_particles_generate(), starsh_particles_generate_quasiuniform1().

◆ starsh_particles_generate_obsolete2()

int starsh_particles_generate_obsolete2 ( STARSH_particles **  data,
STARSH_int  count,
int  ndim 
)

Generate a uniform grid of particles with random shift of grid coordinates.

Similar to starsh_particles_generate_quasiuniform2(), but works only for 1D, 2D and 3D. Parameter count must be square of integer if ndim=2 and cube if integer if ndim=3.

Parameters
[out]dataAddress of pointer to STARSH_particles object.
[in]countAmount of particles to generate.
[in]ndimDimensionality of space.
Returns
Error code STARSH_ERRNO.
See also
starsh_particles_generate(), starsh_particles_generate_quasiuniform2().

◆ starsh_particles_generate_obsolete3()

int starsh_particles_generate_obsolete3 ( STARSH_particles **  data,
STARSH_int  count,
int  ndim 
)

Generate a uniform grid of particles with random shift of each particle.

Similar to starsh_particles_generate_quasiuniform1(), but works only for 1D, 2D and 3D. Number of locations count/2 must be square of integer if ndim=2 and cube if integer ifndim`=3.

Parameters
[out]dataAddress of pointer to STARSH_particles object.
[in]countAmount of particles to generate.
[in]ndimDimensionality of space.
Returns
Error code STARSH_ERRNO.
See also
starsh_particles_generate(), starsh_particles_generate_quasiuniform1().

◆ starsh_particles_generate_obsolete4()

int starsh_particles_generate_obsolete4 ( STARSH_particles **  data,
STARSH_int  count,
int  ndim 
)

Generate a uniform grid of particles with random shift of each particle.

Similar to starsh_particles_generate_quasiuniform1(), but works only for 1D, 2D and 3D. Number of locations count/2 must be square of integer if ndim=2 and cube if integer if ndim=3.

Parameters
[out]dataAddress of pointer to STARSH_particles object.
[in]countAmount of particles to generate.
[in]ndimDimensionality of space.
Returns
Error code STARSH_ERRNO.
See also
starsh_particles_generate(), starsh_particles_generate_quasiuniform1().

◆ starsh_particles_generate_quasiuniform1()

int starsh_particles_generate_quasiuniform1 ( STARSH_particles **  data,
STARSH_int  count,
int  ndim 
)

Generate a uniform grid of particles with random shift of each particle.

Minimal grid, containing all of count particles, is selected.

Parameters
[out]dataAddress of pointer to STARSH_particles object.
[in]countAmount of particles to generate.
[in]ndimDimensionality of space.
Returns
Error code STARSH_ERRNO.
See also
starsh_particles_generate().

◆ starsh_particles_generate_quasiuniform2()

int starsh_particles_generate_quasiuniform2 ( STARSH_particles **  data,
STARSH_int  count,
int  ndim 
)

Generate a uniform grid of particles with random shift of grid coordinates.

Minimal grid, containing all of count particles, is selected.

Parameters
[out]dataAddress of pointer to STARSH_particles object.
[in]countAmount of particles to generate.
[in]ndimDimensionality of space.
Returns
Error code STARSH_ERRNO.
See also
starsh_particles_generate().

◆ starsh_particles_generate_rand()

int starsh_particles_generate_rand ( STARSH_particles **  data,
STARSH_int  count,
int  ndim 
)

Generate particles with [0,1] uniform random distribution.

Parameters
[out]dataAddress of pointer to STARSH_particles object.
[in]countAmount of particles to generate.
[in]ndimDimensionality of space.
Returns
Error code STARSH_ERRNO.
See also
starsh_particles_generate().

◆ starsh_particles_generate_randgrid()

int starsh_particles_generate_randgrid ( STARSH_particles **  data,
STARSH_int  count,
int  ndim 
)

Generate a grid on randomly distributed grid coordinates.

Minimal grid, containing all count particles, is selected.

Parameters
[out]dataAddress of pointer to STARSH_particles object.
[in]countAmount of particles to generate.
[in]ndimDimensionality of space.
Returns
Error code STARSH_ERRNO.
See also
starsh_particles_generate().

◆ starsh_particles_generate_uniform()

int starsh_particles_generate_uniform ( STARSH_particles **  data,
STARSH_int  count,
int  ndim 
)

Generate a uniform grid of particles.

Minimal grid, containing all of count particles, is selected.

Parameters
[out]dataAddress of pointer to STARSH_particles object.
[in]countAmount of particles to generate.
[in]ndimDimensionality of space.
Returns
Error code STARSH_ERRNO.
See also
starsh_particles_generate().

◆ starsh_particles_init()

int starsh_particles_init ( STARSH_particles **  data,
STARSH_int  count,
int  ndim,
double *  point 
)

Initialize STARSH_particles object by given data.

Array point should be stored in a special way: x_1 x_2 ... x_count y_1 y_2 ... y_count z_1 z_2 .... This function does not allocate memory for coordinates and uses provided pointer point. Do not free memory of point until you finish using returned STARSH_particles object. Do not forget to sort particles by starsh_particles_zsort_inplace() to take advantage of low-rank submatrices.

Parameters
[out]dataAddress of pointer to STARSH_particles object.
[in]countNumber of particles.
[in]ndimDimensionality of space.
[in]pointPointer to array of coordinates of particles.
Returns
Error code STARSH_ERRNO.
See also
starsh_particles_new(), starsh_particles_free(), starsh_particles_generate(), starsh_particles_read_from_file(), starsh_particles_zsort_inplace().

◆ starsh_particles_new()

int starsh_particles_new ( STARSH_particles **  data,
STARSH_int  count,
int  ndim 
)

Allocate memory for STARSH_particles object.

Array (*data)->point is stored in a special way: x_1 x_2 ... x_count y_1 y_2 ... y_count z_1 z_2 .... This functions only allocates memory for particles without setting coordinates to any value. Do not forget to sort particles by starsh_particles_zsort_inplace() to take advantage of low-rank submatrices.

Parameters
[out]dataAddress of pointer to STARSH_particles object.
[in]countNumber of particles.
[in]ndimDimensionality of space.
Returns
Error code STARSH_ERRNO.
See also
starsh_particles_init(), starsh_particles_free(), starsh_particles_generate(), starsh_particles_read_from_file(), starsh_particles_zsort_inplace().

◆ starsh_particles_read_from_file()

int starsh_particles_read_from_file ( STARSH_particles **  data,
const char *  fname,
const enum STARSH_FILE_TYPE  ftype 
)

Read STARSH_particles object from file.

Parameters
[out]dataAddress to pointer to STARSH_particles object.
[in]fnameName of file to read from.
[in]ftypeFile type. Look at STARSH_FILE_TYPE for more info.
Returns
Error code STARSH_ERRNO.
See also
starsh_particles_read_from_file_pointer(), starsh_particles_read_from_file_pointer_ascii(), starsh_particles_read_from_file_pointer_binary(), starsh_particles_write_to_file().

◆ starsh_particles_read_from_file_pointer()

int starsh_particles_read_from_file_pointer ( STARSH_particles **  data,
FILE *  fp,
const enum STARSH_FILE_TYPE  ftype 
)

Read STARSH_particles object from file pointer.

After finishing, file pointer fp will still be open.

Parameters
[out]dataAddress of pointer to STARSH_particles object.
[in]fpFile pointer to read from, must be open before reading.
[in]ftypeFile type. Look at STARSH_FILE_TYPE for more info.
Returns
Error code STARSH_ERRNO.
See also
starsh_particles_read_from_file(), starsh_particles_read_from_file_pointer_ascii(), starsh_particles_read_from_file_pointer_binary(), starsh_particles_write_to_file().

◆ starsh_particles_read_from_file_pointer_ascii()

int starsh_particles_read_from_file_pointer_ascii ( STARSH_particles **  data,
FILE *  fp 
)

Read STARSH_particles object from file pointer in ASCII format.

After finishing, file pointer fp will still be open.

Parameters
[out]dataAddress of pointer to STARSH_particles object.
[in]fpFile pointer to read from, must be open before reading.
Returns
Error code STARSH_ERRNO.
See also
starsh_particles_read_from_file(), starsh_particles_read_from_file_pointer(), starsh_particles_read_from_file_pointer_binary(), starsh_particles_write_to_file().

◆ starsh_particles_read_from_file_pointer_binary()

int starsh_particles_read_from_file_pointer_binary ( STARSH_particles **  data,
FILE *  fp 
)

Read STARSH_particles object from file pointer in binary format.

After finishing, file pointer fp will still be open.

Parameters
[out]dataAddress of pointer to STARSH_particles object.
[in]fpFile pointer to read from, must be open before reading.
Returns
Error code STARSH_ERRNO.
See also
starsh_particles_read_from_file(), starsh_particles_read_from_file_pointer(), starsh_particles_read_from_file_pointer_ascii(), starsh_particles_write_to_file().

◆ starsh_particles_write_to_file()

int starsh_particles_write_to_file ( const STARSH_particles data,
const char *  fname,
const enum STARSH_FILE_TYPE  ftype 
)

Write STARSH_particles object to file.

Parameters
[out]dataPointer to STARSH_particles object.
[in]fnameName of file to write to.
[in]ftypeFile type. Look at STARSH_FILE_TYPE for more info.
Returns
Error code STARSH_ERRNO.
See also
starsh_particles_write_to_file_pointer(), starsh_particles_write_to_file_pointer_ascii(), starsh_particles_write_to_file_pointer_binary(), starsh_particles_read_from_file().

◆ starsh_particles_write_to_file_pointer()

int starsh_particles_write_to_file_pointer ( const STARSH_particles data,
FILE *  fp,
const enum STARSH_FILE_TYPE  ftype 
)

Write STARSH_particles object to file pointer.

After finishing, file pointer fp will still be open.

Parameters
[out]dataPointer to STARSH_particles object.
[in]fpFile pointer to write to, must be open before writing.
[in]ftypeFile type. Look at STARSH_FILE_TYPE for more info.
Returns
Error code STARSH_ERRNO.
See also
starsh_particles_write_to_file(), starsh_particles_write_to_file_pointer_ascii(), starsh_particles_write_to_file_pointer_binary(), starsh_particles_read_from_file().

◆ starsh_particles_write_to_file_pointer_ascii()

int starsh_particles_write_to_file_pointer_ascii ( const STARSH_particles data,
FILE *  fp 
)

Write STARSH_particles object to file pointer in ASCII format.

After finishing, file pointer fp will still be open.

Parameters
[out]dataPointer to STARSH_particles object.
[in]fpFile pointer to write to, must be open before writing.
Returns
Error code STARSH_ERRNO.
See also
starsh_particles_write_to_file(), starsh_particles_write_to_file_pointer(), starsh_particles_write_to_file_pointer_binary(), starsh_particles_read_from_file().

◆ starsh_particles_write_to_file_pointer_binary()

int starsh_particles_write_to_file_pointer_binary ( const STARSH_particles data,
FILE *  fp 
)

Write STARSH_particles object to file pointer in binary format.

After finishing, file pointer fp will still be open.

Parameters
[out]dataPointer to STARSH_particles object.
[in]fpFile pointer to write to, must be open before writing.
Returns
Error code STARSH_ERRNO.
See also
starsh_particles_write_to_file(), starsh_particles_write_to_file_pointer(), starsh_particles_write_to_file_pointer_ascii(), starsh_particles_read_from_file().

◆ starsh_particles_zsort_inplace()

int starsh_particles_zsort_inplace ( STARSH_particles data)

Sort particles in Z-order (Morton order).

This function must be used after initializing STARSH_particles with your own data by starsh_particles_init() or starsh_particles_new().

See also
starsh_particles_init(), starsh_particles_new().