[petsc-users] Transform of algorithm containing zgemv/FFT/Slicing into PETSc-functions

Barry Smith bsmith at petsc.dev
Mon Dec 14 22:01:49 CST 2020


  I think you can again use MatDenseGetArray() and do the copies directly respecting the shift that you desire. Each process will just do the 
local rows so you need not worry about parallelism. 

  I think it may be as simple as get the array pointer for A, shift it by number of local rows * number of columns then do a PetscArraycpy() to copy the B values into the shifted location in A.

Barry
 

> On Dec 14, 2020, at 5:18 PM, Roland Richter <roland.richter at ntnu.no> wrote:
> 
> Dear all,
> 
> I am currently working on the transformation of an algorithm implemented using armadillo into PETSc. It is a forward/backward transformation, and boils down to the following steps (for the forward transformation):
> 
> Assumed I have matrices A and B, defined as 
> 
> A =  |aa ab ac ad|
>         |ae af ag ah|
>         |ai aj ak al|
> 
> B =  |ba bb bc|
>         |be bf bg|
>         |bi bj bk|
> 
> with the number of rows in A and B always equal, but number of columns in B always less or equal than half the number of columns in A (Example here is only for demonstration, I am aware of that 3 is not smaller or equal than 2).
> 
> Moreover, I have vectors x and y, with x defined as
> 
> x = |xa xb xc xd|
> 
> and y defined as 
> 
> y = |ya yb yc|
> 
> The number of elements in x corresponds to the number of columns in A, and the number of elements y accordingly correspond to the number of columns in B.
> 
> Now, the transformation can be described as
> 
> Set all values in A to zero
> Copy B into A with an offset of a0:
> A(a0 = 1) = |0 ba bb bc|
>                     |0 be bf bg|
>                     |0 bi bj bk|
> Multiply every row in A elementwise with y, including offset, resulting in
> A(a0 = 1) = |0 ba*ya bb*yb bc*yc|
>                     |0 be*ya bf*yb bg*yc|
>                     |0 bi*ya bj*yb bk*yc|
> Apply a 1d-FFT over each row of A, resulting in A'
> Multiply every row in A' elementwise with x, resulting in 
> A'(a0 = 1) = |aa'*xa (ba*ya)'*xb (bb*yb)'*xc (bc*yc)'*xd|
>                     |ae'*xa (be*ya)'*xb (bf*yb)'*xc (bg*yc)'*xd|
>                     |ai'*xa (bi*ya)'*xb (bj*yb)'*xc (bk*yc)'*xd|
> Based on earlier questions, I already know how to apply a vector to each row of a matrix (by using .diag()) and how to apply an FFT over each row of a distributed matrix by using FFTW. Still, I am not aware of a method for copying B into A with an offset, and therefore I would have to iterate over each row for the copy process, which might slow down the process. Therefore, is there a way I could make this process more efficient using the built-in functions in PETSc? Unfortunately, I am not that familiar with all       the functions yet.
> 
> Thanks!
> 
> Roland
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20201214/1c828b33/attachment.html>


More information about the petsc-users mailing list