convert.c File Reference


Detailed Description

Conversion between CSR and MBCSR format.

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <oski/config.h>
#include <oski/common.h>
#include <oski/modloader.h>
#include <oski/matrix.h>
#include <oski/CSR/format.h>
#include <oski/MBCSR/format.h>
#include <oski/MBCSR/module.h>
#include <oski/xforms_internal.h>

Defines

#define IS_BOUNDED(j, j_min, j_max)   ((j) >= (j_min) && (j) <= (j_max))
 Returns a non-zero value <==> j is in [j_min, j_max].

Enumerations

enum  mirrordir_t {
  NO_MIRROR = 0, LOWER_TO_UPPER = 1, LOWER_TO_UPPER_CONJ = 2, UPPER_TO_LOWER = 3,
  UPPER_TO_LOWER_CONJ = 4
}
 Direction option for MirrorDiagBlocks().

Functions

static oski_index_t ScatterBlockRow (const oski_index_t *ptr, const oski_index_t *ind, const oski_value_t *val, oski_index_t n, oski_index_t indbase, oski_index_t i0, oski_index_t r, oski_index_t c, oski_index_t d0, oski_index_t *has_block_col, oski_index_t *inds, oski_value_t *blocks, oski_value_t *diag)
 Scatter.
static void UnscatterBlockRow (const oski_index_t *ptr, const oski_index_t *ind, oski_index_t indbase, oski_index_t i0, oski_index_t r, oski_index_t c, oski_index_t d0, oski_index_t *has_block_col)
 Unscatter.
static int AllocateBlocks (oski_index_t num_block_rows, oski_index_t num_blocks, oski_index_t r, oski_index_t c, oski_index_t **p_ind, oski_value_t **p_blocks, oski_value_t **p_diagblocks)
 Allocate space for a given number of blocks, including their indices and diagonal blocks.
static int ConvertSubmatFromCSR (oski_index_t M, oski_index_t n, oski_index_t i0, oski_index_t d0, const oski_index_t *ptr, const oski_index_t *ind, const oski_value_t *val, oski_index_t indbase, oski_index_t r, oski_index_t c, oski_index_t **p_bptr, oski_index_t **p_bind, oski_value_t **p_bval, oski_value_t **p_bdiag)
 Given an input matrix $A$ stored in CSR format, convert a submatrix $A(I,:)$ to $r\times c$ MBCSR format.
static void SetUnitDiag (oski_index_t num_blocks, oski_index_t block_size, oski_value_t *blocks)
 Given a packed array of $M$ $b\times b$ blocks, sets the diagonal entries of each block to 1.
static int ConvertFromCSR (oski_index_t m, oski_index_t n, const oski_index_t *ptr, const oski_index_t *ind, const oski_value_t *val, oski_index_t indbase, oski_index_t has_unit_diag_implicit, oski_index_t r, oski_index_t c, oski_index_t *p_M1, oski_index_t **p_ptr1, oski_index_t **p_ind1, oski_value_t **p_val1, oski_value_t **p_diag1, oski_index_t *p_M2, oski_index_t *p_r2, oski_index_t **p_ptr2, oski_index_t **p_ind2, oski_value_t **p_val2, oski_value_t **p_diag2, oski_index_t *p_num_rows_left)
 Convert the portions of the CSR matrix that correspond to partitions $A_1$ and $A_2$ in MBCSR format.
static void SetModuleName (oski_submatMBCSR_t *B)
 Initializes the cached module name for an MBCSR submatrix.
static void InitSubmatCSR (const oski_matCSR_t *A, const oski_matcommon_t *props, oski_index_t row_start, oski_index_t num_rows, oski_matCSR_t *A_sub, oski_matcommon_t *props_sub)
 Given a CSR matrix $A$, compute a shallow copy corresponding to a subset of the rows of $A$.
static int ConvertCSRLeftoverRows (const oski_matCSR_t *A, const oski_matcommon_t *props, oski_index_t row_start, oski_index_t num_rows, oski_index_t r, oski_index_t c, oski_matBCSR_t **p_B)
 Given a CSR matrix $A$, convert all the rows beginning at some row $i$ to $r\times c$ BCSR format.
static void MirrorDiagBlocks (mirrordir_t dir, oski_value_t *blocks, oski_index_t num_blocks, oski_index_t b)
 For each diagonal block $B$ of a matrix which is either symmetric or Hermitian, store $B$ using full-storage such that $B = \mathrm{op}(B)$ where $\mathrm{op}(B) \in \{B^T, B^H\}$, as appropriate.
static oski_index_t CalcNnzStored_CSR (oski_index_t m, const oski_matCSR_t *A)
static oski_index_t CalcNnzStored_BCSR (const oski_matBCSR_t *A)
static oski_index_t CalcNnzStored_submatMBCSR (const oski_submatMBCSR_t *A)
static oski_index_t CalcNnzStored_MBCSR (const oski_matMBCSR_t *A)
static double CalcFillRatio (const oski_matMBCSR_t *A, const oski_matCSR_t *A_orig, const oski_matcommon_t *props)
void * oski_CreateMatReprFromCSR (const oski_matCSR_t *mat, const oski_matcommon_t *props,...)
 Method: Instantiate from an existing CSR representation.
oski_matCSR_toski_ConvertMatReprToCSR (const void *mat, const oski_matcommon_t *props)
 Method: Convert to CSR format.
static int CopySubmat (const oski_submatMBCSR_t *A, oski_submatMBCSR_t *B)
static void DestroySubmat (oski_submatMBCSR_t *const A)
 Destroys any memory allocated for the fields of a submatrix.
static void DestroySubmatBCSR (oski_matBCSR_t *A)
 Free BCSR matrix representation.
void oski_DestroyMatRepr (void *mat)
 Method: Destroy matrix type-specific representation.
void * oski_CopyMatRepr (const void *mat, const oski_matcommon_t *props)
 Method: Duplicate a matrix representation.
int oski_CreateLuaMatReprFromCSR (lua_State *L)
 Matrix-type specific method to convert from a CSR matrix, with arguments passed on the Lua stack.
void oski_EnableMBCSRMatTransMatMult (oski_matMBCSR_t *A, int v)
void oski_EnableMBCSRMatMultAndMatMult (oski_matMBCSR_t *A, int v)
void oski_EnableMBCSRMatMultAndMatTransMult (oski_matMBCSR_t *A, int v)
void oski_EnableMBCSRMatPowMult (oski_matMBCSR_t *A, int v)
void oski_EnableMBCSRMatTransPowMult (oski_matMBCSR_t *A, int v)


Function Documentation

static int AllocateBlocks oski_index_t  num_block_rows,
oski_index_t  num_blocks,
oski_index_t  r,
oski_index_t  c,
oski_index_t **  p_ind,
oski_value_t **  p_blocks,
oski_value_t **  p_diagblocks
[static]
 

Allocate space for a given number of blocks, including their indices and diagonal blocks.

All returned arrays are initialized to 0.

Returns:
A non-zero value and sets the output pointers <==> the allocation was successful. Otherwise, returns 0 and leaves the output pointers unchanged.

static int ConvertFromCSR oski_index_t  m,
oski_index_t  n,
const oski_index_t *  ptr,
const oski_index_t *  ind,
const oski_value_t *  val,
oski_index_t  indbase,
oski_index_t  has_unit_diag_implicit,
oski_index_t  r,
oski_index_t  c,
oski_index_t *  p_M1,
oski_index_t **  p_ptr1,
oski_index_t **  p_ind1,
oski_value_t **  p_val1,
oski_value_t **  p_diag1,
oski_index_t *  p_M2,
oski_index_t *  p_r2,
oski_index_t **  p_ptr2,
oski_index_t **  p_ind2,
oski_value_t **  p_val2,
oski_value_t **  p_diag2,
oski_index_t *  p_num_rows_left
[static]
 

Convert the portions of the CSR matrix that correspond to partitions $A_1$ and $A_2$ in MBCSR format.

Returns:
The starting row index (0-based) in the input CSR data structure where partition $A_3$ should begin. The caller should call the BCSR routine to convert this part of the matrix.

static int ConvertSubmatFromCSR oski_index_t  M,
oski_index_t  n,
oski_index_t  i0,
oski_index_t  d0,
const oski_index_t *  ptr,
const oski_index_t *  ind,
const oski_value_t *  val,
oski_index_t  indbase,
oski_index_t  r,
oski_index_t  c,
oski_index_t **  p_bptr,
oski_index_t **  p_bind,
oski_value_t **  p_bval,
oski_value_t **  p_bdiag
[static]
 

Given an input matrix $A$ stored in CSR format, convert a submatrix $A(I,:)$ to $r\times c$ MBCSR format.

The caller must also select an arbitrary starting column of $A(I,:)$ to be the starting point for the block diagonal of $r\times r$ blocks.

Parameters:
[in] M Number of block rows in the subset $I$, i.e., $I$ consists of $M\cdot r$ rows.
[in] n Number of columns of $A$.
[in] i0 Starting row in the index range $I$.
[in] d0 First column index of the block diagonal.
[in] ptr Row pointers for $A$.
[in] ind Column indices for $A$.
[in] val Explicitly stored values for $A$.
[in] indbase Index base (0 or 1) for: i0, d0, ptr, ind.
[in] r Off-diagonal row block size, $r$.
[in] c Off-diagonal column block size, $c$.
[in,out] p_bptr Pointer to a pointer in which to store a newly allocated array of block-row pointers. The caller may set this pointer to NULL if none are desired.
[in,out] p_bind Pointer to a pointer in which to store a newly allocated array of block column indices. The caller may set this pointer to NULL if none are desired.
[in,out] p_bval Pointer to a pointer in which to store a newly allocated array of stored-value off-diagonal blocks. The caller may set this pointer to NULL if none are desired.
[in,out] p_bdiag Pointer to a pointer in which to store a newly allocated array of block diagonal values. The caller may set this pointer to NULL if none are desired.
Returns:
0 if any error occurs (typically on memory allocation failure) and leaves all output pointers unchanged, or 1 if successful with all non-NULL output pointers initialized.
Precondition:
$r$ divides $m$.

static void InitSubmatCSR const oski_matCSR_t A,
const oski_matcommon_t props,
oski_index_t  row_start,
oski_index_t  num_rows,
oski_matCSR_t A_sub,
oski_matcommon_t props_sub
[static]
 

Given a CSR matrix $A$, compute a shallow copy corresponding to a subset of the rows of $A$.

Precondition:
A != NULL && A_sub != NULL

static void MirrorDiagBlocks mirrordir_t  dir,
oski_value_t *  blocks,
oski_index_t  num_blocks,
oski_index_t  b
[static]
 

For each diagonal block $B$ of a matrix which is either symmetric or Hermitian, store $B$ using full-storage such that $B = \mathrm{op}(B)$ where $\mathrm{op}(B) \in \{B^T, B^H\}$, as appropriate.

Parameters:
[in] blocks Array of r x r blocks.
[in] num_blocks Number of blocks in 'blocks'.
[in] b Block size.
[in] op Desired transpose operation (OP_TRANS, OP_CONJ_TRANS).
[in] dir Direction in which to mirror the block.
Precondition:
The input parameter dir is valid if A is not NULL. If A is NULL or has no diagonal, or if op is not one of {OP_TRANS, OP_CONJ_TRANS}, returns taking no action.

static oski_index_t ScatterBlockRow const oski_index_t *  ptr,
const oski_index_t *  ind,
const oski_value_t *  val,
oski_index_t  n,
oski_index_t  indbase,
oski_index_t  i0,
oski_index_t  r,
oski_index_t  c,
oski_index_t  d0,
oski_index_t *  has_block_col,
oski_index_t *  inds,
oski_value_t *  blocks,
oski_value_t *  diag
[static]
 

Scatter.

..

Parameters:
[in] ptr CSR row pointers, in the base specified by 'indbase'.
[in] ind CSR column indices, in the base specified by 'indbase'.
[in] val CSR explicitly stored values.
[in] n Maximum number of columns.
[in] indbase Index base (0 or 1).
[in] i0 Index of the first row in the block row to scatter, in the base specified by 'indbase'.
[in] r Row block size (i.e., number of rows in the block row starting at 'i0' to consider).
[in] c Column block size.
[in] d0 Index of the first column of the 'r x r' diagonal block, in the base specified by 'indbase'.
[in,out] has_block_col Array of flags indicating whether a given block exists in the block row being scattered.
[in,out] blocks Values of each block in the block row.
[in,out] diag Values of the diagonal block.
Precondition:
ptr != NULL && has_block_col != NULL
Todo:
Update documentation for this routine.

static void SetUnitDiag oski_index_t  num_blocks,
oski_index_t  block_size,
oski_value_t *  blocks
[static]
 

Given a packed array of $M$ $b\times b$ blocks, sets the diagonal entries of each block to 1.

Precondition:
If num_blocks > 0, then blocks != NULL.

static void UnscatterBlockRow const oski_index_t *  ptr,
const oski_index_t *  ind,
oski_index_t  indbase,
oski_index_t  i0,
oski_index_t  r,
oski_index_t  c,
oski_index_t  d0,
oski_index_t *  has_block_col
[static]
 

Unscatter.

..

Parameters:
[in] scatter_op SCATTER_RESET or SCATTER_SET.
[in] indbase Index base (0 or 1).
[in] ptr CSR row pointers, in the base specified by 'indbase'.
[in] ind CSR column indices, in the base specified by 'indbase'.
[in] val CSR explicitly stored values.
[in] i0 Index of the first row in the block row to scatter, in the base specified by 'indbase'.
[in] r Row block size (i.e., number of rows in the block row starting at 'i0' to consider).
[in] c Column block size.
[in] d0 Index of the first column of the 'r x r' diagonal block, in the base specified by 'indbase'.
[in,out] has_block_col Array of flags indicating whether a given block exists in the block row being scattered.
[in,out] blocks Values of each block in the block row.
[in,out] diag Values of the diagonal block.
Precondition:
ptr != NULL && has_block_col != NULL


Generated on Wed Sep 19 16:41:22 2007 for BeBOP Optimized Sparse Kernel Interface Library by  doxygen 1.4.6