tahoma2d/toonz/sources/include/tlin/tlin_superlu_wrap.h

132 lines
4.8 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef TLIN_SUPERLU_WRAP
#define TLIN_SUPERLU_WRAP
#include "tcommon.h"
#undef DVAPI
#undef DVVAR
#ifdef TNZEXT_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
#include "tlin_matrix.h"
#include "tlin_sparsemat.h"
/*
EXPLANATION:
The tlin_superlu_wrap files implement wrappers to the SuperLU library.
They are used to provide utility interfaces to SuperLU from tlin, and
overcome name collisions (in particular, SuperLU is pure C - no
namespaces, and redefines DOUBLES and such already defined
from <windows.h>...)
*/
//================================================================================
2016-06-15 18:43:10 +12:00
namespace tlin {
2016-03-19 06:57:51 +13:00
//*****************************************************************************
// Forward declarations
//*****************************************************************************
/*
The following structs are heirs of the actual SuperLU counterparts - this is
necessary due to the "typedef struct {..} _Name" syntax that prevents forward
declaration of "_Name" (different base types).
No member is added to the original type - so they are accessible exactly the
same way.
*/
struct SuperMatrix;
struct superlu_options_t;
struct SuperFactors {
2016-06-15 18:43:10 +12:00
SuperMatrix *L;
SuperMatrix *U;
int *perm_c;
int *perm_r;
2016-03-19 06:57:51 +13:00
};
//*****************************************************************************
// SuperLU-specific routines
//*****************************************************************************
2016-06-15 18:43:10 +12:00
void DVAPI allocS(SuperMatrix *&A, int rows, int cols,
int nnz); //!< Allocates A in NC (sparse) format
void DVAPI allocD(SuperMatrix *&A, int rows,
int cols); //!< Allocates A in DN (dense) format
2016-03-19 06:57:51 +13:00
//! Allocates A with externally supplied initializer values
2016-06-15 18:43:10 +12:00
void DVAPI allocS(SuperMatrix *&A, int rows, int cols, int nnz, int *colptr,
int *rowind, double *values);
2016-03-19 06:57:51 +13:00
void DVAPI allocD(SuperMatrix *&A, int rows, int cols, int lda, double *values);
2016-06-15 18:43:10 +12:00
void DVAPI freeS(SuperMatrix *A); //!< Frees A allocated with allocS
void DVAPI freeD(SuperMatrix *A); //!< Frees A allocated with allocD
void DVAPI freeF(SuperFactors *F); //!< Frees F returned by factorize
2016-03-19 06:57:51 +13:00
//! Initializes a local SuperMatrix (ie created on stack).
void DVAPI createS(SuperMatrix &A, int rows, int cols, int nnz);
void DVAPI createD(SuperMatrix &A, int rows, int cols);
//! Initializes a local SuperMatrix with externally supplied data.
2016-06-15 18:43:10 +12:00
void DVAPI createS(SuperMatrix &A, int rows, int cols, int nnz, int *colptr,
int *rowind, double *values);
2016-03-19 06:57:51 +13:00
void DVAPI createD(SuperMatrix &A, int rows, int cols, int lda, double *values);
2016-06-15 18:43:10 +12:00
//! Destroys A. To be used when A is local (ie with create). Can be told to
//! spare data deallocation.
2016-03-19 06:57:51 +13:00
void DVAPI destroyS(SuperMatrix &A, bool destroyData = true);
void DVAPI destroyD(SuperMatrix &A, bool destroyData = true);
2016-06-15 18:43:10 +12:00
void DVAPI readDN(SuperMatrix *A, int &lda,
double *&values); //!< Reads values ptr from A
void DVAPI readNC(SuperMatrix *A, int &nnz, int *&colptr, int *&rowind,
double *&values); //!< Reads array ptrs from A
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
//! Copies m's content to A. A could be either 0 or an already initialized
//! SuperMatrix.
2016-03-19 06:57:51 +13:00
void DVAPI traduceS(tlin::sparse_matrix<double> &m, SuperMatrix *&A);
void DVAPI traduceD(const tlin::matrix<double> &m, SuperMatrix *&A);
void DVAPI traduceD(const tlin::sparse_matrix<double> &m, SuperMatrix *&A);
/*!
2016-06-15 18:43:10 +12:00
Returns A's factorization F, or 0 if the factorization failed (due to A's
singularity,
2016-03-19 06:57:51 +13:00
or memory shortage - see SuperLU docs for details).
*/
2016-06-15 18:43:10 +12:00
void DVAPI factorize(SuperMatrix *A, SuperFactors *&F,
superlu_options_t *opt = 0);
2016-03-19 06:57:51 +13:00
void DVAPI solve(SuperFactors *F, SuperMatrix *BX, superlu_options_t *opt = 0);
2016-06-15 18:43:10 +12:00
void DVAPI solve(SuperFactors *F, SuperMatrix *B, SuperMatrix *&X,
superlu_options_t *opt = 0);
2016-03-19 06:57:51 +13:00
void DVAPI solve(SuperMatrix *A, SuperMatrix *BX, superlu_options_t *opt = 0);
2016-06-15 18:43:10 +12:00
void DVAPI solve(SuperMatrix *A, SuperMatrix *B, SuperMatrix *&X,
superlu_options_t *opt = 0);
2016-03-19 06:57:51 +13:00
void DVAPI solve(SuperFactors *F, double *bx, superlu_options_t *opt = 0);
2016-06-15 18:43:10 +12:00
void DVAPI solve(SuperFactors *F, double *b, double *&x,
superlu_options_t *opt = 0);
2016-03-19 06:57:51 +13:00
void DVAPI solve(SuperMatrix *A, double *bx, superlu_options_t *opt = 0);
2016-06-15 18:43:10 +12:00
void DVAPI solve(SuperMatrix *A, double *b, double *&x,
superlu_options_t *opt = 0);
2016-03-19 06:57:51 +13:00
//*****************************************************************************
// BLAS-related routines
//*****************************************************************************
void DVAPI multiplyS(const SuperMatrix *A, const double *v, double *&Av);
void DVAPI multiplyD(const SuperMatrix *A, const double *v, double *&Av);
2016-06-15 18:43:10 +12:00
} // namespace tlin
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
#endif // TLIN_SUPERLU_WRAP