1

In FLENS I want to implement "custom" storage (that is, to be able to provide the pointer to actual data and to be in charge of the memory management for the storage).

A matrix that manages its buffer is defined like this, for example:

typedef flens::GeMatrix<flens::FullStorage<double, flens::ColMajor> >  M;

Later, one can use the matrices like this:

M m1;
M m2;
M m3;
/* initialise the matrices */
m3 = m1 * m2;

To do the same thing with a matrix type that gives access to internal buffer one may implement, say, GhostStorage just the way FullStorage is implemented, with the addition of an init() method that allows setting the internal pointer (full implementation is too long to paste here):

void
init(IndexType numRows, IndexType numCols,
      IndexType firstRow = I::defaultIndexBase,
      IndexType firstCol = I::defaultIndexBase,
      ElementType *p_data = NULL )
{
  _data = p_data;
  _numRows = numRows;
  _numCols = numCols;
  _firstRow = firstRow;
  _firstCol = firstCol;
  ASSERT(_numRows>=0);
  ASSERT(_numCols>=0);
}

After defining types like this:

typedef flens::GhostStorage<double, flens::ColMajor> GhostEng;
class MGhost : public flens::GeMatrix<GhostEng>
{
    public:
    void
    init(IndexType numRows, IndexType numCols,
    IndexType firstRow,
    IndexType firstCol,
    ElementType *p_data = NULL )
  {
    engine().init(numRows,numCols,firstRow,firstCol,p_data);
  }

};

I would expect that same operation as above should be possible:

MGhost mg1;
MGhost mg2;
MGhost mg3;
/* initialise the matrices using the init() method */
mg3 = mg1 * mg2;

However the compiler complains in this case:

no known conversion for argument 1 from 'const flens::MatrixClosure >, flens::GeMatrix > >' to 'const MGhost&'

FLENS author provides guidance about implementing your custom type of matrix, but I'm using an already defined matrix type here - the flens::GeMatrix.

Bottom line, the question is: how does one implement a matrix in FLENS that allows manipulating the internal buffer and high level interaction like m3 = m1 * m2?

1 Answer 1

2

There is no need to write your own class, FLENS already provides the functionality:

typedef FullStorageView<double, ColMajor>  FSView;
typedef GeMatrix<FSView>                   GeMatrixView;
GeMatrixView  A = FSView(numRows, numCols, data, ldA);

Here, data is the pointer to your allocated memory. This is explained is in detail in the tutorial. Besides, there is a mailing list where questions are answered quite fast.

1
  • Hello, Jack, thanks for your answer. It has been a while since I posted this question. I will look into it and mark your answer as the correct one (or not) at that time. +1 for the info.
    – Nicu Tofan
    Dec 16, 2013 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.