[petsc-users] Convert matrix to 1-D array

Hong hzhang at mcs.anl.gov
Thu Aug 21 21:04:31 CDT 2014


You can call
MatGetSubMatrices()
http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatGetSubMatrices.html

Hong

On Thu, Aug 21, 2014 at 6:25 PM, priyank patel <priyankpatel22 at live.com> wrote:
> hi,
>
> Ya this will give me only local entries. But what if I want the complete matrix in one array. So that I can use it with the lapack routines??
>
> Thanks
> Priyank
>
> On 19-Aug-2014, at 2:09 pm, Hong <hzhang at mcs.anl.gov> wrote:
>
>> Priyank:
>> The product C = A * B is a dense matrix in petsc mpidense format.
>> You should use MatDenseGetArray()
>> http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatDenseGetArray.html
>>
>> which gives 1D array of local entries of C.
>>
>> I notice you are using petsc-3.3. Please update to the latest version of petsc.
>>
>> Hong
>>
>>> Hello,
>>>
>>> I have a matrix generated from matrix matrix multiplication. I want that
>>> matrix to convert to 1 dimensional array. my code is as below
>>>
>>> #####################################################
>>> //Multiplication A * B (A is MPIAIJ & B is MPIDENSE)
>>> MatMatMult(A, B,  MAT_INITIAL_MATRIX,  PETSC_DEFAULT, &C);
>>> MatView(C,PETSC_VIEWER_STDOUT_WORLD);
>>> //Convert Matrix C to 1D vector h_C
>>> for(i = 0; i < m; i++)
>>> {
>>> for(j = 0; j < k; j++)
>>> {
>>> ierr = MatGetValues(C, 1, &i, 1, &j, &h_C[IDX2C(i,j,end1)]);CHKERRQ(ierr);
>>> }
>>> }
>>> //printArray(h_B, m, k, "h_B");
>>> printArray(h_C, m, k, "A * X0");
>>> #####################################################
>>> when I tried the routine MatGetValues() it shows some error as below
>>>
>>> #####################################################
>>> --------------------- Error Message ------------------------------------
>>> [1]PETSC ERROR: No support for this operation for this object type!
>>> [1]PETSC ERROR: Only local values currently supported!
>>> [1]PETSC ERROR:
>>> ------------------------------------------------------------------------
>>> [1]PETSC ERROR: Petsc Release Version 3.3.0, Patch 0, Tue Jun  5 14:20:42
>>> CDT 2012
>>> [1]PETSC ERROR: See docs/changes/index.html for recent updates.
>>> [1]PETSC ERROR: See docs/faq.html for hints about trouble shooting.
>>> [1]PETSC ERROR: See docs/index.html for manual pages.
>>> [1]PETSC ERROR:
>>> ------------------------------------------------------------------------
>>> [1]PETSC ERROR: ./blockCG_1 on a arch-linu named hpcd.cs.odu.edu by ppatel
>>> Tue Aug 19 12:29:41 2014
>>> [1]PETSC ERROR: Libraries linked from /export/software/petsc-3.3/lib
>>> [1]PETSC ERROR: Configure run at Wed Jun  6 16:29:21 2012
>>> [1]PETSC ERROR: Configure options --prefix=/export/software/petsc-3.3
>>> --download-f-blas-lapack=1
>>> [1]PETSC ERROR:
>>> ------------------------------------------------------------------------
>>> [1]PETSC ERROR: MatGetValues_MPIDense() line 180 in
>>> src/mat/impls/dense/mpi/mpidense.c
>>> [1]PETSC ERROR: MatGetValues() line 1602 in src/mat/interface/matrix.c
>>> [1]PETSC ERROR: main() line 343 in blockCG_1.c
>>> --------------------------------------------------------------------------
>>> MPI_ABORT was invoked on rank 1 in communicator MPI_COMM_WORLD
>>> with errorcode 56.
>>>
>>> NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes.
>>> You may or may not see output from other processes, depending on
>>> exactly when Open MPI kills them.
>>> --------------------------------------------------------------------------
>>>
>>> #####################################################
>>>
>>> what is the efficient way to create a 1-D array from the PETSC matrix?
>


More information about the petsc-users mailing list