Boost logo

Boost :

From: Janek Kozicki (janek.listy.mailowe_at_[hidden])
Date: 2021-01-07 13:24:07


Cem Bassoy via Boost said: (by the date of Thu, 7 Jan 2021 12:43:47 +0100)

> Have a look @ https://godbolt.org/z/cMKc9T

wow, This is very good. Thank you.

> You can get the pointer (like for vector) to the underlying contiguous
> memory (you do not own the memory):

This is exactly what I need. FFT does in-place transform by modifying the memory.

> using format_t = boost::numeric::ublas::column_major;

FFT does its work on row_major format. You have this one so
I assume that you also have the other one ;)

However I needed to write a custom memory allocator (also very crude):

https://gitlab.com/cosurgi/trunk/-/blob/addQuantumMechanics_FixEnum_FixRebase1/lib/base/NDimTable.hpp#L96
https://gitlab.com/cosurgi/trunk/-/blob/addQuantumMechanics_FixEnum_FixRebase1/lib/base/FFTW3_Allocator.hpp

Can I provide a custom allocator to tensor_t ?

In fact maybe during past 5 years some better C++ interface for
libfftw appeared. I will have to check :)
maybe even boost library has an FFT interface? :)

If not then I will need to refactor this crude FFTW3_Allocator memory allocator.

> using tensor_t = boost::numeric::ublas::tensor<float,format_t>;
> auto A = tensor_t(shape{3,4,2},2);auto ap = A.data();
> You can also use the standard c++ library for convenience:
> std::for_each(A.begin(), A.end(), [](auto& a){ ++a; });
> If you do not want to use the Einstein-notation, you can as well use either

I'm definitely going to use the Einstein notation :)

> the prod function:
> // C3(i,l1,l2) = A(i,j,k)*T1(l1,j)*T2(l2,k);
> q = 3u;
> tensor_t C3 = prod(prod(A,matrix_t(m+1,n[q-2],1),q-1),matrix_t(m+2,n[q-1],1),q);
>
> "prod" uses internally a C-like interface which will not allocate memory
> at all.
>
> ttm(m, p,
> c.data(), c.extents().data(), c.strides().data(),
> a.data(), a.extents().data(), a.strides().data(),
> bb, nb.data(), wb.data());

I have another question about indexing the tensor.

Can I have a custom index redirection? I mean, when I type code to
access zero-th element of 1D array:

tensor[0] = ... ;

I mean to access the element which is located exactly in the middle
of the reserved memory region. This is because libfftw implementation
is not compatible with other parts of the quantum dynamic time
propagation algorithm. This incompatibility is possible because FT is
intrinsically periodic. Currently I have to use this function
shiftByHalf():

https://gitlab.com/cosurgi/trunk/-/blob/addQuantumMechanics_FixEnum_FixRebase1/lib/base/NDimTable.hpp#L1107

Which shifts by half an N-dimensional table. So that libfftw sees the
data which it will process correctly. And doing a single calculation
step is rather slow because after doing FFT it has to be shifted back:

https://gitlab.com/cosurgi/trunk/-/blob/addQuantumMechanics_FixEnum_FixRebase1/lib/base/NDimTable.hpp#L1436

this makes calcuations very slow. If I could use some kind of index
redirection, that will make all iterators treat the data as being
shifted by half:

 * zero-th element: in the middle of reserved memory.
 * half: at the end of reserved memory
 * half+1: at the beginning of reserved memory

then all other parts of my algorithm will not need to be modified,
because they solely work with iterators.

(Also I need to check if it's now possible to tell FFT to treat data
differently, it wasn't possible 5 years ago, then I wouldn't need all
these complications with indexing)

Thank you, your code is very promising.
Janek

-- 
# Janek Kozicki                              http://janek.kozicki.pl/

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk