[petsc-users] How to have a local copy (sequential) of a parallel matrix
Barry Smith
bsmith at mcs.anl.gov
Wed Jun 29 14:59:25 CDT 2016
The call requires arrays of IS so even though you only want one sub matrix you need to pass an array of length 1 which you can do with &set etc
> MatGetSubMatrices(m_WA_norm_T, 1, &set, &set, MAT_INITIAL_MATRIX, &m_local_W);
> On Jun 29, 2016, at 2:54 PM, ehsan sadrfaridpour <it.sadr at gmail.com> wrote:
>
> I faced the below error during compiling my code for using MatGetSubMatrices.
>
> error: cannot convert ‘IS {aka _p_IS*}’ to ‘_p_IS* const*’ for argument ‘3’ to ‘PetscErrorCode MatGetSubMatrices(Mat, PetscInt, _p_IS* const*, _p_IS* const*, MatReuse, _p_Mat***)’
> MatGetSubMatrices(m_WA_norm_T, 1, set, set, MAT_INITIAL_MATRIX, &m_local_W);
>
> My code :
> PetscMPIInt rank;
> MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
>
> if(rank ==0){
> Mat m_local_W;
> MatCreateSeqAIJ(PETSC_COMM_SELF,num_points,num_points, num_nz, NULL,&m_local_W);// try to reserve space for only number of final non zero entries for each fine node (e.g. 4)
> IS set;
> ISCreateStride(PETSC_COMM_SELF, num_points, 0, 1, &set_row);
> MatGetSubMatrices(m_WA_norm_T, 1, set_row, set_col, MAT_INITIAL_MATRIX, &m_local_W);
>
> }
>
> I followed below example:
> http://www.mcs.anl.gov/petsc/petsc-current/src/vec/is/is/examples/tutorials/ex2.c.html
>
>
>
>
>
>
> On Wed, Jun 29, 2016 at 3:19 PM, ehsan sadrfaridpour <it.sadr at gmail.com> wrote:
> Thanks a lot for great support.
>
> On Wed, Jun 29, 2016 at 3:11 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
>
> MatGetSubmatrices() just have the first process request all the rows and columns and the others request none. You can use ISCreateStride() to create the ISs without having to make an array of all the indices.
>
>
> > On Jun 29, 2016, at 1:43 PM, ehsan sadrfaridpour <it.sadr at gmail.com> wrote:
> >
> > Hi,
> >
> > I need to have access to most of elements of a parallel MPIAIJ matrix only from 1 process (rank 0).
> > I tried to copy or duplicate it to SEQAIJ, but I faced problems.
> >
> > How can I have a local copy of a matrix which is distributed on multiple process? I don't want to update the matrix, and the read-only version of it would be enough.
> >
> > Best,
> > Ehsan
> >
> >
>
>
>
More information about the petsc-users
mailing list