[petsc-dev] MATLMVM
Lisandro Dalcin
dalcinl at gmail.com
Tue Sep 11 10:12:06 CDT 2018
On Tue, 11 Sep 2018 at 16:47, Dener, Alp <adener at anl.gov> wrote:
> 1 base type and 8 subtypes. If there’s a better convention/structure to do
> this in PETSc, I’d be happy to get a refactoring done ASAP this week so
> that it’s cleaner in the release.
>
Your definition of subtype is not one used almost everywhere else.
The matrix type should be just MATLMVM (corresponding to a single new entry
of the MatType typedef),
Then you do the following, and
/*J
MatLMVMType - String with the name of a LMVM matrix subtype
Level: beginner
.seealso: MatLMVMSetType(), MatSetType(), Mat
J*/
typedef const char* MatLMVMType;
#define MATLMVMDFP "lmvmdfp"
#define MATLMVMBFGS "lmvmbfgs"
#define MATLMVMSR1 "lmvmsr1"
#define MATLMVMBRDN "lmvmbrdn"
#define MATLMVMBADBRDN "lmvmbadbrdn"
#define MATLMVMSYMBRDN "lmvmsymbrdn"
#define MATLMVMSYMBADBRDN "lmvmsymbadbrdn"
#define MATLMVMDIAGBRDN "lmvmdiagbrdn"
Then you need a couple API function
PetscErrorCode MatLMVMSetType(Mat,MatLMVMType); // implement this one
using PetscTryMethod() macro
PetscErrorCode MatLMVMGetType(Mat,MatLMVMType); // implement this one using
PetscUseMethod() macro
After you create an LMVM matrix and the subtype is already set with the
call above, you have to manage for MatSetUp() to properly fill in the
virtual table (mat->ops structure). Or maybe you can do the filling right
way in the call to MatLMVMSetType().
And now you can get rid of all these public API functions:
PETSC_EXTERN PetscErrorCode
MatCreateLMVMDFP(MPI_Comm,PetscInt,PetscInt,Mat*);
PETSC_EXTERN PetscErrorCode
MatCreateLMVMBFGS(MPI_Comm,PetscInt,PetscInt,Mat*);
PETSC_EXTERN PetscErrorCode
MatCreateLMVMSR1(MPI_Comm,PetscInt,PetscInt,Mat*);
PETSC_EXTERN PetscErrorCode
MatCreateLMVMBrdn(MPI_Comm,PetscInt,PetscInt,Mat*);
PETSC_EXTERN PetscErrorCode
MatCreateLMVMBadBrdn(MPI_Comm,PetscInt,PetscInt,Mat*);
PETSC_EXTERN PetscErrorCode
MatCreateLMVMSymBrdn(MPI_Comm,PetscInt,PetscInt,Mat*);
PETSC_EXTERN PetscErrorCode
MatCreateLMVMSymBadBrdn(MPI_Comm,PetscInt,PetscInt,Mat*);
PETSC_EXTERN PetscErrorCode
MatCreateLMVMDiagBrdn(MPI_Comm,PetscInt,PetscInt,Mat*);
For convenience, you just add an single quick constructor:
MatCreateLMVMD(MPI_Comm,PetscInt,PetscInt,PetscLMVMType,Mat*)
(you should accept NULL for PetscLMVMType and decide what to do in that
case, maybe set a default subtype, or just not set the subtype, whatever,
and you document the behavior)
I don't want to be pendantic and pretend to have a remove brain reader, but
once you get to know PETSc, the basic rule to follow is quite simple:
"How Barry the Dark Lord would do it??"...
and the answer should always revolve around reducing top level API
complexity. Then you do it that way, and it's going to be the right way.
--
Lisandro Dalcin
============
Research Scientist
Computer, Electrical and Mathematical Sciences & Engineering (CEMSE)
Extreme Computing Research Center (ECRC)
King Abdullah University of Science and Technology (KAUST)
http://ecrc.kaust.edu.sa/
4700 King Abdullah University of Science and Technology
al-Khawarizmi Bldg (Bldg 1), Office # 0109
Thuwal 23955-6900, Kingdom of Saudi Arabia
http://www.kaust.edu.sa
Office Phone: +966 12 808-0459
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20180911/7c77c06e/attachment.html>
More information about the petsc-dev
mailing list