GHOST  1.1.2
General, Hybrid, and Optimized Sparse Toolkit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
densemat.h
Go to the documentation of this file.
1 #ifndef GHOST_DENSEMAT_H
2 #define GHOST_DENSEMAT_H
3 
4 #include "config.h"
5 #include "types.h"
6 #include "bitmap.h"
7 #include "bindensemat.h"
8 #include "context.h"
9 
10 #define GHOST_CM_IDX 0
11 #define GHOST_RM_IDX 1
12 
13 #define GHOST_DENSEMAT_CHECK_SIMILARITY(vec1,vec2)\
14  if (DM_NROWS(vec1) != DM_NROWS(vec2)) {\
15  GHOST_ERROR_LOG("Number of rows do not match!");\
16  return GHOST_ERR_INVALID_ARG;\
17  }\
18  if (vec1->traits.ncols != vec2->traits.ncols) {\
19  GHOST_ERROR_LOG("Number of cols do not match!");\
20  return GHOST_ERR_INVALID_ARG;\
21  }\
22  if (vec1->traits.storage != vec2->traits.storage) {\
23  GHOST_ERROR_LOG("Storage orders do not match!");\
24  return GHOST_ERR_INVALID_ARG;\
25  }\
26  if (!(vec1->traits.location & vec2->traits.location)) {\
27  GHOST_ERROR_LOG("Locations do not match!");\
28  return GHOST_ERR_INVALID_ARG;\
29  }\
30  if (!(vec1->traits.datatype == vec2->traits.datatype)) {\
31  GHOST_ERROR_LOG("Types do not match!");\
32  return GHOST_ERR_INVALID_ARG;\
33  }
34 
35 
36 
47 typedef int (*ghost_densemat_srcfunc)(ghost_gidx row, ghost_lidx col, void * val, void * arg);
48 
52 typedef enum {
85 }
87 
88 
89 #define GHOST_DENSEMAT_SCATTERED (GHOST_DENSEMAT_SCATTERED_LD|GHOST_DENSEMAT_SCATTERED_TR)
90 
94 typedef enum
95 {
105 }
107 
111 typedef struct
112 {
113 #ifdef GHOST_HAVE_MPI
114 
117  int msgcount;
121  MPI_Request *request;
125  MPI_Status *status;
129  char **tmprecv;
135  char *tmprecv_mem;
139  char *work;
143  ghost_lidx *dueptr;
147  ghost_lidx *wishptr;
151  ghost_lidx acc_dues;
155  ghost_lidx acc_wishes;
159  void *cu_work;
160 #endif
161 }
163 
167 typedef struct
168 {
211 }
213 
215 
216 
227 {
235  char* val;
243  size_t elSize;
284  char * cu_val;
301 };
302 
303 #define DM_NROWS(dm) dm->map->dim
304 #define DM_GNROWS(dm) dm->map->gdim
305 #define DM_NROWSPAD(dm) dm->map->dimpad
306 
307 #ifdef __cplusplus
308 static inline ghost_densemat_flags operator|(const ghost_densemat_flags &a, const ghost_densemat_flags &b) {
309 return static_cast<ghost_densemat_flags>(static_cast<int>(a) | static_cast<int>(b));
310 }
311 static inline ghost_densemat_flags operator|=(ghost_densemat_flags &a, const ghost_densemat_flags &b) {
312  a = static_cast<ghost_densemat_flags>(static_cast<int>(a) | static_cast<int>(b));
313  return a;
314 }
315 static inline ghost_densemat_flags operator&=(ghost_densemat_flags &a, const ghost_densemat_flags &b) {
316  a = static_cast<ghost_densemat_flags>(static_cast<int>(a) & static_cast<int>(b));
317  return a;
318 }
319 
320 extern "C" {
321 #endif
322 
339 
350  ghost_lidx len, char *charfield);
351 
362 
373  ghost_densemat *vec,ghost_mpi_comm mpicomm);
374 
381 
388  ghost_densemat *densemat);
389 
422 
429 
438 
447 
455 
463 
482 
493 
504 
514 
524 
535 
549 
563 
575 
587 
599 
610 
619 
633 
643 
653 
686 
699 
710  ghost_error ghost_densemat_to_file(ghost_densemat *vec, char *filename, ghost_mpi_comm mpicomm);
711 
723 
734 
755 
765 
776 #ifdef __cplusplus
777 }
778 #endif
779 
784 
789 
790 #endif
ghost_densemat_flags
Flags to configure a densemat.
Definition: densemat.h:52
ghost_implementation
Possible implementations of a CPU function.
Definition: types.h:323
ghost_error ghost_densemat_init_file(ghost_densemat *x, char *path, ghost_mpi_comm mpicomm)
Initializes a densemat from a file.
Definition: densemat.c:771
Header file for type definitions.
ghost_error ghost_densemat_info_string(char **str, ghost_densemat *densemat)
Get a string containing information about the densemat.
Definition: densemat.c:328
ghost_mpi_datatype mpidt
An MPI data type which holds one element.
Definition: densemat.h:276
Traits of the densemat.
Definition: densemat.h:167
bool array_strictly_ascending(ghost_lidx *coffs, ghost_lidx nc)
Check if an array consists of strictly ascending numbers.
Definition: densemat.c:264
Types and functions related to GHOST contexts.
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.
Definition: densemat.c:759
int32_t ghost_gidx
Type for global indices.
Definition: types.h:443
ghost_lidx ncolssub
The number of columns of each sub-densemat.
Definition: densemat.h:210
ghost_permutation_direction
Possible permutation directions.
Definition: context.h:19
The densemat is scattered in leading dimension, i.e., the rows/columns are not consecutive in memory...
Definition: densemat.h:62
ghost_error ghost_densemat_halocomm_start(ghost_densemat *vec, ghost_context *ctx, ghost_densemat_halo_comm *comm)
Start halo communication asynchronously.
Definition: densemat.c:461
const ghost_densemat_traits GHOST_DENSEMAT_TRAITS_INITIALIZER
Initializer for densemat traits.
Definition: densemat.c:31
ghost_densemat ** subdm
List of sub-densemats, points to densemat itself if no sub-densemats.
Definition: densemat.h:292
ghost_densemat * src
The source densemat (must not be a view).
Definition: densemat.h:239
ghost_location compute_at
If the densemat is the result of a computation, decide where to execute the computation.
Definition: densemat.h:199
ghost_location location
Location of the densemat.
Definition: densemat.h:193
ghost_bitmap rowmask
Masked out rows for scattered views.
Definition: densemat.h:272
ghost_lidx blocklen
The leading dimensions of the densemat.
Definition: densemat.h:257
Column-major storage (as in Fortran).
Definition: densemat.h:103
ghost_lidx nblock
The trailing dimensions of the densemat.
Definition: densemat.h:250
The densemat has been permuted in GHOST_PERMUTATION_ORIG2PERM direction via its ghost_densemat::permu...
Definition: densemat.h:75
ghost_error ghost_densemat_create(ghost_densemat **vec, ghost_map *map, ghost_densemat_traits traits)
Create a dense matrix/vector.
Definition: densemat.c:60
ghost_error ghost_densemat_init_val(ghost_densemat *x, void *v)
Initializes a densemat from a scalar value.
Definition: densemat.c:653
ghost_error ghost_densemat_init_complex(ghost_densemat *re, ghost_densemat *im, ghost_densemat *src)
Initializes two real densemats from a complex one.
Definition: densemat.c:787
ghost_bitmap colmask
Masked out columns for scattered views.
Definition: densemat.h:268
ghost_error ghost_densemat_malloc(ghost_densemat *x, int *needInit)
Allocate sparse for a densemat.
Definition: densemat.c:674
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()
Definition: densemat.c:378
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.
Definition: densemat.c:765
int32_t ghost_lidx
Definition: types.h:503
ghost_error ghost_densemat_view_plain(ghost_densemat *x, void *data, ghost_lidx stride)
View plain data which is stored with a given stride.
Definition: densemat.c:802
ghost_error ghost_densemat_halocommFinalize_common(ghost_densemat_halo_comm *comm)
Common (storage-independent) functions for ghost_densemat::halocommFinalize()
Definition: densemat.c:558
ghost_error ghost_densemat_reduce(ghost_densemat *vec, int dest)
Reduces the densemats using addition in its map's communicator.
Definition: densemat.c:716
char * ghost_densemat_storage_string(ghost_densemat_storage storage)
Get a string about the storage order.
Definition: densemat.c:296
ghost_error ghost_densemat_permute(ghost_densemat *x, ghost_permutation_direction dir)
Permute a densemat in a given direction.
Definition: densemat.c:711
ghost_lidx nsub
Number of sub-densemats.
Definition: densemat.h:296
int ghost_mpi_comm
Definition: types.h:19
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.
Definition: densemat.c:797
ghost_map * map
The densemat's map.
Definition: densemat.h:288
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...
Definition: densemat.c:809
ghost_lidx ncolspadded
The padded number of columns (may differ from ncols for row-major densemats).
Definition: densemat.h:177
ghost_error
Error return type.
Definition: error.h:23
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 ...
Definition: densemat.c:782
int(* ghost_densemat_srcfunc)(ghost_gidx row, ghost_lidx col, void *val, void *arg)
Callback function to construct a ghost_densemat.
Definition: densemat.h:47
size_t elSize
Size (in bytes) of one matrix element.
Definition: densemat.h:243
Row-major storage (as in C).
Definition: densemat.h:99
ghost_error ghost_densemat_halocomm_init(ghost_densemat *vec, ghost_context *ctx, ghost_densemat_halo_comm *comm)
Initialize a halo communication data structure.
Definition: densemat.c:726
ghost_error ghost_densemat_set_map(ghost_densemat *vec, ghost_map *map)
Sets a densemat's active map.
Definition: densemat.c:834
ghost_datatype datatype
The data type.
Definition: densemat.h:189
const ghost_densemat_halo_comm GHOST_DENSEMAT_HALO_COMM_INITIALIZER
Initializer for densemat halo communicator.
Definition: densemat.c:43
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.
Definition: densemat.c:753
ghost_densemat_flags flags
Property flags.
Definition: densemat.h:181
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.
Definition: densemat.c:747
ghost_lidx coloff
Column offset into the parent densemat (if it is a subdensemat).
Definition: densemat.h:300
The densemat is scattered in trailing dimension, i.e., the rows/columns are not consecutive in memory...
Definition: densemat.h:67
Densemat halo exchange communication data structure.
Definition: densemat.h:111
ghost_error ghost_densemat_entry(void *entry, ghost_densemat *vec, ghost_lidx i, ghost_lidx j)
Get a single entry of a ghost_densemat.
Definition: densemat.c:792
ghost_datatype
Available primitive data types.
Definition: types.h:248
void ghost_densemat_destroy(ghost_densemat *vec)
Destroys a densemat, i.e., frees all its data structures.
Definition: densemat.c:581
#define GHOST_BINDENSEMAT_ORDER_ROW_FIRST
Definition: bindensemat.h:10
A GHOST map.
Definition: map.h:83
int ghost_mpi_datatype
Definition: types.h:21
ghost_error ghost_densemat_download(ghost_densemat *vec)
Downloads a densemat from a compute device, excluding halo elements.
Definition: densemat.c:738
ghost_error ghost_densemat_init_func(ghost_densemat *x, ghost_densemat_srcfunc func, void *arg)
Initializes a densemat from a given callback function.
Definition: densemat.c:702
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.
Definition: densemat.c:249
Set this flag if the number of columns should be padded according to the SIMD width.
Definition: densemat.h:84
ghost_lidx stride
The leading dimensions of the densemat in memory.
Definition: densemat.h:264
ghost_error ghost_densemat_distribute(ghost_densemat *vec, ghost_densemat *localVec, ghost_context *ctx)
Distributes a global densemat into node-local vetors.
Definition: densemat.c:814
ghost_error ghost_densemat_to_file(ghost_densemat *vec, char *filename, ghost_mpi_comm mpicomm)
Write a densemat to a file.
Definition: densemat.c:721
hwloc_bitmap_t ghost_bitmap
ghost_bitmap is just an alias for hwloc_bitmap_t
Definition: bitmap.h:18
ghost_densemat_storage
Densemat storage orders.
Definition: densemat.h:94
By default, a densemat's location gets set to #GHOST_DENSEMAT_HOST|#GHOST_DENSEMAT_DEVICE automatical...
Definition: densemat.h:80
Bitmap used for viewing densemat cols/rows in the leading dimension.
The GHOST context.
Definition: context.h:108
char * val
The values of the densemat.
Definition: densemat.h:235
Definition: densemat.h:104
ghost_lidx ncols
The number of columns.
Definition: densemat.h:172
int ghost_idx_of_densemat_storage(ghost_densemat_storage s)
Translates a ghost_densemat_storage into an consectuive index.
Definition: densemat.c:626
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...
Definition: densemat.c:740
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 o...
Definition: densemat.c:807
Definition: densemat.h:53
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.
Definition: densemat.c:776
ghost_densemat_traits traits
The densemat's traits.
Definition: densemat.h:231
ghost_error ghost_densemat_halocomm_finalize(ghost_densemat *vec, ghost_context *ctx, ghost_densemat_halo_comm *comm)
Finalize halo communication.
Definition: densemat.c:732
ghost_implementation compute_with
If the densemat is the result of a computation, decide with which implementation to compute it...
Definition: densemat.h:206
ghost_error ghost_densemat_init_rand(ghost_densemat *x)
Initializes a densemat from random values.
Definition: densemat.c:635
The densemat is a view of another densemat.
Definition: densemat.h:57
ghost_error ghost_densemat_halo_avg(ghost_densemat *vec, ghost_context *ctx)
Average each entry over all it's halo siblings.
Definition: densemat.c:742
ghost_error ghost_densemat_string(char **str, ghost_densemat *x)
Creates a string of the densemat's contents.
Definition: densemat.cpp:22
ghost_mpi_datatype fullmpidt
An MPI data type which holds the entire densemat.
Definition: densemat.h:280
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.
Definition: densemat.c:820
ghost_location
Definition: types.h:270
char * cu_val
The values of the densemat on the CUDA device.
Definition: densemat.h:284
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.
Definition: densemat.c:276
#define GHOST_BINDENSEMAT_ORDER_COL_FIRST
Definition: bindensemat.h:9
ghost_densemat_storage storage
The storage order.
Definition: densemat.h:185
A dense vector/matrix.
Definition: densemat.h:226
ghost_lidx ghost_densemat_row_padding()
Determine the number of padded rows.
Definition: densemat.c:616
Constant defintions for binary dense matrix files.