[petsc-users] copy vector into a matrix
    Jed Brown 
    jedbrown at mcs.anl.gov
       
    Wed Apr  3 12:52:05 CDT 2013
    
    
  
On Wed, Apr 3, 2013 at 11:55 AM, Michael Povolotskyi <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);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20130403/2844da83/attachment.html>
    
    
More information about the petsc-users
mailing list