Re: [petsc-dev] FieldSplit with different nonzero pattern

2018-05-03 Thread Pierre Jolivet
Hong,
Thanks for your reply.
It’s not so minimalist, but at least it is based on one of your example.
diff --git a/src/ksp/ksp/examples/tutorials/ex42.c 
b/src/ksp/ksp/examples/tutorials/ex42.c
index 8be4389a2d..520c82569a 100644
--- a/src/ksp/ksp/examples/tutorials/ex42.c
+++ b/src/ksp/ksp/examples/tutorials/ex42.c
@@ -1953,6 +1953,15 @@ static PetscErrorCode solve_stokes_3d_coupled(PetscInt 
mx,PetscInt my,PetscInt m
 }
   }
   ierr = KSPSolve(ksp_S,f,X);CHKERRQ(ierr);
+  PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD, PETSC_VIEWER_ASCII_INFO);
+  MatView(A, PETSC_VIEWER_STDOUT_WORLD);
+  Mat C;
+  MatMatMult(A, A, MAT_INITIAL_MATRIX, PETSC_DEFAULT, &C);
+  MatView(C, PETSC_VIEWER_STDOUT_WORLD);
+  PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD);
+  ierr = KSPSetOperators(ksp_S,C,C);CHKERRQ(ierr);
+  ierr = KSPSolve(ksp_S,f,X);CHKERRQ(ierr);
+  MatDestroy(&C);

   ierr = 
PetscOptionsGetBool(NULL,NULL,"-write_pvts",&write_output,NULL);CHKERRQ(ierr);
   if (write_output) {ierr = DAView3DPVTS(da_Stokes,X,"up");CHKERRQ(ierr);}

$ mpirun -np 1 ./ex42 -mx 2 -my 2 -mz 2 -stokes_pc_type fieldsplit
This should give you this exact error.
Do you know of a way to bypass the error by flushing/destroying the PC while 
still keeping the options for the following KSPSolve?

Thanks in advance,
Pierre

> On 3 May 2018, at 5:07 PM, Hong  wrote:
> 
> Pierre :
> The code crashes inside
> if (scall == MAT_REUSE_MATRIX) {
> ...
> } 
> which assumes both original matrix and its submatrices data structures remain 
> unchanged.
> We did not anticipate the usage of looping
> 
> 3) change the sparsity pattern of the Mat for one of the field
> 4) do a KSPSolve
>  
> Can you send us a stand-alone code for this type of application.
> We will investigate how to support it.
> 
> Hong
> 
> I cannot change this calling sequence, because I’d like to nest 3) and 4) 
> inside a loop.
> However, I end up with this error during 4):
> [0]PETSC ERROR: Nonconforming object sizes
> [0]PETSC ERROR: Cannot reuse matrix. wrong no of nonzeros
> [0]PETSC ERROR: Petsc Development GIT revision: v3.9-13-g05d412bc58  GIT 
> Date: 2018-04-09 08:39:52 -0500
> 
> [0]PETSC ERROR: #1 MatCreateSubMatrix_SeqAIJ() line 2330 in 
> /Users/jolivet/Documents/repositories/petsc/src/mat/impls/aij/seq/aij.c
> [0]PETSC ERROR: #2 MatCreateSubMatrix_MPIAIJ_SameRowColDist() line 3184 in 
> /Users/jolivet/Documents/repositories/petsc/src/mat/impls/aij/mpi/mpiaij.c
> [0]PETSC ERROR: #3 MatCreateSubMatrix_MPIAIJ() line 3310 in 
> /Users/jolivet/Documents/repositories/petsc/src/mat/impls/aij/mpi/mpiaij.c
> [0]PETSC ERROR: #4 MatCreateSubMatrix() line 7813 in 
> /Users/jolivet/Documents/repositories/petsc/src/mat/interface/matrix.c
> [0]PETSC ERROR: #5 PCSetUp_FieldSplit() line 564 in 
> /Users/jolivet/Documents/repositories/petsc/src/ksp/pc/impls/fieldsplit/fieldsplit.c
> [0]PETSC ERROR: #6 PCSetUp() line 923 in 
> /Users/jolivet/Documents/repositories/petsc/src/ksp/pc/interface/precon.c
> [0]PETSC ERROR: #7 PCApply() line 453 in 
> /Users/jolivet/Documents/repositories/petsc/src/ksp/pc/interface/precon.c
> [0]PETSC ERROR: #8 KSP_PCApply() line 276 in 
> /Users/jolivet/repo/petsc/include/petsc/private/kspimpl.h
> [0]PETSC ERROR: #9 KSPFGMRESCycle() line 166 in 
> /Users/jolivet/Documents/repositories/petsc/src/ksp/ksp/impls/gmres/fgmres/fgmres.c
> [0]PETSC ERROR: #10 KSPSolve_FGMRES() line 291 in 
> /Users/jolivet/Documents/repositories/petsc/src/ksp/ksp/impls/gmres/fgmres/fgmres.c
> [0]PETSC ERROR: #11 KSPSolve() line 669 in 
> /Users/jolivet/Documents/repositories/petsc/src/ksp/ksp/interface/itfunc.c
> 
> Is this the expected behaviour? Would you need a MWE?
> What I find funny is that if I turn -info on, then just before the error, I 
> get:
> [0] PCSetUp(): Setting up PC with different nonzero pattern
> So why is it trying to reuse the matrix? I am missing a call to some function?
> 
> Thanks in advance,
> Pierre
> 



Re: [petsc-dev] GCC8 Fortran length changes from int to size_t

2018-05-03 Thread Jeff Hammond
Yes.  John Linford (formerly of ParaTools, Inc. aka TAU team, now at ARM)
developed such a thing for OpenSHMEM.

Jeff

-- Forwarded message --
I've written a Fortran bindings generator that uses ISO_C_BINDING to link a
Fortran code to any SHMEM implementation with C linkage:
https://github.com/jlinford/shmem_iso_c_binding. shmem.f90 in that repo
provides the complete OpenSHMEM 1.2 API.

We can use this and the TAU Performance System to automatically generate
Fortran interfaces for just about any OpenSHMEM implementation, and to
update bindings as the API expands, in support of
https://github.com/openshmem-org/specification/pull/48.

There are some quirks of using ISO_C_BINDING, e.g. shmem_malloc needs a
following call to c_f_pointer and C_PTRDIFF_T isn't available in some
compilers so I used C_INTPTR_T as a workaround.   See rotput.f90 in the
repo for details.


On Thu, May 3, 2018 at 8:50 AM, Smith, Barry F.  wrote:

>
>Jeff, (and others),
>
>  Do you know of a tool that can take a C prototype and automatically
> generate the Fortran C binding interface definition? We currently generate
> stubs for C functions that have character arguments manually and it would
> be great to remove that manual step.
>
>Thanks
>
>   Barry
>
>
> > On May 2, 2018, at 11:42 PM, Jeff Hammond 
> wrote:
> >
> > Or you could just use ISO_C_BINDING.  Decent compilers should support it.
> >
> > On Wed, May 2, 2018 at 8:56 AM, Jed Brown  wrote:
> > See Fortran Language Issues.
> >
> >   https://gcc.gnu.org/gcc-8/porting_to.html
> >
> > We'll have to test for this (probably compiler version) and change the
> > PETSC_MIXED_LEN / PETSC_END_LEN to use size_t instead of int.
> >
> >
> >
> > --
> > Jeff Hammond
> > jeff.scie...@gmail.com
> > http://jeffhammond.github.io/
>
>


-- 
Jeff Hammond
jeff.scie...@gmail.com
http://jeffhammond.github.io/


Re: [petsc-dev] variable 'length' is uninitialized in src/sys/fileio/mprint.c

2018-05-03 Thread Smith, Barry F.

   Thanks. I have removed the function in commit 08486c302b2  since it is dead, 
unneeded code that I should have removed before.

   Barry


> On May 3, 2018, at 10:19 AM, Vaclav Hapla  wrote:
> 
> Barry,
> this is obviously wrong in current master:
> 
> 14416c0e507 src/sys/fileio/mprint.c 791) size_t length;
> cb500232d0b src/sys/fileio/mprint.c 792) char   buff[length];
> 
> It results in
>  warning: variable 'length' is uninitialized when used here [-Wuninitialized]
> when the PETSC_HAVE_MATLAB_ENGINE macro is defined.
> 
> Vaclav



Re: [petsc-dev] GCC8 Fortran length changes from int to size_t

2018-05-03 Thread Jed Brown
Lisandro Dalcin  writes:

> On 3 May 2018 at 18:50, Smith, Barry F.  wrote:
>>
>>Jeff, (and others),
>>
>>  Do you know of a tool that can take a C prototype and automatically 
>> generate the Fortran C binding interface definition? We currently generate 
>> stubs for C functions that have character arguments manually and it would be 
>> great to remove that manual step.
>>
>
> How do you exactly want to implement that? Totally replace these
> special functions with the BIND(C) interface that calls directly the C
> function, or rather generate a native Fortran subroutine that calls
> the C function through a BIND(C) interface?

The latter.  Usage should not change for existing Fortran users.


Re: [petsc-dev] GCC8 Fortran length changes from int to size_t

2018-05-03 Thread Lisandro Dalcin
On 3 May 2018 at 18:50, Smith, Barry F.  wrote:
>
>Jeff, (and others),
>
>  Do you know of a tool that can take a C prototype and automatically 
> generate the Fortran C binding interface definition? We currently generate 
> stubs for C functions that have character arguments manually and it would be 
> great to remove that manual step.
>

How do you exactly want to implement that? Totally replace these
special functions with the BIND(C) interface that calls directly the C
function, or rather generate a native Fortran subroutine that calls
the C function through a BIND(C) interface?




-- 
Lisandro Dalcin

Research Scientist
Computer, Electrical and Mathematical Sciences & Engineering (CEMSE)
Extreme Computing Research Center (ECRC)
King Abdullah University of Science and Technology (KAUST)
http://ecrc.kaust.edu.sa/

4700 King Abdullah University of Science and Technology
al-Khawarizmi Bldg (Bldg 1), Office # 0109
Thuwal 23955-6900, Kingdom of Saudi Arabia
http://www.kaust.edu.sa

Office Phone: +966 12 808-0459


Re: [petsc-dev] GCC8 Fortran length changes from int to size_t

2018-05-03 Thread Smith, Barry F.

   Jeff, (and others),

 Do you know of a tool that can take a C prototype and automatically 
generate the Fortran C binding interface definition? We currently generate 
stubs for C functions that have character arguments manually and it would be 
great to remove that manual step.

   Thanks

  Barry


> On May 2, 2018, at 11:42 PM, Jeff Hammond  wrote:
> 
> Or you could just use ISO_C_BINDING.  Decent compilers should support it.
> 
> On Wed, May 2, 2018 at 8:56 AM, Jed Brown  wrote:
> See Fortran Language Issues.
> 
>   https://gcc.gnu.org/gcc-8/porting_to.html
> 
> We'll have to test for this (probably compiler version) and change the
> PETSC_MIXED_LEN / PETSC_END_LEN to use size_t instead of int.
> 
> 
> 
> -- 
> Jeff Hammond
> jeff.scie...@gmail.com
> http://jeffhammond.github.io/



[petsc-dev] variable 'length' is uninitialized in src/sys/fileio/mprint.c

2018-05-03 Thread Vaclav Hapla
Barry,
this is obviously wrong in current master:

14416c0e507 src/sys/fileio/mprint.c 791) size_t length;
cb500232d0b src/sys/fileio/mprint.c 792) char   buff[length];

It results in
  warning: variable 'length' is uninitialized when used here [-Wuninitialized]
when the PETSC_HAVE_MATLAB_ENGINE macro is defined.

Vaclav

Re: [petsc-dev] FieldSplit with different nonzero pattern

2018-05-03 Thread Hong
Pierre :
The code crashes inside
if (scall == MAT_REUSE_MATRIX) {
...
}
which assumes both original matrix and its submatrices data structures
remain unchanged.
We did not anticipate the usage of looping

>
> 3) change the sparsity pattern of the Mat for one of the field
> 4) do a KSPSolve
>

Can you send us a stand-alone code for this type of application.
We will investigate how to support it.

Hong

I cannot change this calling sequence, because I’d like to nest 3) and 4)
> inside a loop.
> However, I end up with this error during 4):
> [0]PETSC ERROR: Nonconforming object sizes
> [0]PETSC ERROR: Cannot reuse matrix. wrong no of nonzeros
> [0]PETSC ERROR: Petsc Development GIT revision: v3.9-13-g05d412bc58  GIT
> Date: 2018-04-09 08:39:52 -0500
>
> [0]PETSC ERROR: #1 MatCreateSubMatrix_SeqAIJ() line 2330 in
> /Users/jolivet/Documents/repositories/petsc/src/mat/impls/aij/seq/aij.c
> [0]PETSC ERROR: #2 MatCreateSubMatrix_MPIAIJ_SameRowColDist() line 3184
> in /Users/jolivet/Documents/repositories/petsc/src/mat/
> impls/aij/mpi/mpiaij.c
> [0]PETSC ERROR: #3 MatCreateSubMatrix_MPIAIJ() line 3310 in
> /Users/jolivet/Documents/repositories/petsc/src/mat/impls/aij/mpi/mpiaij.c
> [0]PETSC ERROR: #4 MatCreateSubMatrix() line 7813 in
> /Users/jolivet/Documents/repositories/petsc/src/mat/interface/matrix.c
> [0]PETSC ERROR: #5 PCSetUp_FieldSplit() line 564 in
> /Users/jolivet/Documents/repositories/petsc/src/ksp/pc/
> impls/fieldsplit/fieldsplit.c
> [0]PETSC ERROR: #6 PCSetUp() line 923 in /Users/jolivet/Documents/
> repositories/petsc/src/ksp/pc/interface/precon.c
> [0]PETSC ERROR: #7 PCApply() line 453 in /Users/jolivet/Documents/
> repositories/petsc/src/ksp/pc/interface/precon.c
> [0]PETSC ERROR: #8 KSP_PCApply() line 276 in /Users/jolivet/repo/petsc/
> include/petsc/private/kspimpl.h
> [0]PETSC ERROR: #9 KSPFGMRESCycle() line 166 in /Users/jolivet/Documents/
> repositories/petsc/src/ksp/ksp/impls/gmres/fgmres/fgmres.c
> [0]PETSC ERROR: #10 KSPSolve_FGMRES() line 291 in /Users/jolivet/Documents/
> repositories/petsc/src/ksp/ksp/impls/gmres/fgmres/fgmres.c
> [0]PETSC ERROR: #11 KSPSolve() line 669 in /Users/jolivet/Documents/
> repositories/petsc/src/ksp/ksp/interface/itfunc.c
>
> Is this the expected behaviour? Would you need a MWE?
> What I find funny is that if I turn -info on, then just before the error,
> I get:
> [0] PCSetUp(): Setting up PC with different nonzero pattern
> So why is it trying to reuse the matrix? I am missing a call to some
> function?
>
> Thanks in advance,
> Pierre