[petsc-users] copy vector into a matrix

Michael Povolotskyi mpovolot at purdue.edu
Wed Apr 3 12:58:16 CDT 2013


On 04/03/2013 01:52 PM, Jed Brown wrote:
> On Wed, Apr 3, 2013 at 11:55 AM, Michael Povolotskyi 
> <mpovolot at purdue.edu <mailto:mpovolot at purdue.edu>> wrote:
>
>     Dear PETSc developers,
>     I have a following question:
>
>     I have a dense serial matrix of M x N size
>     I have a N vectors of size M.
>     I need to copy content of those vectors to the columns of the matrix.
>     What is the fastest way of doing this?
>
>
> MatGetLocalSize(A,&m,NULL);
> MatDenseGetArray(A,&a);
> for (i=0; i<nvecs; i++) {
>   const PetscScalar *x;
>   VecGetArrayRead(X[i],&x);
>   PetscMemcpy(a+i*m,x,m*sizeof(PetscScalar));
>   VecRestoreArrayRead(X[i],&x);
> }
> MatDenseRestoreArray(A,&a);
>
Thank you for help.
Michael.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20130403/835c1471/attachment.html>


More information about the petsc-users mailing list