[petsc-users] MatPermute problem because of wrong sized index set

Mark Adams mfadams at lbl.gov
Mon Jun 17 08:23:18 CDT 2019


You also do not seem to be initializing kk.

On Mon, Jun 17, 2019 at 4:00 AM Eda Oktay via petsc-users <
petsc-users at mcs.anl.gov> wrote:

> Hello everyone again,
>
> I was making an index mistake in for loop. I corrected it and my problem
> solved.
>
> Thank you,
>
> Eda
>
> Eda Oktay <eda.oktay at metu.edu.tr>, 17 Haz 2019 Pzt, 10:28 tarihinde şunu
> yazdı:
>
>> Hello everyone,
>>
>> I am trying to permute a matrix by using a sorted eigenvector in order to
>> partition the matrix. I sorted the vector and got the index set idx. I am
>> using 2 processors and I have to divide the vector into 2 according to the
>> sign of elements (first negative signed ones, then positive signed ones)
>> first, so I wrote the code below (if-else part). After sorting and dividing
>> them, I need to permute the matrix with these index sets.
>>
>> However, in last line (MatPermute), I got the following error:
>>
>> [0]PETSC ERROR: --------------------- Error Message
>> --------------------------------------------------------------
>> [0]PETSC ERROR: Argument out of range
>> [0]PETSC ERROR: Index 13 is out of range
>> [0]PETSC ERROR: See http://www.mcs.anl.gov/petsc/documentation/faq.html
>> for trouble shooting.
>> [0]PETSC ERROR: Petsc Release Version 3.11.1, Apr, 12, 2019
>> [0]PETSC ERROR: ./son_without_parmetis on a arch-linux2-c-debug named
>> 5470.wls.metu.edu.tr by edaoktay Mon Jun 17 10:11:54 2019
>> [0]PETSC ERROR: Configure options --download-mpich --download-openblas
>> --download-slepc --download-metis --download-parmetis --download-chaco
>> --with-X=1
>> [0]PETSC ERROR: #1 PetscLayoutFindOwner() line 249 in
>> /home/edaoktay/petsc-3.11.1/include/petscis.h
>> [0]PETSC ERROR: #2 PetscSFSetGraphLayout() line 545 in
>> /home/edaoktay/petsc-3.11.1/src/vec/is/utils/pmap.c
>> [0]PETSC ERROR: #3 MatPermute_MPIAIJ() line 1622 in
>> /home/edaoktay/petsc-3.11.1/src/mat/impls/aij/mpi/mpiaij.c
>> [0]PETSC ERROR: #4 MatPermute() line 5095 in
>> /home/edaoktay/petsc-3.11.1/src/mat/interface/matrix.c
>> [0]PETSC ERROR: #5 main() line 354 in
>> /home/edaoktay/petsc-3.11.1/arch-linux2-c-debug/share/slepc/examples/src/eda/son_without_parmetis.c
>> [0]PETSC ERROR: PETSc Option Table entries:
>> [0]PETSC ERROR: -f
>> /home/edaoktay/petsc-3.11.1/share/petsc/datafiles/matrices/binary_files/LFAT5_binary
>> [0]PETSC ERROR: -weighted
>> [0]PETSC ERROR: ----------------End of Error Message -------send entire
>> error message to petsc-maint at mcs.anl.gov----------
>>
>> I also found out that when I look at the submatrix Ais, I got different
>> sized matrix. For example, I used 14*14 matrix, I get the vector of length
>> 14 but then idx is divided into 5 and 7 elements so Ais is of size 12. 2 of
>> the positive signed elements are not counted and I didn't understand why.
>>
>> I also checked the if-else part and I found out that this portion of the
>> code is ran by processor 0.  Can be this the problem for different sized
>> Ais? And how can I fix that problem?
>>
>> Thanks,
>>
>> Eda
>>
>>
>> PetscMPIInt rank,size;
>>   MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
>>   MPI_Comm_size(PETSC_COMM_WORLD, &size);
>>
>>   PetscInt kk;
>>
>>   for (i=0;i<siz;i++){
>>       if (avr[i] < 0){
>>           ++kk;
>>       }
>>   }
>>
>>   PetscInt *idxx;
>>   IS iskk;
>>   PetscInt sizeofidxx;
>>   if (rank == 0){
>>
>>       PetscMalloc1(kk,&idxx);
>>       j = 0;
>>       for (i=0; i<kk; i++){
>>           idxx[j] = idx[i];
>>           j++;
>>       }
>>   } else{
>>       PetscMalloc1(siz-kk,&idxx);
>>       j = 0;
>>       for (i=siz-kk-2 ;i<siz; i++){
>>           idxx[j] = idx[i];
>>           j++;
>>       }
>>   }
>>
>>   sizeofidxx = j;
>>   ISCreateGeneral(PETSC_COMM_WORLD,sizeofidxx,idxx,PETSC_COPY_VALUES,&is);
>>   ISView(is,PETSC_VIEWER_STDOUT_WORLD);
>>
>>   /*Permute matrix L (spy(A(p1,p1)))*/
>>
>>   Mat Ais;
>>   MatCreateSubMatrix(A,is,is,MAT_INITIAL_MATRIX,&Ais);
>>   ierr =ISSetPermutation(is);CHKERRQ(ierr);
>>
>>     /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>>                     Create Partitioning
>>      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>> */
>>     PetscInt mA,nA,mL,nL;
>>     MatGetSize(Ais,&mA,&nA);
>>     MatGetLocalSize(Ais,&mL,&nL);
>>     PetscPrintf(PETSC_COMM_WORLD," Size of Ais: %D,%D\n",mA,nA);
>>     PetscPrintf(PETSC_COMM_WORLD," Size of local Ais: %D,%D\n",mL,nL);
>>
>>   ierr = MatPermute(Ais,is,is,&PL);CHKERRQ(ierr);
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20190617/90f9213b/attachment-0001.html>


More information about the petsc-users mailing list