(git:3f0d10b)
Loading...
Searching...
No Matches
dbm_matrix.c File Reference
#include "dbm_matrix.h"
#include "dbm_hyperparams.h"
#include <assert.h>
#include <math.h>
#include <omp.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Functions

void dbm_create (dbm_matrix_t **matrix_out, dbm_distribution_t *dist, const char name[], const int nrows, const int ncols, const int row_sizes[nrows], const int col_sizes[ncols])
 Creates a new matrix.
void dbm_release (dbm_matrix_t *matrix)
 Releases a matrix and all its ressources.
void dbm_copy (dbm_matrix_t *matrix_a, const dbm_matrix_t *matrix_b)
 Copies content of matrix_b into matrix_a. Matrices must have the same row/col block sizes and distribution.
void dbm_redistribute (const dbm_matrix_t *matrix, dbm_matrix_t *redist)
 Copies content of matrix_b into matrix_a. Matrices may have different distributions.
void dbm_get_block_p (dbm_matrix_t *matrix, const int row, const int col, double **block, int *row_size, int *col_size)
 Looks up a block from given matrics. This routine is thread-safe. If the block is not found then a null pointer is returned.
void dbm_put_block (dbm_matrix_t *matrix, const int row, const int col, const bool summation, const double *block)
 Adds a block to given matrix. This routine is thread-safe. If block already exist then it gets overwritten (or summed).
void dbm_clear (dbm_matrix_t *matrix)
 Remove all blocks from matrix, but does not release underlying memory.
void dbm_filter (dbm_matrix_t *matrix, const double eps)
 Removes all blocks from the matrix whose norm is below the threshold. Blocks of size zero are always kept.
void dbm_reserve_blocks (dbm_matrix_t *matrix, const int nblocks, const int rows[], const int cols[])
 Adds list of blocks efficiently. The blocks will be filled with zeros. This routine must always be called within an OpenMP parallel region.
void dbm_reserve_blocks_template (dbm_matrix_t *matrix, const dbm_matrix_t *matrix_template)
 Reserves template blocks in a matrix sharing the distribution object. Block sizes may differ. Existing values are kept, new blocks zeroed. Call outside an OpenMP parallel region.
void dbm_scale (dbm_matrix_t *matrix, const double alpha)
 Multiplies all entries in the given matrix by the given factor alpha.
void dbm_zero (dbm_matrix_t *matrix)
 Sets all blocks in the given matrix to zero.
void dbm_add (dbm_matrix_t *matrix_a, const dbm_matrix_t *matrix_b)
 Adds matrix_b to matrix_a.
void dbm_iterator_start (dbm_iterator_t **iter_out, const dbm_matrix_t *matrix)
 Creates an iterator for the blocks of the given matrix. The iteration order is not stable. This routine must always be called within an OpenMP parallel region.
int dbm_iterator_num_blocks (const dbm_iterator_t *iter)
 Returns number of blocks the iterator will provide to calling thread.
bool dbm_iterator_blocks_left (const dbm_iterator_t *iter)
 Tests whether the given iterator has any block left.
void dbm_iterator_next_block (dbm_iterator_t *iter, int *row, int *col, double **block, int *row_size, int *col_size)
 Returns the next block from the given iterator.
void dbm_iterator_stop (dbm_iterator_t *iter)
 Releases the given iterator.
static double kahan_sum (double value, double *accumulator, double *compensation)
 Private routine to accumulate using Kahan's summation.
double dbm_checksum (const dbm_matrix_t *matrix)
 Computes a checksum of the given matrix.
double dbm_maxabs (const dbm_matrix_t *matrix)
 Returns the largest absolute value of all matrix elements.
double dbm_maxeps (const dbm_matrix_t *matrix_a, const dbm_matrix_t *matrix_b)
 Calculates maximum relative difference between matrix_a and matrix_b.
const char * dbm_get_name (const dbm_matrix_t *matrix)
 Returns the name of the matrix of the given matrix.
int dbm_get_nze (const dbm_matrix_t *matrix)
 Returns the number of local Non-Zero Elements of the given matrix.
int dbm_get_num_blocks (const dbm_matrix_t *matrix)
 Returns the number of local blocks of the given matrix.
void dbm_get_row_sizes (const dbm_matrix_t *matrix, int *nrows, const int **row_sizes)
 Returns the row block sizes of the given matrix.
void dbm_get_col_sizes (const dbm_matrix_t *matrix, int *ncols, const int **col_sizes)
 Returns the column block sizes of the given matrix.
void dbm_get_local_rows (const dbm_matrix_t *matrix, int *nlocal_rows, const int **local_rows)
 Returns the local row block sizes of the given matrix.
void dbm_get_local_cols (const dbm_matrix_t *matrix, int *nlocal_cols, const int **local_cols)
 Returns the local column block sizes of the given matrix.
int dbm_get_stored_coordinates (const dbm_matrix_t *matrix, const int row, const int col)
 Returns the MPI rank on which the given block should be stored.
const dbm_distribution_t * dbm_get_distribution (const dbm_matrix_t *matrix)
 Returns the distribution of the given matrix.

Function Documentation

◆ dbm_create()

void dbm_create ( dbm_matrix_t ** matrix_out,
dbm_distribution_t * dist,
const char name[],
const int nrows,
const int ncols,
const int row_sizes[nrows],
const int col_sizes[ncols] )

Creates a new matrix.

Author
Ole Schuett

Definition at line 22 of file dbm_matrix.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dbm_release()

void dbm_release ( dbm_matrix_t * matrix)

Releases a matrix and all its ressources.

Author
Ole Schuett

Definition at line 72 of file dbm_matrix.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dbm_copy()

void dbm_copy ( dbm_matrix_t * matrix_a,
const dbm_matrix_t * matrix_b )

Copies content of matrix_b into matrix_a. Matrices must have the same row/col block sizes and distribution.

Author
Ole Schuett

Definition at line 90 of file dbm_matrix.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dbm_redistribute()

void dbm_redistribute ( const dbm_matrix_t * matrix,
dbm_matrix_t * redist )

Copies content of matrix_b into matrix_a. Matrices may have different distributions.

Author
Ole Schuett

Definition at line 115 of file dbm_matrix.c.

Here is the call graph for this function:

◆ dbm_get_block_p()

void dbm_get_block_p ( dbm_matrix_t * matrix,
const int row,
const int col,
double ** block,
int * row_size,
int * col_size )

Looks up a block from given matrics. This routine is thread-safe. If the block is not found then a null pointer is returned.

Author
Ole Schuett

Definition at line 213 of file dbm_matrix.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dbm_put_block()

void dbm_put_block ( dbm_matrix_t * matrix,
const int row,
const int col,
const bool summation,
const double * block )

Adds a block to given matrix. This routine is thread-safe. If block already exist then it gets overwritten (or summed).

Author
Ole Schuett

Definition at line 235 of file dbm_matrix.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dbm_clear()

void dbm_clear ( dbm_matrix_t * matrix)

Remove all blocks from matrix, but does not release underlying memory.

Author
Ole Schuett

Definition at line 265 of file dbm_matrix.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dbm_filter()

void dbm_filter ( dbm_matrix_t * matrix,
const double eps )

Removes all blocks from the matrix whose norm is below the threshold. Blocks of size zero are always kept.

Author
Ole Schuett

Definition at line 282 of file dbm_matrix.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dbm_reserve_blocks()

void dbm_reserve_blocks ( dbm_matrix_t * matrix,
const int nblocks,
const int rows[],
const int cols[] )

Adds list of blocks efficiently. The blocks will be filled with zeros. This routine must always be called within an OpenMP parallel region.

Author
Ole Schuett and Hans Pabst

Definition at line 335 of file dbm_matrix.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dbm_reserve_blocks_template()

void dbm_reserve_blocks_template ( dbm_matrix_t * matrix,
const dbm_matrix_t * matrix_template )

Reserves template blocks in a matrix sharing the distribution object. Block sizes may differ. Existing values are kept, new blocks zeroed. Call outside an OpenMP parallel region.

Definition at line 437 of file dbm_matrix.c.

Here is the call graph for this function:

◆ dbm_scale()

void dbm_scale ( dbm_matrix_t * matrix,
const double alpha )

Multiplies all entries in the given matrix by the given factor alpha.

Author
Ole Schuett

Definition at line 469 of file dbm_matrix.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dbm_zero()

void dbm_zero ( dbm_matrix_t * matrix)

Sets all blocks in the given matrix to zero.

Author
Ole Schuett

Definition at line 492 of file dbm_matrix.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dbm_add()

void dbm_add ( dbm_matrix_t * matrix_a,
const dbm_matrix_t * matrix_b )

Adds matrix_b to matrix_a.

Author
Ole Schuett

Definition at line 508 of file dbm_matrix.c.

Here is the call graph for this function:

◆ dbm_iterator_start()

void dbm_iterator_start ( dbm_iterator_t ** iter_out,
const dbm_matrix_t * matrix )

Creates an iterator for the blocks of the given matrix. The iteration order is not stable. This routine must always be called within an OpenMP parallel region.

Author
Ole Schuett

Definition at line 540 of file dbm_matrix.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dbm_iterator_num_blocks()

int dbm_iterator_num_blocks ( const dbm_iterator_t * iter)

Returns number of blocks the iterator will provide to calling thread.

Author
Ole Schuett

Definition at line 560 of file dbm_matrix.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dbm_iterator_blocks_left()

bool dbm_iterator_blocks_left ( const dbm_iterator_t * iter)

Tests whether the given iterator has any block left.

Author
Ole Schuett

Definition at line 574 of file dbm_matrix.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dbm_iterator_next_block()

void dbm_iterator_next_block ( dbm_iterator_t * iter,
int * row,
int * col,
double ** block,
int * row_size,
int * col_size )

Returns the next block from the given iterator.

Author
Ole Schuett

Definition at line 582 of file dbm_matrix.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dbm_iterator_stop()

void dbm_iterator_stop ( dbm_iterator_t * iter)

Releases the given iterator.

Author
Ole Schuett

Definition at line 612 of file dbm_matrix.c.

Here is the caller graph for this function:

◆ kahan_sum()

double kahan_sum ( double value,
double * accumulator,
double * compensation )
static

Private routine to accumulate using Kahan's summation.

Author
Hans Pabst

Definition at line 618 of file dbm_matrix.c.

◆ dbm_checksum()

double dbm_checksum ( const dbm_matrix_t * matrix)

Computes a checksum of the given matrix.

Author
Ole Schuett

Definition at line 633 of file dbm_matrix.c.

Here is the call graph for this function:

◆ dbm_maxabs()

double dbm_maxabs ( const dbm_matrix_t * matrix)

Returns the largest absolute value of all matrix elements.

Returns the absolute value of the larges element of the entire matrix.

Author
Ole Schuett

Definition at line 650 of file dbm_matrix.c.

Here is the call graph for this function:

◆ dbm_maxeps()

double dbm_maxeps ( const dbm_matrix_t * matrix_a,
const dbm_matrix_t * matrix_b )

Calculates maximum relative difference between matrix_a and matrix_b.

Author
Hans Pabst

Definition at line 666 of file dbm_matrix.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dbm_get_name()

const char * dbm_get_name ( const dbm_matrix_t * matrix)

Returns the name of the matrix of the given matrix.

Author
Ole Schuett

Definition at line 728 of file dbm_matrix.c.

Here is the caller graph for this function:

◆ dbm_get_nze()

int dbm_get_nze ( const dbm_matrix_t * matrix)

Returns the number of local Non-Zero Elements of the given matrix.

Author
Ole Schuett

Definition at line 734 of file dbm_matrix.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dbm_get_num_blocks()

int dbm_get_num_blocks ( const dbm_matrix_t * matrix)

Returns the number of local blocks of the given matrix.

Author
Ole Schuett

Definition at line 746 of file dbm_matrix.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dbm_get_row_sizes()

void dbm_get_row_sizes ( const dbm_matrix_t * matrix,
int * nrows,
const int ** row_sizes )

Returns the row block sizes of the given matrix.

Author
Ole Schuett

Definition at line 758 of file dbm_matrix.c.

Here is the caller graph for this function:

◆ dbm_get_col_sizes()

void dbm_get_col_sizes ( const dbm_matrix_t * matrix,
int * ncols,
const int ** col_sizes )

Returns the column block sizes of the given matrix.

Author
Ole Schuett

Definition at line 768 of file dbm_matrix.c.

Here is the caller graph for this function:

◆ dbm_get_local_rows()

void dbm_get_local_rows ( const dbm_matrix_t * matrix,
int * nlocal_rows,
const int ** local_rows )

Returns the local row block sizes of the given matrix.

Author
Ole Schuett

Definition at line 778 of file dbm_matrix.c.

Here is the caller graph for this function:

◆ dbm_get_local_cols()

void dbm_get_local_cols ( const dbm_matrix_t * matrix,
int * nlocal_cols,
const int ** local_cols )

Returns the local column block sizes of the given matrix.

Author
Ole Schuett

Definition at line 788 of file dbm_matrix.c.

Here is the caller graph for this function:

◆ dbm_get_stored_coordinates()

int dbm_get_stored_coordinates ( const dbm_matrix_t * matrix,
const int row,
const int col )

Returns the MPI rank on which the given block should be stored.

Author
Ole Schuett

Definition at line 798 of file dbm_matrix.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dbm_get_distribution()

const dbm_distribution_t * dbm_get_distribution ( const dbm_matrix_t * matrix)

Returns the distribution of the given matrix.

Author
Ole Schuett

Definition at line 807 of file dbm_matrix.c.

Here is the caller graph for this function: