plumed / plumed2

Development version of plumed 2
https://www.plumed.org
GNU Lesser General Public License v3.0
357 stars 283 forks source link

Typed vector and tensor #1092

Open Iximiel opened 3 months ago

Iximiel commented 3 months ago
Description

I started to work on this in the context of #1076 and in sync with what I did with #1075. My idea was to set up some types of plumed to be more flexible and usable in contexts like sycl, cuda, openACC or targetted openMP. Then I dropped this for a while, but I thought it could be interesting to bring it out again.

Most of the problems this new approach gives are in the friend functions within the vector and the tensor, they give strange warnings. I think due to the fact that I am declaring friend functions like template<typename U, unsigned m> U dotProduct(const VectorGeneric<U, m>&,const VectorGeneric<U, m>&); to a template<typename T, unsigned n> VectorGeneric<T, n>, with all types and all dimensions. On one hand, I do not think is a problem, but on the other hand, it does make me a little uncomfortable.

If I understood correctly those functions are declared friend to appear in the documentation page of Tensor/Vector, maybe by putting \ingroup TOOLBOX in their docstring they will appear in the toolbox, or in another doxygen module and we can remove the friend declarations.

In any case the part with the friend-declared functions must be finished because I applied two different approaches in Vector and Tensor: in tensor, I eliminated the friend nearly all the friend declarations because I was having an hard time in trying to compile with all of them.


I also added a .data() method to access the underline array in both classes. This new method should be used in place of the various &variable[0] to get the pointer to the first element of the array. But as now, I did not refactored it in the code (but I am using something similar in #1075 ).

Target release

I would like my code to appear in release 2.10

Type of contribution?
Copyright
Tests
GiovanniBussi commented 3 months ago

Quick note, replace VectorGeneric<T,N> with VectorTyped<T,N> to avoid breaking existing code, as we discussed

Iximiel commented 3 months ago

Quick note, replace VectorGeneric<T,N> with VectorTyped<T,N> to avoid breaking existing code, as we discussed

I force-pushed to align with existing code, and to have clearer commits

I have to set up a few benchmarks and redo the documentation, to keep the not-member functions in the wanted pages