[petsc-users] inserting vector into row of dense matrix
bsmith at mcs.anl.gov
Wed Apr 23 21:04:06 CDT 2014
The problem is that MatMPIDense stores each row on a single process; while the solution in DMGetGlobalVector() will be spread over all processes. Thus you could use MatSetValues() as you have done to put the values in but it will be terribly inefficient.
What I suggest is to instead store the solutions in the COLUMNS of the dense matrix and use MatMultTranspose() to do the matrix-vector products you wish to do later. Then transferring from the DMGetGlobalVector to a column of the MatMPIDense will be a completely local copy. You can use MatDenseGetF90() to give you access to the matrix and VecGetArrayF90 to get access to the global vector and then just copy the values from the vec to the particular column of the dense matrix you want to put them. Each process will simply copy over its part of the global vector to its part of the column of the dense matrix.
On Apr 23, 2014, at 8:48 PM, Randall Mackie <rlmackie862 at gmail.com> wrote:
> 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