<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Aug 1, 2016 at 3:00 AM, Klaij, Christiaan <span dir="ltr"><<a href="mailto:C.Klaij@marin.nl" target="_blank">C.Klaij@marin.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div dir="ltr" style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif">
<p></p>
<p>Matt, Barry<br>
<br>
Thanks for your replies! I've added a call to MatNestSetSubMats()<br>
but something's still wrong, see below.<br>
<br>
Chris<br>
<br>
<br>
$ cat mattry.F90<br>
program mattry<br>
<br>
  use petscksp<br>
  implicit none<br>
#include <petsc/finclude/petsckspdef.h><br>
<br>
  PetscInt :: n=4   ! setting 4 cells per process<br>
<br>
  PetscErrorCode         :: ierr<br>
  PetscInt               :: size,rank,i<br>
  Mat                    :: A,A02<br>
  MatType                :: type<br>
  IS                     :: isg0,isg1,isg2<br>
  IS                     :: isl0,isl1,isl2<br>
  ISLocalToGlobalMapping :: map<br>
<br>
  integer, allocatable, dimension(:) :: idx<br>
<br>
  call PetscInitialize(PETSC_NULL_CHARACTER,ierr); CHKERRQ(ierr)<br>
  call MPI_Comm_size(PETSC_COMM_WORLD,size,ierr); CHKERRQ(ierr)<br>
  call MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr);CHKERRQ(ierr)<br>
<br>
  ! local index sets for 3 fields<br>
  allocate(idx(n))<br>
  idx=(/ (i-1, i=1,n) /)<br>
  call ISCreateGeneral(PETSC_COMM_WORLD,n,idx,PETSC_COPY_VALUES,isl0,ierr);CHKERRQ(ierr)<br>
  call ISCreateGeneral(PETSC_COMM_WORLD,n,idx+n,PETSC_COPY_VALUES,isl1,ierr);CHKERRQ(ierr)<br>
  call ISCreateGeneral(PETSC_COMM_WORLD,n,idx+2*n,PETSC_COPY_VALUES,isl2,ierr);CHKERRQ(ierr)<br>
!  call ISView(isl3,PETSC_VIEWER_STDOUT_WORLD,ierr); CHKERRQ(ierr)<br>
  deallocate(idx)<br>
<br>
  ! global index sets for 3 fields<br>
  allocate(idx(n))<br>
  idx=(/ (i-1+rank*3*n, i=1,n) /)<br>
  call ISCreateGeneral(PETSC_COMM_WORLD,n,idx,PETSC_COPY_VALUES,isg0,ierr);CHKERRQ(ierr)<br>
  call ISCreateGeneral(PETSC_COMM_WORLD,n,idx+n,PETSC_COPY_VALUES,isg1,ierr); CHKERRQ(ierr)<br>
  call ISCreateGeneral(PETSC_COMM_WORLD,n,idx+2*n,PETSC_COPY_VALUES,isg2,ierr); CHKERRQ(ierr)<br>
!  call ISView(isg3,PETSC_VIEWER_STDOUT_WORLD,ierr); CHKERRQ(ierr)<br>
  deallocate(idx)<br>
<br>
  ! local-to-global mapping<br>
  allocate(idx(3*n))<br>
  idx=(/ (i-1+rank*3*n, i=1,3*n) /)<br>
  call ISLocalToGlobalMappingCreate(PETSC_COMM_WORLD,1,3*n,idx,PETSC_COPY_VALUES,map,ierr); CHKERRQ(ierr)<br>
!  call ISLocalToGlobalMappingView(map,PETSC_VIEWER_STDOUT_WORLD,ierr); CHKERRQ(ierr)<br>
  deallocate(idx)<br>
<br>
  ! create the 3-by-3 block matrix<br>
  call MatCreate(PETSC_COMM_WORLD,A,ierr); CHKERRQ(ierr)<br>
  call MatSetSizes(A,3*n,3*n,PETSC_DECIDE,PETSC_DECIDE,ierr); CHKERRQ(ierr)<br>
  call MatSetUp(A,ierr); CHKERRQ(ierr)<br>
  call MatSetOptionsPrefix(A,"A_",ierr); CHKERRQ(ierr)<br>
  call MatSetLocalToGlobalMapping(A,map,map,ierr); CHKERRQ(ierr)<br>
  call MatSetFromOptions(A,ierr); CHKERRQ(ierr)<br>
<br>
  ! setup nest<br>
  call MatGetType(A,type,ierr); CHKERRQ(ierr)<br>
  if (type.eq."nest") then<br></p></div></blockquote><div>1) Get rid of this protection, you do not need it.</div><div><br></div><div>2) It looks like the (/ /) notation does not work here. Can you put them in proper array?</div><div><br></div><div>  Thanks,</div><div><br></div><div>     Matt</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif"><p>
     call MatNestSetSubMats(A,3,(/isg0,isg1,isg2/),3,(/isg0,isg1,isg2/),PETSC_NULL_OBJECT,ierr); CHKERRQ(ierr)<br>
  end if<br>
<br>
  ! set diagonal of block A02 to 0.65<br>
  call MatGetLocalSubmatrix(A,isl0,isl2,A02,ierr); CHKERRQ(ierr)<br>
  do i=1,n<br>
     call MatSetValuesLocal(A02,1,i-1,1,i-1,0.65d0,INSERT_VALUES,ierr); CHKERRQ(ierr)<br>
  end do<br>
  call MatRestoreLocalSubMatrix(A,isl0,isl2,A02,ierr); CHKERRQ(ierr)<br>
  call MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr); CHKERRQ(ierr)<br>
  call MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr); CHKERRQ(ierr)<br>
<br>
  ! verify<br>
  call MatGetSubmatrix(A,isg0,isg2,MAT_INITIAL_MATRIX,A02,ierr); CHKERRQ(ierr)<br>
  call MatView(A02,PETSC_VIEWER_STDOUT_WORLD,ierr);CHKERRQ(ierr)<br>
<br>
  call PetscFinalize(ierr)<br>
<br>
end program mattry<br>
<br>
<br>
$ mpiexec -n 2 ./mattry -A_mat_type nest<br>
[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------<br>
[0]PETSC ERROR: Corrupt argument: <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind" target="_blank">http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind</a><br>
[0]PETSC ERROR: Invalid Pointer to Object: Parameter # 1<br>
[0]PETSC ERROR: See <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html" target="_blank">http://www.mcs.anl.gov/petsc/documentation/faq.html</a> for trouble shooting.<br>
[0]PETSC ERROR: Petsc Release Version 3.7.3, Jul, 24, 2016 <br>
[0]PETSC ERROR: ./mattry                                                                                                                                                                                                                                                      
       on a linux_64bit_debug named lin0322.marin.local by cklaij Mon Aug  1 09:54:07 2016<br>
[0]PETSC ERROR: Configure options --with-mpi-dir=/home/cklaij/ReFRESCO/Dev/trunk/Libs/install/openmpi/1.8.7 --with-clanguage=c++ --with-x=1 --with-debugging=1 --with-blas-lapack-dir=/opt/intel/composer_xe_2015.1.133/mkl --with-shared-libraries=0<br>
[0]PETSC ERROR: #1 PetscObjectReference() line 534 in /home/cklaij/ReFRESCO/Dev/trunk/Libs/build/petsc/3.7.3-dbg/src/sys/objects/inherit.c<br>
[0]PETSC ERROR: #2 MatNestSetSubMats_Nest() line 1042 in /home/cklaij/ReFRESCO/Dev/trunk/Libs/build/petsc/3.7.3-dbg/src/mat/impls/nest/matnest.c<br>
[0]PETSC ERROR: #3 MatNestSetSubMats() line 1105 in /home/cklaij/ReFRESCO/Dev/trunk/Libs/build/petsc/3.7.3-dbg/src/mat/impls/nest/matnest.c<br>
[1]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------<br>
[1]PETSC ERROR: Corrupt argument: <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind" target="_blank">http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind</a><br>
[1]PETSC ERROR: Invalid Pointer to Object: Parameter # 1<br>
[1]PETSC ERROR: See <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html" target="_blank">http://www.mcs.anl.gov/petsc/documentation/faq.html</a> for trouble shooting.<br>
[1]PETSC ERROR: Petsc Release Version 3.7.3, Jul, 24, 2016 <br>
[1]PETSC ERROR: ./mattry                                                                                                                                                                                                                                                      
       on a linux_64bit_debug named lin0322.marin.local by cklaij Mon Aug  1 09:54:07 2016<br>
[1]PETSC ERROR: Configure options --with-mpi-dir=/home/cklaij/ReFRESCO/Dev/trunk/Libs/install/openmpi/1.8.7 --with-clanguage=c++ --with-x=1 --with-debugging=1 --with-blas-lapack-dir=/opt/intel/composer_xe_2015.1.133/mkl --with-shared-libraries=0<br>
[1]PETSC ERROR: #1 PetscObjectReference() line 534 in /home/cklaij/ReFRESCO/Dev/trunk/Libs/build/petsc/3.7.3-dbg/src/sys/objects/inherit.c<br>
[1]PETSC ERROR: #2 MatNestSetSubMats_Nest() line 1042 in /home/cklaij/ReFRESCO/Dev/trunk/Libs/build/petsc/3.7.3-dbg/src/mat/impls/nest/matnest.c<br>
[1]PETSC ERROR: #3 MatNestSetSubMats() line 1105 in /home/cklaij/ReFRESCO/Dev/trunk/Libs/build/petsc/3.7.3-dbg/src/mat/impls/nest/matnest.c<br>
--------------------------------------------------------------------------<br>
MPI_ABORT was invoked on rank 1 in communicator MPI_COMM_WORLD <br>
with errorcode 64.<br>
<br>
NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes.<br>
You may or may not see output from other processes, depending on<br>
exactly when Open MPI kills them.<br>
--------------------------------------------------------------------------<br>
[lin0322.marin.local:14326] 1 more process has sent help message help-mpi-api.txt / mpi-abort<br>
[lin0322.marin.local:14326] Set MCA parameter "orte_base_help_aggregate" to 0 to see all help / error messages<br>
$ </p>
<p><br>
<br>
</p>
<br>
<font style="font-family:Verdana;font-size:8pt;color:#7d7d7d;font-weight:bold">dr. ir.</font><font style="font-family:Verdana;font-size:8pt;color:#7d7d7d;font-weight:bold">
</font><font style="font-family:Verdana;font-size:8pt;color:#7d7d7d;font-weight:bold">Christiaan</font><font style="font-family:Verdana;font-size:8pt;color:#7d7d7d;font-weight:bold">
</font><font style="font-family:Verdana;font-size:8pt;color:#7d7d7d;font-weight:bold">Klaij</font><font size="3" face="Segoe UI"></font><font style="font-family:Verdana;font-size:8pt;color:#7d7d7d;font-weight:bold"> |
</font><font style="font-family:Verdana;font-size:8pt;color:#7d7d7d;font-weight:bold">CFD Researcher</font><font style="font-family:Verdana;font-size:8pt;color:#7d7d7d;font-weight:bold"> |
</font><font style="font-family:Verdana;font-size:8pt;color:#7d7d7d;font-weight:bold">Research & Development</font><br>
<font style="font-family:Verdana;font-size:9pt;color:#7d7d7d;font-weight:bold">MARIN</font><font style="font-family:Verdana;font-size:8pt;color:#7d7d7d"> | T
</font><font style="font-family:Verdana;font-size:8pt;color:#7d7d7d"><a href="tel:%2B31%20317%2049%2033%2044" value="+31317493344" target="_blank">+31 317 49 33 44</a></font><font color="#7d7d7d" size="2" face="Segoe UI"></font><font style="font-family:Verdana;font-size:8pt"> |
</font><span style="font-family:Verdana;font-size:8pt"><a href="mailto:C.Klaij@marin.nl" title="" style="font-family:Verdana;font-size:8pt" target="_blank"><span style="font-family:Verdana;font-size:8pt">C.Klaij@marin.nl</span></a></span><font color="#7d7d7d" size="2" face="Segoe UI"></font><font style="font-family:Verdana;font-size:8pt"> |
</font><span style="font-family:Verdana;font-size:8pt"><a href="http://www.marin.nl" title="" style="font-family:Verdana;font-size:8pt" target="_blank"><span style="font-family:Verdana;font-size:8pt">www.marin.nl</span></a></span><br>
<br>
<a href="https://www.linkedin.com/company/marin" target="_blank"><img width="16" height="16" style="border:0px Solid" src="cid:image2bc716.PNG@d52d5496.48888819" alt="LinkedIn"></a> <a href="http://www.youtube.com/marinmultimedia" target="_blank"><img width="16" height="16" style="border:0px Solid" src="cid:imageaadb69.PNG@7e73d986.4ca9819b" alt="YouTube"></a> <a href="https://twitter.com/MARIN_nieuws" target="_blank"><img width="16" height="16" style="border:0px Solid" src="cid:imagedd86d2.PNG@cac328a1.4eb3c75f" alt="Twitter"></a> <a href="https://www.facebook.com/marin.wageningen" target="_blank"><img width="16" height="16" style="border:0px Solid" src="cid:imaged1a140.PNG@7628f185.4993b715" alt="Facebook"></a><br>
<font style="FONT-FAMILY:Verdana;FONT-SIZE:8pt" color="#7d7d7d" size="2" face="Verdana">MARIN news:
<font style="font-family:Verdana;font-size:8pt"><span style="font-family:Verdana;font-size:8pt"><a href="http://www.marin.nl/web/News/News-items/Joint-Industry-Project-LifeLine-kicks-off.htm" title="" style="font-family:Verdana;font-size:8pt" target="_blank"><span style="font-family:Verdana;font-size:8pt">Joint
 Industry Project LifeLine kicks off</span></a></span></font></font>
<p></p>
<p><u></u></p>
<u></u><u></u><u></u>
</div>

</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">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</div>
</div></div>