<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>here some example code which works for MPIAIJ but fails for MPIDENSE. Maybe you can tell me what I am doing wrong</div>

<div> </div>

<div> </div>

<div>
<div>program submatrix<br/>
#include <petsc/finclude/petscmat.h><br/>
  use petscmat<br/>
  implicit none<br/>
  <br/>
  Mat :: A,B<br/>
  PetscInt ::n,m,nl1,nl2,nlc1,nlc2,nproc,iproc,i,ncols,nrow,ncol<br/>
  PetscReal :: info(MAT_INFO_SIZE)<br/>
  PetscErrorCode :: ierr<br/>
  IS :: isrow,iscol<br/>
  integer,allocatable :: irow(:),icol(:),cols(:)<br/>
  character(256) :: stype,sdummy</div>

<div>  <br/>
  call PetscInitialize(PETSC_NULL_CHARACTER,ierr)<br/>
  <br/>
  call MPI_COMM_SIZE(PETSC_COMM_WORLD, nproc,ierr)<br/>
  <br/>
  call MPI_Comm_rank(PETSC_COMM_WORLD, iproc, ierr )<br/>
  <br/>
  if (nproc.ne.3) then<br/>
    if (iproc.eq.0) write(0,*) "nproc.ne.3 ",nproc<br/>
    call PetscFinalize(ierr)<br/>
    stop<br/>
  end if<br/>
  <br/>
  n=3<br/>
  m=n<br/>
      <br/>
  call MatCreateDense(PETSC_COMM_WORLD,1,PETSC_DECIDE,n,m,PETSC_NULL_SCALAR,A,ierr)<br/>
  call MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr)<br/>
  call MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr)<br/>
  <br/>
  allocate(irow(1),icol(1))<br/>
  <br/>
!~   call MatConvert(A,MATAIJ, MAT_INPLACE_MATRIX,A,ierr)</div>

<div> </div>

<div>  nrow=0<br/>
  ncol=1<br/>
  icol=iproc<br/>
  if (iproc.eq.0) then<br/>
    irow=iproc<br/>
    nrow=1<br/>
  end if</div>

<div>  call ISCreateGeneral(PETSC_COMM_SELF,nrow,irow,&<br/>
 & PETSC_COPY_VALUES,isrow,ierr)<br/>
    <br/>
  call ISCreateGeneral(PETSC_COMM_SELF,ncol,icol,&<br/>
 & PETSC_COPY_VALUES,iscol,ierr)<br/>
  <br/>
  call MatCreateSubMatrix(A,isrow,iscol,MAT_INITIAL_MATRIX,B,ierr)<br/>
  <br/>
  call MatGetType(B,stype,ierr)<br/>
  call MatGetInfo(B, MAT_LOCAL, info,ierr)<br/>
  call MatGetOwnershipRange(B,nl1,nl2,ierr)<br/>
  call MatGetOwnershipRangeColumn(B,nlc1,nlc2,ierr)<br/>
  call MatGetSize(B,m,n,ierr)<br/>
  write(sdummy,fmt='(A,25i16)') trim(stype),iproc,int(info(mat_info_nz_allocated)),int(info(mat_info_nz_used)),nl1,nl2,nlc1,nlc2,m,n</div>

<div>  call PetscSynchronizedPrintf(PETSC_COMM_WORLD,trim(sdummy)//NEW_LINE('A'),ierr)<br/>
  call PetscSynchronizedFlush(PETSC_COMM_WORLD,PETSC_STDOUT,ierr)  <br/>
  <br/>
  <br/>
  call PetscFinalize(ierr)<br/>
 <br/>
end program submatrix<br/>
 </div>
</div>

<div> </div>

<div> 
<div> 
<div name="quote" style="margin:10px 5px 5px 10px; padding: 10px 0 10px 10px; border-left:2px solid #C3D9E5; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div style="margin:0 0 10px 0;"> </div>

<div name="quoted-content">
<div style="font-family: Verdana;font-size: 12.0px;">
<div>i see. but i doesn't work for me. maybe I made some mistake. If not I will try to make some example code where it fails.
<div> 
<div style="margin: 10.0px 5.0px 5.0px 10.0px;padding: 10.0px 0 10.0px 10.0px;border-left: 2.0px solid rgb(195,217,229);">
<div style="margin: 0 0 10.0px 0;"><br/>
<br/>
> On Jul 10, 2018, at 11:50 PM, Marius Buerkle <mbuerkle@web.de> wrote:<br/>
><br/>
> Sorry, I have yet another question. While it works well for MPIAIJ, I end up in a deadlock if I use MatCreateSubmatrix on a MPIDENSE matrix. Should MatCreateSubmatrix work on dense matricies ?<br/>
<br/>
yes<br/>
<br/>
> On Mon, Jul 9, 2018 at 10:02 PM Marius Buerkle <mbuerkle@web.de> wrote:<br/>
> MatGetSubmatrix is in the current PETSc released called MatCreateSubmatrix. Is this correct ?<br/>
><br/>
><br/>
> Yep. I am old and cannot follow API changes anymore.<br/>
><br/>
> Matt<br/>
><br/>
> On Mon, Jul 9, 2018 at 8:38 PM Marius Buerkle <mbuerkle@web.de> wrote:<br/>
> I see. What I want to do is to calculate the matrix product C=A*B' between two sparse matrices A=(A11 0 , A21 0) and B=(B11 0 , B21 0) where C will be dense in the end but I just want to calculate some selected entries C_ij of C. At the moment I extract submatricies for the corresponding rows and columns,<br/>
><br/>
> I think that is the right way, but you should only need MatGetSubmatrix for that.<br/>
><br/>
> Thanks,<br/>
><br/>
> Matt<br/>
><br/>
> so I was wondering if there is a simpler or performancer-wise faster way. I assume there is not such thing as a restricted MatMatMul which just calculated the lets say predefined nonzero entries of C.<br/>
><br/>
><br/>
> These are "internal" routines that we rarely expect end users to use since they are specific for particular matrix implementations. As such they are also kind of strange to use from Fortran since none of the AIJ data structures can be made visible to Fortran.<br/>
><br/>
> Could you explain why you want them from Fortran and maybe we'll have alternative suggestions on how you can achieve the same effect.<br/>
><br/>
> Barry<br/>
><br/>
><br/>
> > On Jul 5, 2018, at 3:05 AM, Marius Buerkle <mbuerkle@web.de> wrote:<br/>
> ><br/>
> > or MatMPIAIJGetLocalMatCondensed for that matter.<br/>
> ><br/>
> ><br/>
> ><br/>
> > Hi !<br/>
> ><br/>
> > Is MatMPIAIJGetSeqAIJ implemented for fortran?<br/>
> ><br/>
> > best,<br/>
> > Marius<br/>
><br/>
><br/>
><br/>
> --<br/>
> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br/>
> -- Norbert Wiener<br/>
><br/>
> <a href="https://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br/>
><br/>
><br/>
> --<br/>
> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br/>
> -- Norbert Wiener<br/>
><br/>
> <a href="https://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br/>
 </div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div></div></body></html>