[petsc-users] Forming a matrix from vectors

Zhang, Hong hongzhang at anl.gov
Mon Feb 17 13:44:14 CST 2020


You can create a dense matrix and use VecPlaceArray() to take a column out of the matrix as a vector. For example,

MatCreateDense()
MatDenseGetColumn(A,0,col)
VecPlaceArray(v,col)

… // fill in the vector with values

VecResetArray(v)
MatDenseRestoreColumn(A,&col)

Hong (Mr.)

> On Feb 17, 2020, at 2:35 AM, Eda Oktay <eda.oktay at metu.edu.tr> wrote:
> 
> Hello all,
> 
> I am trying to form a matrix whose columns are eigenvectors I have calculated before U = [v1,v2,v3]. Is there any easy way of forming this matrix? My matrix should be parallel and I have created vectors as below, where nev i s the number of requested eigenvalues. So each V[i] represents an eigenvector and I should form a matrix by using V.
> 
> Vec *V;
>   VecDuplicateVecs(vr,nev,&V); 
>   for (i=0; i<nev;i++){
>   ierr = EPSGetEigenpair(eps,i,&kr,NULL,V[i],NULL);  
>   }
> 
> Thanks!
> 
> Eda



More information about the petsc-users mailing list