[petsc-users] inserting vector into row of dense matrix

Randall Mackie rlmackie862 at gmail.com
Wed Apr 23 20:48:10 CDT 2014

I have a 3D rectangular grid over which I am doing some computations. I have created a 3D DA for that grid, and I can put the results of the computations into a global vector obtained via DMGetGlobalVector.

Now, I need to do these computations for several realizations, and I want to keep all the results in order to do matrix-vector multiplies later.

So, I have created a dense parallel matrix using MatCreateDense, but specifying the same layout for the columns as for the global vector on the DA (using VecGetLocalSize).

My question is what is the best way to insert the global vector obtained from the DA into a row of the dense parallel matrix?

My first attempt was to simply use MatSetValues on the values on each processor as I computed them (rather than putting into a global vector), then using MatAssemblyBegin/End and that worked fine, but I thought maybe that wasn't the most efficient way to do it.

My next thought was to  use VecGetArrayF90 to access the elements of the global vector,  and MatDenseGetArrayF90 on the dense matrix, and then just copy the values over (as I read on some email in the archives), but I suspect I am not using MatDenseGetArrayF90 correctly because I am getting a memory corruption error.

I wonder if MatDenseGetArrayF90 can be used in the way I am thinking, and if it can, then it must mean that I am not doing something correctly. Or is there a better way to insert an entire vector into each row of a dense parallel matrix?

Thanks, Randy 

More information about the petsc-users mailing list