<div dir="ltr">Thanks, it works!<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 29, 2016 at 4:31 PM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
On all other processes don't pass in 1 pass in 0 since all other processes want 0 sub matrices<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
> On Jun 29, 2016, at 3:24 PM, ehsan sadrfaridpour <<a href="mailto:it.sadr@gmail.com">it.sadr@gmail.com</a>> wrote:<br>
><br>
> Thanks, the IS problem is solved.<br>
> But now I have another problem to compile the code.<br>
><br>
> I use below code:<br>
> Mat m_WA_nt_local;<br>
> MatCreateSeqAIJ(PETSC_COMM_SELF,num_points,num_points, Config_params::getInstance()->get_pre_init_loader_matrix(), NULL, &m_WA_nt_local);<br>
> IS set;<br>
> if(rank ==0){<br>
> ISCreateStride(PETSC_COMM_SELF, num_points, 0, 1, &set);<br>
> ISView(set, PETSC_VIEWER_STDOUT_SELF);<br>
> }<br>
> MatGetSubMatrices(m_WA_norm_T, 1, &set, &set, MAT_INITIAL_MATRIX, &m_WA_nt_local);<br>
><br>
> The error I get is :<br>
> error: cannot convert ‘_p_Mat**’ to ‘_p_Mat***’ for argument ‘6’ to ‘PetscErrorCode MatGetSubMatrices(Mat, PetscInt, _p_IS* const*, _p_IS* const*, MatReuse, _p_Mat***)’<br>
> MatGetSubMatrices(m_WA_norm_T, 1, &set, &set, MAT_INITIAL_MATRIX, &m_WA_nt_local);<br>
><br>
><br>
> I tried to go around it by define a array of Matrices using "Mat * m_WA_nt_local"<br>
> So, the first 2 lines changed to below and I can compile the code.<br>
> Mat * m_WA_nt_local;<br>
> MatCreateSeqAIJ(PETSC_COMM_SELF,num_points,num_points, Config_params::getInstance()->get_pre_init_loader_matrix(), NULL, m_WA_nt_local);<br>
><br>
><br>
><br>
> However, I get errors like below when I run the code with 2 mpi process.<br>
> --------------------- Error Message --------------------------------------------------------------<br>
> [1]PETSC ERROR: Invalid argument<br>
> [1]PETSC ERROR: Wrong type of object: Parameter # 3<br>
> [1]PETSC ERROR: See <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html" rel="noreferrer" target="_blank">http://www.mcs.anl.gov/petsc/documentation/faq.html</a> for trouble shooting.<br>
> [1]PETSC ERROR: Petsc Release Version 3.6.3, unknown<br>
> [1]PETSC ERROR: ut_main on a linux-cxx-debug named grappelli by esfp Wed Jun 29 16:21:04 2016<br>
> [1]PETSC ERROR: Configure options PETSC_ARCH=linux-cxx-debug --with-cc=gcc --with-cxx=g++ --with-clanguage=c++ --with-gnu-compilers=1 --with-mpi-compilers=1 --with-debugging=1 --with-shared-libraries=1 --download-openmpi=1 --download-f2cblaslapack --download-superlu_dist=1 --download-superlu=1 --download-metis=1 --download-parmetis=1 --download-blacs=1 --with-hdf5 --with-hdf5-dir=/usr/local/hdf5/<br>
> [1]PETSC ERROR: #1 MatGetSubMatrices() line 6605 in /home/esfp/tools/libraries/petsc/src/mat/interface/matrix.c<br>
><br>
><br>
> I think I need to do something for other processes, but I don't know what I need to do.<br>
><br>
> Best,<br>
> Ehsan<br>
><br>
><br>
><br>
> On Wed, Jun 29, 2016 at 4:03 PM, Dave May <<a href="mailto:dave.mayhem23@gmail.com">dave.mayhem23@gmail.com</a>> wrote:<br>
><br>
><br>
> On Wednesday, 29 June 2016, ehsan sadrfaridpour <<a href="mailto:it.sadr@gmail.com">it.sadr@gmail.com</a>> wrote:<br>
> I faced the below error during compiling my code for using MatGetSubMatrices.<br>
><br>
> 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***)’<br>
> MatGetSubMatrices(m_WA_norm_T, 1, set, set, MAT_INITIAL_MATRIX, &m_local_W);<br>
><br>
> My code :<br>
> PetscMPIInt rank;<br>
> MPI_Comm_rank(PETSC_COMM_WORLD, &rank);<br>
><br>
> if(rank ==0){<br>
> Mat m_local_W;<br>
> 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)<br>
> IS set;<br>
> ISCreateStride(PETSC_COMM_SELF, num_points, 0, 1, &set_row);<br>
> MatGetSubMatrices(m_WA_norm_T, 1, set_row, set_col, MAT_INITIAL_MATRIX, &m_local_W);<br>
><br>
> }<br>
><br>
> I followed below example:<br>
> <a href="http://www.mcs.anl.gov/petsc/petsc-current/src/vec/is/is/examples/tutorials/ex2.c.html" rel="noreferrer" target="_blank">http://www.mcs.anl.gov/petsc/petsc-current/src/vec/is/is/examples/tutorials/ex2.c.html</a><br>
><br>
> This code won't work in parallel.<br>
> The man page says this function is collective on Mat. You need to move the call to MatGetSubMatrices outside of the if(rank==0) loop.<br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
> On Wed, Jun 29, 2016 at 3:19 PM, ehsan sadrfaridpour <<a href="mailto:it.sadr@gmail.com">it.sadr@gmail.com</a>> wrote:<br>
> Thanks a lot for great support.<br>
><br>
> On Wed, Jun 29, 2016 at 3:11 PM, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br>
><br>
> 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.<br>
><br>
><br>
> > On Jun 29, 2016, at 1:43 PM, ehsan sadrfaridpour <<a href="mailto:it.sadr@gmail.com">it.sadr@gmail.com</a>> wrote:<br>
> ><br>
> > Hi,<br>
> ><br>
> > I need to have access to most of elements of a parallel MPIAIJ matrix only from 1 process (rank 0).<br>
> > I tried to copy or duplicate it to SEQAIJ, but I faced problems.<br>
> ><br>
> > 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.<br>
> ><br>
> > Best,<br>
> > Ehsan<br>
> ><br>
> ><br>
><br>
><br>
><br>
><br>
<br>
</div></div></blockquote></div><br></div>