Seeking Advice on Implementing Solver with Trillinos and PETSc Vectors

48 views
Skip to first unread message

Hussein Shaito

unread,
Feb 21, 2025, 6:48:21 AM2/21/25
to deal.II User Group
Dear community,

I am trying to write a solver and I want to support both trillinos and petsc vectors at runtime.
I am doing this by having the vector type as a class template for my solver.
Since you guys are more experienced than I am, is there a disadvantage for this approach? Will this bloat my compile time if my code grows? Would anyone recommend something else?
I know I can do an #ifdef for either pets. and trilinos like in step40 and compile but I would still want to know what you guys suggest.

Best regards,
Hussein.

Daniel Arndt

unread,
Feb 21, 2025, 8:16:27 AM2/21/25
to dea...@googlegroups.com
Hussein,

There are certainly some advantages to use a template for the vector
type, mostly because it allows you try out multiple but I wouldn't be
surprised if you settle on one or the other in the end. There really
isn't much of a difference using the approach taken in step-40 via
preprocessor guarded alias namespaces or via templates. I would
probably go with templates, though, since that feels more natural for
C++. I wouldn't expect much of a compile time overhead either way. In
the end, you only compile what you use.

Best,
Daniel
> --
> The deal.II project is located at http://www.dealii.org/
> For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en
> ---
> You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to dealii+un...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/dealii/1fa81747-f79f-4e6b-887a-d624f7acd306n%40googlegroups.com.

blais...@gmail.com

unread,
Feb 21, 2025, 8:18:49 AM2/21/25
to deal.II User Group
Dear Hussein,
It's not a big deal to have the VectorType as a class template. The only thing you will get is that every function / member of the class will be compiled twice (once for every vector type).
In the software my group develops (lethe https://github.com/chaos-polymtl/lethe), some classes are instantiated with three vector types (Trilinos::block, Trilinos, dealii parallel vectors). This for sure increase compile time, but on a modern machine we can still compile the entire 100k line C++ code in less than 3-4 minutes, so it's not a big deal.
i would not worry about this. It is better to integrate this kind of flexibility from the beginning. I would advise you to start also looking into the deal.II parallel vectors. They are compatible with the Trilinos and PETSC solvers and they work quite well. This templating of the vector type actually saved us tremendously when we started to develop our matrix free solver.

TLDR: Use a template parameter, compile both versions, you won't suffer from it.

Feel free to reach out if you have any questions.

Hussein Shaito

unread,
Feb 22, 2025, 11:04:09 AM2/22/25
to deal.II User Group

Hello,


Thank you both for the quick response and useful advice! 


Wish you a great weekend 


Regards,

Hussein

Reply all
Reply to author
Forward
0 new messages