<div dir="auto">I misread local sizes of the matrix. Without using valgrind, I was able to fix the problem by using small sized matrix. It turned out that there is an indexing mistake.<div dir="auto"><br></div><div dir="auto">Thank you!</div><div dir="auto"><br></div><div dir="auto">Eda</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, May 9, 2019, 8:53 AM Smith, Barry F. <<a href="mailto:bsmith@mcs.anl.gov" target="_blank" rel="noreferrer">bsmith@mcs.anl.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Did you ever make progress on this issue?<br>
<br>
> On Apr 22, 2019, at 8:47 AM, Smith, Barry F. <<a href="mailto:bsmith@mcs.anl.gov" rel="noreferrer noreferrer" target="_blank">bsmith@mcs.anl.gov</a>> wrote:<br>
> <br>
> <br>
> Are you able to run under valgrind? It is a bit better than the PETSc malloc to find each instance of memory corruption and the sooner you find it the easier it is to find the bug. <a href="https://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind" rel="noreferrer noreferrer noreferrer" target="_blank">https://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind</a><br>
> <br>
> <br>
> <br>
>> On Apr 22, 2019, at 7:31 AM, Eda Oktay via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" rel="noreferrer noreferrer" target="_blank">petsc-users@mcs.anl.gov</a>> wrote:<br>
>> <br>
>> Hello,<br>
>> <br>
>> I am trying to partition an odd-numbered sized (for example 4253*4253), square permutation matrix by using 2 processors with ParMETIS. The permutation matrix is obtained by permuting the matrix by an index set "is" (MatPermute(A,is,is,&PL)). I checked the index set, it gives a permutation and it is correct.<br>
>> <br>
>> When I look at the local size of the matrix, it is given by 2127 and 2127 on each processor, so in order the local sizes of matrix and index sets to be same, I defined the index sets' sizes as 2127 and 2127. <br>
>> <br>
>> When I do that, I get memory corruption error in MatPartiitioningApply function. The error is as follows:<br>
>> <br>
>> [0]PETSC ERROR: PetscMallocValidate: error detected at MatPartitioningApply_Parmetis_Private() line 141 in /home/edaoktay/petsc-3.10.3/src/mat/partition/impls/pmetis/pmetis.c<br>
>> [0]PETSC ERROR: Memory [id=0(8512)] at address 0x19e6870 is corrupted (probably write past end of array)<br>
>> [0]PETSC ERROR: Memory originally allocated in main() line 310 in /home/edaoktay/petsc-3.10.3/arch-linux2-c-debug/share/slepc/examples/src/eda/TEK_SAYI_SON_YENI_DENEME_TEMIZ_ENYENI_FINAL.c<br>
>> [0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------<br>
>> [0]PETSC ERROR: Memory corruption: <a href="http://www.mcs.anl.gov/petsc/documentation/installation.html#valgrind" rel="noreferrer noreferrer noreferrer" target="_blank">http://www.mcs.anl.gov/petsc/documentation/installation.html#valgrind</a><br>
>> [0]PETSC ERROR: <br>
>> [0]PETSC ERROR: See <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html" rel="noreferrer noreferrer noreferrer" target="_blank">http://www.mcs.anl.gov/petsc/documentation/faq.html</a> for trouble shooting.<br>
>> [0]PETSC ERROR: Petsc Release Version 3.10.3, Dec, 18, 2018 <br>
>> [0]PETSC ERROR: ./TEK_SAYI_SON_YENI_DENEME_TEMIZ_ENYENI_FINAL on a arch-linux2-c-debug named <a href="http://13ed.wls.metu.edu.tr" rel="noreferrer noreferrer noreferrer" target="_blank">13ed.wls.metu.edu.tr</a> by edaoktay Mon Apr 22 14:58:52 2019<br>
>> [0]PETSC ERROR: Configure options --with-cc=gcc --with-cxx=g++ --with-fc=gfortran --with-cxx-dialect=C++11 --download-openblas --download-metis --download-parmetis --download-superlu_dist --download-slepc --download-mpich<br>
>> [0]PETSC ERROR: #1 PetscMallocValidate() line 146 in /home/edaoktay/petsc-3.10.3/src/sys/memory/mtr.c<br>
>> [0]PETSC ERROR: #2 MatPartitioningApply_Parmetis_Private() line 141 in /home/edaoktay/petsc-3.10.3/src/mat/partition/impls/pmetis/pmetis.c<br>
>> [0]PETSC ERROR: #3 MatPartitioningApply_Parmetis() line 215 in /home/edaoktay/petsc-3.10.3/src/mat/partition/impls/pmetis/pmetis.c<br>
>> [0]PETSC ERROR: #4 MatPartitioningApply() line 340 in /home/edaoktay/petsc-3.10.3/src/mat/partition/partition.c<br>
>> [0]PETSC ERROR: #5 main() line 374 in /home/edaoktay/petsc-3.10.3/arch-linux2-c-debug/share/slepc/examples/src/eda/TEK_SAYI_SON_YENI_DENEME_TEMIZ_ENYENI_FINAL.c<br>
>> [0]PETSC ERROR: PETSc Option Table entries:<br>
>> [0]PETSC ERROR: -f /home/edaoktay/petsc-3.10.3/share/petsc/datafiles/matrices/binary_files/airfoil1_binary<br>
>> [0]PETSC ERROR: -mat_partitioning_type parmetis<br>
>> [0]PETSC ERROR: -unweighted<br>
>> [0]PETSC ERROR: ----------------End of Error Message -------send entire error message to petsc-maint@mcs.anl.gov----------<br>
>> <br>
>> <br>
>> The line 310 is PetscMalloc1(ss,&idxx). The part of my program is written as below:<br>
>> <br>
>> if (mod != 0){<br>
>> ss = (siz+1)/size;//(siz+size-mod)/size;<br>
>> } else{<br>
>> ss = siz/size;<br>
>> }<br>
>> <br>
>> PetscMalloc1(ss,&idxx); // LINE 310<br>
>> <br>
>> if (rank != size-1) {<br>
>> j =0;<br>
>> for (i=rank*ss; i<(rank+1)*ss; i++) {<br>
>> idxx[j] = idx[i];<br>
>> j++;<br>
>> }<br>
>> <br>
>> } else {<br>
>> <br>
>> j =0;<br>
>> for (i=rank*ss; i<siz; i++) {<br>
>> idxx[j] = idx[i];<br>
>> j++;<br>
>> }<br>
>> <br>
>> }<br>
>> <br>
>> if (mod != 0){<br>
>> if (rank<mod){<br>
>> idxx[ss+1] = idx[ss*size+rank+1];<br>
>> }<br>
>> }<br>
>> <br>
>> /*Permute matrix L (spy(A(p1,p1))*/<br>
>> <br>
>> if (mod != 0){<br>
>> if (rank<mod){<br>
>> ierr = ISCreateGeneral(PETSC_COMM_WORLD,ss+1,idxx,PETSC_COPY_VALUES,&is);CHKERRQ(ierr);<br>
>> } else{<br>
>> ierr = ISCreateGeneral(PETSC_COMM_WORLD,ss,idxx,PETSC_COPY_VALUES,&is);CHKERRQ(ierr);<br>
>> } <br>
>> <br>
>> }else {<br>
>> ierr = ISCreateGeneral(PETSC_COMM_WORLD,ss,idxx,PETSC_COPY_VALUES,&is);CHKERRQ(ierr);<br>
>> }<br>
>> <br>
>> ierr = ISSetPermutation(is);CHKERRQ(ierr); <br>
>> ierr = MatPermute(A,is,is,&PL);CHKERRQ(ierr); <br>
>> <br>
>> /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<br>
>> Create Partitioning<br>
>> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */<br>
>> <br>
>> ierr = MatConvert(PL,MATMPIADJ,MAT_INITIAL_MATRIX,&AL);CHKERRQ(ierr); <br>
>> ierr = MatPartitioningCreate(MPI_COMM_WORLD,&part);CHKERRQ(ierr);<br>
>> ierr = MatPartitioningSetAdjacency(part,AL);CHKERRQ(ierr); <br>
>> ierr = MatPartitioningSetFromOptions(part);CHKERRQ(ierr);<br>
>> ierr = MatPartitioningApply(part,&partitioning);CHKERRQ(ierr); <br>
>> <br>
>> I understood that I cannot change the local size of the matrix since it is read from a file. But as you can see above, when I defined index sets' sizes as 2127 and 2127, memory corruption occurs. I tried several things but at the end I got error in MatPermute or here.<br>
>> <br>
>> By the way, idx is from 0 to 4252 but the global size of is is 4253. If I change idx to 0:4253 then I think it will be incorrect since actually there is no 4254th element.<br>
>> <br>
>> How can I solve this problem?<br>
>> <br>
>> Thank you,<br>
>> <br>
>> Eda<br>
> <br>
<br>
</blockquote></div>