GHOST  1.1.2
General, Hybrid, and Optimized Sparse Toolkit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions | Variables
densemat.c File Reference
#include "ghost/config.h"
#include "ghost/types.h"
#include "ghost/core.h"
#include "ghost/datatransfers.h"
#include "ghost/densemat.h"
#include "ghost/densemat_cm.h"
#include "ghost/densemat_rm.h"
#include "ghost/util.h"
#include "ghost/locality.h"
#include "ghost/context.h"
#include "ghost/instr.h"
#include "ghost/machine.h"
#include "ghost/log.h"
#include "ghost/bindensemat.h"
#include "ghost/constants.h"
#include "ghost/math.h"
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
Include dependency graph for densemat.c:

Macros

#define _XOPEN_SOURCE   500
 
#define PASTER(x, y)   x##_##y
 
#define EVALUATOR(x, y)   PASTER(x, y)
 
#define CM_FUNCNAME(fun)   EVALUATOR(ghost_densemat_cm, fun)
 
#define RM_FUNCNAME(fun)   EVALUATOR(ghost_densemat_rm, fun)
 
#define CALL_DENSEMAT_FUNC(vec, func,...)
 
#define CALL_DENSEMAT_FUNC_NORET(ret, vec, func,...)
 

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...
 
static void charfield2string (char *str, char *cf, int len)
 
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 *val)
 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_permute (ghost_densemat *x, ghost_permutation_direction dir)
 Permute a densemat in a given direction. 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_to_file (ghost_densemat *vec, char *filename, ghost_mpi_comm mpicomm)
 Write a densemat to a file. 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_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_halo_avg (ghost_densemat *vec, ghost_context *ctx)
 Average each entry over all it's halo siblings. 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_init_file (ghost_densemat *x, char *path, ghost_mpi_comm mpicomm)
 Initializes a densemat from a file. 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_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_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_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_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_clone (ghost_densemat **dst, 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_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 _XOPEN_SOURCE   500
#define CALL_DENSEMAT_FUNC (   vec,
  func,
  ... 
)
Value:
if (vec->traits.storage == GHOST_DENSEMAT_COLMAJOR) { \
return CM_FUNCNAME(func)(__VA_ARGS__); \
} else { \
return RM_FUNCNAME(func)(__VA_ARGS__); \
}
Column-major storage (as in Fortran).
Definition: densemat.h:103
#define CM_FUNCNAME(fun)
Definition: densemat.c:685
#define RM_FUNCNAME(fun)
Definition: densemat.c:686
#define CALL_DENSEMAT_FUNC_NORET (   ret,
  vec,
  func,
  ... 
)
Value:
if (vec->traits.storage == GHOST_DENSEMAT_COLMAJOR) { \
ret = CM_FUNCNAME(func)(__VA_ARGS__); \
} else { \
ret = RM_FUNCNAME(func)(__VA_ARGS__); \
}
Column-major storage (as in Fortran).
Definition: densemat.h:103
#define CM_FUNCNAME(fun)
Definition: densemat.c:685
#define RM_FUNCNAME(fun)
Definition: densemat.c:686
#define CM_FUNCNAME (   fun)    EVALUATOR(ghost_densemat_cm, fun)
#define EVALUATOR (   x,
 
)    PASTER(x, y)
#define PASTER (   x,
 
)    x##_##y
#define RM_FUNCNAME (   fun)    EVALUATOR(ghost_densemat_rm, fun)

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.
static void charfield2string ( char *  str,
char *  cf,
int  len 
)
static
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
Initial value:
= {
}

Initializer for densemat halo communicator.

const ghost_densemat_traits GHOST_DENSEMAT_TRAITS_INITIALIZER
Initial value:
= {
.ncols = 1,
.ncolspadded = 0,
.ncolssub = 0,
.compute_at = GHOST_LOCATION_DEFAULT,
}
Definition: types.h:324
Double precision.
Definition: types.h:256
Real numbers.
Definition: types.h:260
Default location. This is only a placeholder and the actual location has to be specified by GHOST...
Definition: types.h:274
ghost_datatype
Available primitive data types.
Definition: types.h:248
Definition: densemat.h:104
Definition: densemat.h:53

Initializer for densemat traits.