![]() |
GHOST
1.1.2
General, Hybrid, and Optimized Sparse Toolkit
|
#include "config.h"
#include "types.h"
#include "bitmap.h"
#include "bindensemat.h"
#include "context.h"
Go to the source code of this file.
Classes | |
struct | ghost_densemat_halo_comm |
Densemat halo exchange communication data structure. More... | |
struct | ghost_densemat_traits |
Traits of the densemat. More... | |
struct | ghost_densemat |
A dense vector/matrix. More... | |
Macros | |
#define | GHOST_CM_IDX 0 |
#define | GHOST_RM_IDX 1 |
#define | GHOST_DENSEMAT_CHECK_SIMILARITY(vec1, vec2) |
#define | GHOST_DENSEMAT_SCATTERED (GHOST_DENSEMAT_SCATTERED_LD|GHOST_DENSEMAT_SCATTERED_TR) |
#define | DM_NROWS(dm) dm->map->dim |
#define | DM_GNROWS(dm) dm->map->gdim |
#define | DM_NROWSPAD(dm) dm->map->dimpad |
Typedefs | |
typedef int(* | ghost_densemat_srcfunc )(ghost_gidx row, ghost_lidx col, void *val, void *arg) |
Callback function to construct a ghost_densemat. More... | |
typedef struct ghost_densemat | ghost_densemat |
Enumerations | |
enum | ghost_densemat_flags { GHOST_DENSEMAT_DEFAULT = 0, GHOST_DENSEMAT_VIEW = 1<<0, GHOST_DENSEMAT_SCATTERED_LD = 1<<1, GHOST_DENSEMAT_SCATTERED_TR = 1<<2, GHOST_DENSEMAT_PERMUTED = 1<<3, GHOST_DENSEMAT_NOT_RELOCATE = 1<<4, GHOST_DENSEMAT_PAD_COLS = 1<<5 } |
Flags to configure a densemat. More... | |
enum | ghost_densemat_storage { GHOST_DENSEMAT_ROWMAJOR = GHOST_BINDENSEMAT_ORDER_ROW_FIRST, GHOST_DENSEMAT_COLMAJOR = GHOST_BINDENSEMAT_ORDER_COL_FIRST, GHOST_DENSEMAT_STORAGE_DEFAULT = 2 } |
Densemat storage orders. More... | |
Functions | |
ghost_error | ghost_densemat_create (ghost_densemat **vec, ghost_map *map, ghost_densemat_traits traits) |
Create a dense matrix/vector. More... | |
ghost_error | ghost_densemat_mask2charfield (ghost_bitmap mask, ghost_lidx len, char *charfield) |
Create an array of chars ('0' or '1') of the densemat mask. More... | |
bool | array_strictly_ascending (ghost_lidx *coffs, ghost_lidx nc) |
Check if an array consists of strictly ascending numbers. More... | |
ghost_error | ghost_densemat_uniformstorage (bool *uniform, ghost_densemat *vec, ghost_mpi_comm mpicomm) |
Check if a densemat has the same storage order on all processes of a given communicator. More... | |
char * | ghost_densemat_storage_string (ghost_densemat_storage storage) |
Get a string about the storage order. More... | |
ghost_error | ghost_densemat_info_string (char **str, ghost_densemat *densemat) |
Get a string containing information about the densemat. More... | |
ghost_error | ghost_densemat_halocommInit_common (ghost_densemat *vec, ghost_context *ctx, ghost_densemat_halo_comm *comm) |
Common (storage-independent) functions for ghost_densemat::halocommInit() More... | |
ghost_error | ghost_densemat_halocomm_start (ghost_densemat *vec, ghost_context *ctx, ghost_densemat_halo_comm *comm) |
Start halo communication asynchronously. More... | |
ghost_error | ghost_densemat_halocommFinalize_common (ghost_densemat_halo_comm *comm) |
Common (storage-independent) functions for ghost_densemat::halocommFinalize() More... | |
void | ghost_densemat_destroy (ghost_densemat *vec) |
Destroys a densemat, i.e., frees all its data structures. More... | |
ghost_lidx | ghost_densemat_row_padding () |
Determine the number of padded rows. More... | |
int | ghost_idx_of_densemat_storage (ghost_densemat_storage s) |
Translates a ghost_densemat_storage into an consectuive index. More... | |
ghost_error | ghost_densemat_init_rand (ghost_densemat *x) |
Initializes a densemat from random values. More... | |
ghost_error | ghost_densemat_init_val (ghost_densemat *x, void *v) |
Initializes a densemat from a scalar value. More... | |
ghost_error | ghost_densemat_malloc (ghost_densemat *x, int *needInit) |
Allocate sparse for a densemat. More... | |
ghost_error | ghost_densemat_init_func (ghost_densemat *x, ghost_densemat_srcfunc func, void *arg) |
Initializes a densemat from a given callback function. More... | |
ghost_error | ghost_densemat_init_densemat (ghost_densemat *x, ghost_densemat *y, ghost_lidx roffs, ghost_lidx coffs) |
Initializes a densemat from another densemat at a given column and row offset. More... | |
ghost_error | ghost_densemat_init_file (ghost_densemat *x, char *path, ghost_mpi_comm mpicomm) |
Initializes a densemat from a file. More... | |
ghost_error | ghost_densemat_init_real (ghost_densemat *vec, ghost_densemat *re, ghost_densemat *im) |
Initializes a complex densemat from two real ones (one holding the real, the other one the imaginary part). More... | |
ghost_error | ghost_densemat_init_complex (ghost_densemat *re, ghost_densemat *im, ghost_densemat *src) |
Initializes two real densemats from a complex one. More... | |
ghost_error | ghost_densemat_view_plain (ghost_densemat *x, void *data, ghost_lidx stride) |
View plain data which is stored with a given stride. More... | |
ghost_error | ghost_densemat_create_and_view_densemat (ghost_densemat **x, ghost_densemat *src, ghost_lidx nr, ghost_lidx roffs, ghost_lidx nc, ghost_lidx coffs) |
Create a ghost_densemat as a view of compact data of another ghost_densemat. More... | |
ghost_error | ghost_densemat_create_and_view_densemat_scattered (ghost_densemat **x, ghost_densemat *src, ghost_lidx nr, ghost_lidx *ridx, ghost_lidx nc, ghost_lidx *cidx) |
Create a ghost_densemat as a view of arbitrarily scattered data of another ghost_densemat. More... | |
ghost_error | ghost_densemat_create_and_view_densemat_cols (ghost_densemat **x, ghost_densemat *src, ghost_lidx nc, ghost_lidx coffs) |
Create a ghost_densemat as a view of compact columns of another ghost_densemat. More... | |
ghost_error | ghost_densemat_create_and_view_densemat_cols_scattered (ghost_densemat **x, ghost_densemat *src, ghost_lidx nc, ghost_lidx *cidx) |
Create a ghost_densemat as a view of full but scattered columns of another ghost_densemat. More... | |
ghost_error | ghost_densemat_clone (ghost_densemat **x, ghost_densemat *src, ghost_lidx nc, ghost_lidx coffs) |
Create a ghost_densemat as a clone of another ghost_densemat at a column given offset. More... | |
ghost_error | ghost_densemat_string (char **str, ghost_densemat *x) |
Creates a string of the densemat's contents. More... | |
ghost_error | ghost_densemat_permute (ghost_densemat *x, ghost_permutation_direction dir) |
Permute a densemat in a given direction. More... | |
ghost_error | ghost_densemat_download (ghost_densemat *vec) |
Downloads a densemat from a compute device, excluding halo elements. More... | |
ghost_error | ghost_densemat_upload (ghost_densemat *vec) |
Uploads a densemat to a compute device, excluding halo elements. The densemat must be present on both host and device. More... | |
ghost_error | ghost_densemat_reduce (ghost_densemat *vec, int dest) |
Reduces the densemats using addition in its map's communicator. More... | |
ghost_error | ghost_densemat_halocomm_init (ghost_densemat *vec, ghost_context *ctx, ghost_densemat_halo_comm *comm) |
Initialize a halo communication data structure. More... | |
ghost_error | ghost_densemat_halocomm_finalize (ghost_densemat *vec, ghost_context *ctx, ghost_densemat_halo_comm *comm) |
Finalize halo communication. More... | |
ghost_error | ghost_densemat_halo_avg (ghost_densemat *vec, ghost_context *ctx) |
Average each entry over all it's halo siblings. More... | |
ghost_error | ghost_densemat_to_file (ghost_densemat *vec, char *filename, ghost_mpi_comm mpicomm) |
Write a densemat to a file. More... | |
ghost_error | ghost_densemat_entry (void *entry, ghost_densemat *vec, ghost_lidx i, ghost_lidx j) |
Get a single entry of a ghost_densemat. More... | |
ghost_error | ghost_densemat_sync_vals (ghost_densemat *vec, ghost_mpi_comm comm, int root) |
Sets the densemat to have the same values on all processes. More... | |
ghost_error | ghost_densemat_compress (ghost_densemat *vec) |
Compresses a densemat, i.e., make it non-scattered. If the densemat is a view, it will no longer be one afterwards. More... | |
ghost_error | ghost_densemat_collect (ghost_densemat *vec, ghost_densemat *globvec, ghost_context *ctx) |
Collects vec from all MPI ranks and combines them into globalVec. The row permutation (if present) if vec's context is used. More... | |
ghost_error | ghost_densemat_distribute (ghost_densemat *vec, ghost_densemat *localVec, ghost_context *ctx) |
Distributes a global densemat into node-local vetors. More... | |
ghost_error | ghost_densemat_set_map (ghost_densemat *vec, ghost_map *map) |
Sets a densemat's active map. More... | |
Variables | |
const ghost_densemat_traits | GHOST_DENSEMAT_TRAITS_INITIALIZER |
Initializer for densemat traits. More... | |
const ghost_densemat_halo_comm | GHOST_DENSEMAT_HALO_COMM_INITIALIZER |
Initializer for densemat halo communicator. More... | |
#define DM_GNROWS | ( | dm | ) | dm->map->gdim |
#define DM_NROWS | ( | dm | ) | dm->map->dim |
#define DM_NROWSPAD | ( | dm | ) | dm->map->dimpad |
#define GHOST_CM_IDX 0 |
#define GHOST_DENSEMAT_CHECK_SIMILARITY | ( | vec1, | |
vec2 | |||
) |
#define GHOST_DENSEMAT_SCATTERED (GHOST_DENSEMAT_SCATTERED_LD|GHOST_DENSEMAT_SCATTERED_TR) |
#define GHOST_RM_IDX 1 |
typedef struct ghost_densemat ghost_densemat |
typedef int(* ghost_densemat_srcfunc)(ghost_gidx row, ghost_lidx col, void *val, void *arg) |
Callback function to construct a ghost_densemat.
[in] | row | The global row index. |
[in] | col | The column. |
[out] | val | The value at the specified location. |
[in,out] | arg | Additional arguments. |
enum ghost_densemat_flags |
Flags to configure a densemat.
Enumerator | |
---|---|
GHOST_DENSEMAT_DEFAULT | |
GHOST_DENSEMAT_VIEW |
The densemat is a view of another densemat. |
GHOST_DENSEMAT_SCATTERED_LD |
The densemat is scattered in leading dimension, i.e., the rows/columns are not consecutive in memory. This is only possible for views. |
GHOST_DENSEMAT_SCATTERED_TR |
The densemat is scattered in trailing dimension, i.e., the rows/columns are not consecutive in memory. This is only possible for views. |
GHOST_DENSEMAT_PERMUTED |
The densemat has been permuted in GHOST_PERMUTATION_ORIG2PERM direction via its ghost_densemat::permute() function. This flag gets deleted once the densemat has been permuted back (GHOST_PERMUTATION_PERM2ORIG). |
GHOST_DENSEMAT_NOT_RELOCATE |
By default, a densemat's location gets set to #GHOST_DENSEMAT_HOST|#GHOST_DENSEMAT_DEVICE automatically when the first up-/download occurs and the GHOST type is CUDA. This behavior can be disabled by setting this flag. |
GHOST_DENSEMAT_PAD_COLS |
Set this flag if the number of columns should be padded according to the SIMD width. |
bool array_strictly_ascending | ( | ghost_lidx * | coffs, |
ghost_lidx | nc | ||
) |
Check if an array consists of strictly ascending numbers.
coffs | The numbers. |
nc | Length of the array. |
ghost_error ghost_densemat_collect | ( | ghost_densemat * | vec, |
ghost_densemat * | globvec, | ||
ghost_context * | ctx | ||
) |
Collects vec from all MPI ranks and combines them into globalVec. The row permutation (if present) if vec's context is used.
vec | The distributed densemat. |
globvec | The global densemat. |
ctx | The context. |
ghost_error ghost_densemat_compress | ( | ghost_densemat * | vec | ) |
Compresses a densemat, i.e., make it non-scattered. If the densemat is a view, it will no longer be one afterwards.
vec | The densemat. |
ghost_error ghost_densemat_distribute | ( | ghost_densemat * | vec, |
ghost_densemat * | localVec, | ||
ghost_context * | ctx | ||
) |
Distributes a global densemat into node-local vetors.
vec | The global densemat. |
localVec | The local densemat. |
ghost_error ghost_densemat_entry | ( | void * | entry, |
ghost_densemat * | vec, | ||
ghost_lidx | i, | ||
ghost_lidx | j | ||
) |
Get a single entry of a ghost_densemat.
entry | Where to store the entry. |
vec | The densemat. |
i | The row. |
j | The column. |
ghost_error ghost_densemat_halo_avg | ( | ghost_densemat * | vec, |
ghost_context * | ctx | ||
) |
Average each entry over all it's halo siblings.
This function collects the values for each entry which have been communicated to other processes. Then, it computes the average over all and stores the value. This is used, e.g., in ghost_carp().
vec | The densemat. |
ctx | The context in which the densemat lives. |
ghost_error ghost_densemat_halocomm_finalize | ( | ghost_densemat * | vec, |
ghost_context * | ctx, | ||
ghost_densemat_halo_comm * | comm | ||
) |
Finalize halo communication.
This includes waiting for the communication to finish and freeing the data in the comm data structure.
vec | The densemat. |
ctx | The context in which to communicate. |
comm | The halo communication data structure. |
ghost_error ghost_densemat_halocomm_init | ( | ghost_densemat * | vec, |
ghost_context * | ctx, | ||
ghost_densemat_halo_comm * | comm | ||
) |
Initialize a halo communication data structure.
vec | The densemat. |
ctx | The context in which to communicate. |
comm | The halo communication data structure. |
ghost_error ghost_densemat_halocomm_start | ( | ghost_densemat * | vec, |
ghost_context * | ctx, | ||
ghost_densemat_halo_comm * | comm | ||
) |
Start halo communication asynchronously.
vec | The densemat. |
ctx | The context in which to communicate. |
comm | The halo communication data structure. |
ghost_error ghost_densemat_halocommFinalize_common | ( | ghost_densemat_halo_comm * | comm | ) |
Common (storage-independent) functions for ghost_densemat::halocommFinalize()
This function should not be called by a user.
comm | The comm data structure. |
ghost_error ghost_densemat_halocommInit_common | ( | ghost_densemat * | vec, |
ghost_context * | ctx, | ||
ghost_densemat_halo_comm * | comm | ||
) |
Common (storage-independent) functions for ghost_densemat::halocommInit()
This function should not be called by a user.
vec | The densemat. |
ctx | The context in which to communicate. |
comm | The comm data structure. |
ghost_error ghost_densemat_malloc | ( | ghost_densemat * | x, |
int * | needInit | ||
) |
Allocate sparse for a densemat.
x | The densemat |
needInit | This will be set to one of the padding elements require initialization |
ghost_error ghost_densemat_mask2charfield | ( | ghost_bitmap | mask, |
ghost_lidx | len, | ||
char * | charfield | ||
) |
Create an array of chars ('0' or '1') of the densemat mask.
mask | The ldmask. |
len | Length of the ldmask. |
charfield | Location of the char array. |
ghost_error ghost_densemat_permute | ( | ghost_densemat * | x, |
ghost_permutation_direction | dir | ||
) |
Permute a densemat in a given direction.
x | The densemat. |
ctx | The context if a global permutation is present. |
dir | The permutation direction. |
ghost_error ghost_densemat_reduce | ( | ghost_densemat * | vec, |
int | dest | ||
) |
Reduces the densemats using addition in its map's communicator.
vec | The densemat. |
dest | The destination rank or GHOST_ALLREDUCE |
ghost_lidx ghost_densemat_row_padding | ( | ) |
Determine the number of padded rows.
The offset from which halo elements begin and the column indices of remote matrix entries depend on this.
ghost_error ghost_densemat_set_map | ( | ghost_densemat * | vec, |
ghost_map * | map | ||
) |
Sets a densemat's active map.
vec | The densemat. |
map | The map. |
ghost_error ghost_densemat_sync_vals | ( | ghost_densemat * | vec, |
ghost_mpi_comm | comm, | ||
int | root | ||
) |
Sets the densemat to have the same values on all processes.
vec | The densemat. |
comm | The communicator in which to synchronize. |
root | The process from which to take the values. |
ghost_error ghost_densemat_to_file | ( | ghost_densemat * | vec, |
char * | filename, | ||
ghost_mpi_comm | mpicomm | ||
) |
Write a densemat to a file.
vec | The densemat. |
filename | The path to the file. |
mpicomm | If equal to MPI_COMM_SELF, each process will write a separate file. Else, a combined file will be written with MPI I/O. |
ghost_error ghost_densemat_uniformstorage | ( | bool * | uniform, |
ghost_densemat * | vec, | ||
ghost_mpi_comm | mpicomm | ||
) |
Check if a densemat has the same storage order on all processes of a given communicator.
uniform | Where to store the result of the check. |
vec | The densemat. |
mpicomm | The communicator. |
int ghost_idx_of_densemat_storage | ( | ghost_densemat_storage | s | ) |
Translates a ghost_densemat_storage into an consectuive index.
s | The storage type. |
const ghost_densemat_halo_comm GHOST_DENSEMAT_HALO_COMM_INITIALIZER |
Initializer for densemat halo communicator.
const ghost_densemat_traits GHOST_DENSEMAT_TRAITS_INITIALIZER |
Initializer for densemat traits.