GHOST  1.1.2
General, Hybrid, and Optimized Sparse Toolkit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Classes | Macros | Typedefs | Enumerations | Functions | Variables
densemat.h File Reference
#include "config.h"
#include "types.h"
#include "bitmap.h"
#include "bindensemat.h"
#include "context.h"
Include dependency graph for densemat.h:
This graph shows which files directly or indirectly include this file:

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...
 

Macro Definition Documentation

#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 
)
Value:
if (DM_NROWS(vec1) != DM_NROWS(vec2)) {\
GHOST_ERROR_LOG("Number of rows do not match!");\
}\
if (vec1->traits.ncols != vec2->traits.ncols) {\
GHOST_ERROR_LOG("Number of cols do not match!");\
}\
if (vec1->traits.storage != vec2->traits.storage) {\
GHOST_ERROR_LOG("Storage orders do not match!");\
}\
if (!(vec1->traits.location & vec2->traits.location)) {\
GHOST_ERROR_LOG("Locations do not match!");\
}\
if (!(vec1->traits.datatype == vec2->traits.datatype)) {\
GHOST_ERROR_LOG("Types do not match!");\
}
#define GHOST_ERROR_LOG(...)
Definition: log.h:125
#define DM_NROWS(dm)
Definition: densemat.h:303
One or more of the arguments are invalid.
Definition: error.h:31
#define GHOST_DENSEMAT_SCATTERED   (GHOST_DENSEMAT_SCATTERED_LD|GHOST_DENSEMAT_SCATTERED_TR)
#define GHOST_RM_IDX   1

Typedef Documentation

typedef int(* ghost_densemat_srcfunc)(ghost_gidx row, ghost_lidx col, void *val, void *arg)

Callback function to construct a ghost_densemat.

Parameters
[in]rowThe global row index.
[in]colThe column.
[out]valThe value at the specified location.
[in,out]argAdditional arguments.
Returns

Enumeration Type Documentation

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.

Densemat storage orders.

Enumerator
GHOST_DENSEMAT_ROWMAJOR 

Row-major storage (as in C).

GHOST_DENSEMAT_COLMAJOR 

Column-major storage (as in Fortran).

GHOST_DENSEMAT_STORAGE_DEFAULT 

Function Documentation

bool array_strictly_ascending ( ghost_lidx coffs,
ghost_lidx  nc 
)

Check if an array consists of strictly ascending numbers.

Parameters
coffsThe numbers.
ncLength of the array.
Returns
True if each number is greater than the previous one, false otherwise.
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.

Parameters
vecThe distributed densemat.
globvecThe global densemat.
ctxThe context.
Returns
GHOST_SUCCESS on success or an error indicator.
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.

Parameters
vecThe densemat.
Returns
GHOST_SUCCESS on success or an error indicator.
ghost_error ghost_densemat_distribute ( ghost_densemat vec,
ghost_densemat localVec,
ghost_context ctx 
)

Distributes a global densemat into node-local vetors.

Parameters
vecThe global densemat.
localVecThe local densemat.
Returns
GHOST_SUCCESS on success or an error indicator.
ghost_error ghost_densemat_entry ( void *  entry,
ghost_densemat vec,
ghost_lidx  i,
ghost_lidx  j 
)

Get a single entry of a ghost_densemat.

Parameters
entryWhere to store the entry.
vecThe densemat.
iThe row.
jThe column.
Returns
GHOST_SUCCESS on success or an error indicator.
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().

Parameters
vecThe densemat.
ctxThe 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.

Parameters
vecThe densemat.
ctxThe context in which to communicate.
commThe halo communication data structure.
Returns
GHOST_SUCCESS on success or an error indicator.
ghost_error ghost_densemat_halocomm_init ( ghost_densemat vec,
ghost_context ctx,
ghost_densemat_halo_comm comm 
)

Initialize a halo communication data structure.

Parameters
vecThe densemat.
ctxThe context in which to communicate.
commThe halo communication data structure.
Returns
GHOST_SUCCESS on success or an error indicator.
ghost_error ghost_densemat_halocomm_start ( ghost_densemat vec,
ghost_context ctx,
ghost_densemat_halo_comm comm 
)

Start halo communication asynchronously.

Parameters
vecThe densemat.
ctxThe context in which to communicate.
commThe halo communication data structure.
Returns
GHOST_SUCCESS on success or an error indicator.

Here is the call graph for this function:

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.

Parameters
commThe comm data structure.
Returns
GHOST_SUCCESS on success or an error indicator.
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.

Parameters
vecThe densemat.
ctxThe context in which to communicate.
commThe comm data structure.
Returns
GHOST_SUCCESS on success or an error indicator.

Here is the call graph for this function:

ghost_error ghost_densemat_malloc ( ghost_densemat x,
int *  needInit 
)

Allocate sparse for a densemat.

Parameters
xThe densemat
needInitThis will be set to one of the padding elements require initialization
Returns
GHOST_SUCCESS on success or an error indicator.

Here is the call graph for this function:

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.

Parameters
maskThe ldmask.
lenLength of the ldmask.
charfieldLocation of the char array.
Returns
GHOST_SUCCESS on success or an error indicator.
ghost_error ghost_densemat_permute ( ghost_densemat x,
ghost_permutation_direction  dir 
)

Permute a densemat in a given direction.

Parameters
xThe densemat.
ctxThe context if a global permutation is present.
dirThe permutation direction.
Returns
GHOST_SUCCESS on success or an error indicator.
ghost_error ghost_densemat_reduce ( ghost_densemat vec,
int  dest 
)

Reduces the densemats using addition in its map's communicator.

Parameters
vecThe densemat.
destThe destination rank or GHOST_ALLREDUCE
Returns
GHOST_SUCCESS on success or an error indicator.
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.

Returns
The number of padded rows.

Here is the call graph for this function:

ghost_error ghost_densemat_set_map ( ghost_densemat vec,
ghost_map map 
)

Sets a densemat's active map.

Parameters
vecThe densemat.
mapThe map.
Returns
GHOST_SUCCESS on success or an error indicator.
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.

Parameters
vecThe densemat.
commThe communicator in which to synchronize.
rootThe process from which to take the values.
Returns
GHOST_SUCCESS on success or an error indicator.
ghost_error ghost_densemat_to_file ( ghost_densemat vec,
char *  filename,
ghost_mpi_comm  mpicomm 
)

Write a densemat to a file.

Parameters
vecThe densemat.
filenameThe path to the file.
mpicommIf equal to MPI_COMM_SELF, each process will write a separate file. Else, a combined file will be written with MPI I/O.
Returns
GHOST_SUCCESS on success or an error indicator.
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.

Parameters
uniformWhere to store the result of the check.
vecThe densemat.
mpicommThe communicator.
Returns
GHOST_SUCCESS on success or an error indicator.

Here is the call graph for this function:

int ghost_idx_of_densemat_storage ( ghost_densemat_storage  s)

Translates a ghost_densemat_storage into an consectuive index.

Parameters
sThe storage type.
Returns
The index.

Variable Documentation

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.