[petsc-users] MatSetValue in Fortran
Yann Jobic
yann.jobic at univ-amu.fr
Wed Feb 9 09:36:08 CST 2022
Sorry for the bad subject , i made a mistake.
The correct email subject and message was :
I'm struggling for a very simple error that i can not see. I'm running
in a sequential program, for the test.
MatView is giving me for the row 125 :
row 125: (125, 0.) (107, 0.)
I'm getting those values with MatGetRow :
row=125
CALL MatGetRow(MATGLOB,row,nb,testcols,testvalues,IER)
write(*,*)row,testcols(1),testvalues(1),
& testcols(2),testvalues(2)
CALL MatRestoreRow(MATGLOB,row,nb,testcols,testvalues,IER)
The output is :
125 125 0.000000000000000E+000 107 0.000000000000000E+000
Which is what i want. It's ok.
Then i'm doing the MatSetValue :
val = -1
row = 125
col = 107
CALL MatSetValue(MATGLOB,row,col,val,
& INSERT_VALUES, IER)
And i've got the error :
[0]PETSC ERROR: --------------------- Error Message
--------------------------------------------------------------
[0]PETSC ERROR: Argument out of range
[0]PETSC ERROR: New nonzero at (125,107) caused a malloc
Use MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE) to turn
off this check
[0]PETSC ERROR: See https://petsc.org/release/faq/ for trouble shooting.
[0]PETSC ERROR: Petsc Release Version 3.16.4, unknown
[0]PETSC ERROR:
/home/jobic/projet/fe-utils/marcus/3.16/test_MatSetValue_loem_3.16p4_openmpi_intel
on a named leto4.iusti-calcul.recherche by jobic Wed Feb 9 16:01:51 2022
[0]PETSC ERROR: Configure options
--prefix=/local/lib/petsc/3.16/p4/17/openmpi_intel-mkl-works
--with-single-library=0 --with-large-file-io=1 --with-debugging=0
--with-blacs=1
--with-blacs-dir=/opt/intel/compilers_and_libraries_2017.1.132/linux/compiler/lib/intel64/
--download-scalapack=1 --download-parmetis=1 --download-make=1
--download-mumps=1 --LIBS="
-Wl,-rpath,/opt/intel/compilers_and_libraries_2017.1.132/linux/compiler/lib/intel64/"
--with-blaslapack-dir=/opt/intel/compilers_and_libraries_2017.1.132/linux/compiler/lib/intel64/
--download-metis=1 --download-parmetis=1 --download-ptscotch=1
--download-cmake=1 --download-slepc=1 --download-hdf5=1 --with-zlib=1
--download-szlib=1 --download-suitesparse=1 --download-p4est=1
--download-netcdf=1 --download-triangle=1 --with-shared-libraries=0
--with-cxx-dialect=C++11 -CFLAGS=" -O3 -mtune=core-avx2 -mkl"
--COPTFLAGS="-D_POSIX_C_SOURCE=199309L" -CXXFLAGS=" -O3 -mtune=core-avx2
-mkl" -FFLAGS=" -O3 -mtune=core-avx2 -mkl"
PETSC_ARCH=openmpi_intel-mkl-17-works
[0]PETSC ERROR: #1 MatSetValues_SeqAIJ() at
/home/devel/src_linux/petsc-3.16.4/src/mat/impls/aij/seq/aij.c:520
[0]PETSC ERROR: #2 MatSetValues() at
/home/devel/src_linux/petsc-3.16.4/src/mat/interface/matrix.c:1398
[0]PETSC ERROR: #3 MatGetRow() at
/home/devel/src_linux/petsc-3.16.4/src/mat/interface/matrix.c:558
[0]PETSC ERROR: #4 MatRestoreRow_Fortran() at
/home/devel/src_linux/petsc-3.16.4/src/mat/interface/ftn-custom/zmatrixf.c:582
I'm obviously doing something wrong, but where ?
Thanks,
Yann
Le 2/9/2022 à 12:46 PM, Matthew Knepley a écrit :
> On Wed, Feb 9, 2022 at 5:56 AM Yann Jobic <yann.jobic at univ-amu.fr
> <mailto:yann.jobic at univ-amu.fr>> wrote:
>
> Dear All,
>
> I'm facing a strange problem. I did not succeed in putting some values
> in an MPI matrix. I'm using Petsc 3.16.4. The matrix is pre-allocated,
> with some zeroes at the right position.
>
> To explain the context, it's a finit elements code, thus in the tangent
> matrix creation, i've got a first loop over the elements, and feed the
> matrix accordingly. This part is working. I'm using ADD_VALUES.
>
> I then have to put the periodic boundary conditions on some nodes, that
> is to say that i've got 1 at the diagonal, and -1 on the mirror element
> of the designated ddl (i've got a Newton-Raphson minimisation
> procedure). I'm using INSERT_VALUES here.
>
> According to the documentation, i should do :
>
> Loop over Elements
> call MatSetValues
> end loop
> call MatAssemblyBegin(A,MAT_FLUSH_ASSEMBLY,ierr);CHKERRA(ierr)
> call MatAssemblyEnd(A,MAT_FLUSH_ASSEMBLY,ierr);CHKERRA(ierr)
>
> Loop over periodic nodes
> call MatSetValue
> end loop
> call MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr);CHKERRA(ierr)
> call MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr);CHKERRA(ierr)
>
> But it's not working. I don't have those values from the periodic
> boundary condition in the global matrix. The return value of
> MatSetValue
> is 0.
>
> I tried valgrind, but memory access looks ok. I really don't know
> how to
> debug this. Do you have any idea of what could happen here ?
> Debug ideas ?
>
>
> This is strange since we have tests for this kind of insertion. I would
> make a tiny
> code that adds two neighboring cells and a periodic boundary between the
> other side.
> If that fails it will be easy for us to look at the figure out what is
> happening.
>
> Thanks,
>
> Matt
>
> Many thanks,
>
> Best Regards,
>
> Yann
>
>
>
> --
> What most experimenters take for granted before they begin their
> experiments is infinitely more interesting than any results to which
> their experiments lead.
> -- Norbert Wiener
>
> https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
More information about the petsc-users
mailing list