<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Tue, 11 Sep 2018 at 16:47, Dener, Alp <<a href="mailto:adener@anl.gov">adener@anl.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="auto">
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.</div></blockquote><div><br></div><div>Your definition of subtype is not one used almost everywhere else.</div><div><br></div><div>The matrix type should be just MATLMVM (corresponding to a single new entry of the MatType typedef), </div><div><br></div><div>Then you do the following, and</div><div><div><br></div><div>/*J</div><div> MatLMVMType - String with the name of a LMVM matrix subtype</div><div><br></div><div> Level: beginner</div><div><br></div><div>.seealso: MatLMVMSetType(), MatSetType(), Mat</div><div>J*/</div></div><div><div>typedef const char* MatLMVMType;</div></div><div>#define MATLMVMDFP "lmvmdfp"<br></div><div><div>#define MATLMVMBFGS "lmvmbfgs"</div><div>#define MATLMVMSR1 "lmvmsr1"</div><div>#define MATLMVMBRDN "lmvmbrdn"</div><div>#define MATLMVMBADBRDN "lmvmbadbrdn"</div><div>#define MATLMVMSYMBRDN "lmvmsymbrdn"</div><div>#define MATLMVMSYMBADBRDN "lmvmsymbadbrdn"</div><div>#define MATLMVMDIAGBRDN "lmvmdiagbrdn"</div></div><div><br></div><div>Then you need a couple API function</div><div><br></div><div>PetscErrorCode MatLMVMSetType(Mat,MatLMVMType); // implement this one using PetscTryMethod() macro</div><div><div>PetscErrorCode MatLMVMGetType(Mat,MatLMVMType); // implement this one using PetscUseMethod() macro</div><br class="gmail-Apple-interchange-newline"></div><div><div>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().<br></div><br class="gmail-Apple-interchange-newline"></div><div><div>And now you can get rid of all these public API functions:</div><div><div>PETSC_EXTERN PetscErrorCode MatCreateLMVMDFP(MPI_Comm,PetscInt,PetscInt,Mat*);<br></div><div>PETSC_EXTERN PetscErrorCode MatCreateLMVMBFGS(MPI_Comm,PetscInt,PetscInt,Mat*);</div><div>PETSC_EXTERN PetscErrorCode MatCreateLMVMSR1(MPI_Comm,PetscInt,PetscInt,Mat*);</div><div>PETSC_EXTERN PetscErrorCode MatCreateLMVMBrdn(MPI_Comm,PetscInt,PetscInt,Mat*);</div><div>PETSC_EXTERN PetscErrorCode MatCreateLMVMBadBrdn(MPI_Comm,PetscInt,PetscInt,Mat*);</div><div>PETSC_EXTERN PetscErrorCode MatCreateLMVMSymBrdn(MPI_Comm,PetscInt,PetscInt,Mat*);</div><div>PETSC_EXTERN PetscErrorCode MatCreateLMVMSymBadBrdn(MPI_Comm,PetscInt,PetscInt,Mat*);</div><div>PETSC_EXTERN PetscErrorCode MatCreateLMVMDiagBrdn(MPI_Comm,PetscInt,PetscInt,Mat*);</div></div><br class="gmail-Apple-interchange-newline"></div><div>For convenience, you just add an single quick constructor:</div><div>MatCreateLMVMD(MPI_Comm,PetscInt,PetscInt,PetscLMVMType,Mat*)<br></div><div>(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)</div><div><br></div><div>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:</div><div><br></div><div> "How Barry the Dark Lord would do it??"...</div><div><br></div><div>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.</div><div><br></div></div><div><br></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature">Lisandro Dalcin<br>============<br>Research Scientist<br>Computer, Electrical and Mathematical Sciences & Engineering (CEMSE)<br>Extreme Computing Research Center (ECRC)<br>King Abdullah University of Science and Technology (KAUST)<br><a href="http://ecrc.kaust.edu.sa/" target="_blank">http://ecrc.kaust.edu.sa/</a><br><br>4700 King Abdullah University of Science and Technology<br>al-Khawarizmi Bldg (Bldg 1), Office # 0109<br>Thuwal 23955-6900, Kingdom of Saudi Arabia<br><a href="http://www.kaust.edu.sa" target="_blank">http://www.kaust.edu.sa</a><br><br>Office Phone: +966 12 808-0459</div></div></div></div></div></div></div>