Re: [petsc-users] Installing Triangle for PETSc by not using --download

2022-11-04 Thread Satish Balay via petsc-users
On Fri, 4 Nov 2022, Mike Michell wrote:

> Thank you very much. It seems that --download-package={downloaded_dir} is
> the right way to let PETSc know the source files and let it configures &
> installs everything as it wants.
> If I try --with-packages-download-dir, PETSc again tries to connect and get
> the external packages from online, which I cannot do.

No - it tells you what to download - and where to place it locally. In my 
example below - I used 'git clone' but you can use rsync or any other mechanism 
that you are currently using to copy stuff over.

And sure  --download-package=/local/location/[tarball,git,dir] also works .

Satish

> 
> Thanks,
> 
> 
> > Can you try the --with-packages-download-dir option?
> >
> > It tells you the URL to download - and then PETSc configure does the
> > install.
> >
> > Satish
> >
> > 
> >
> > balay@p1 /home/balay/petsc (release =)
> > $ ./configure --with-packages-download-dir=$HOME/tmp --download-triangle
> > Download the following packages to /home/balay/tmp
> >
> > triangle ['git://https://bitbucket.org/petsc/pkg-triangle', '
> > https://bitbucket.org/petsc/pkg-triangle/get/v1.3-p2.tar.gz']
> >
> > Then run the script again
> >
> > balay@p1 /home/balay/petsc (release =)
> > $ pushd $HOME/tmp
> > ~/tmp ~/petsc
> > balay@p1 /home/balay/tmp
> > $ git clone -q https://bitbucket.org/petsc/pkg-triangle
> > balay@p1 /home/balay/tmp
> > $ popd
> > ~/petsc
> > balay@p1 /home/balay/petsc (release =)
> > $ ./configure --with-packages-download-dir=$HOME/tmp --download-triangle
> >
> > =
> >  Configuring PETSc to compile on your system
> >
> > =
> >
> > =
> > Running /home/balay/soft/sowing-1.1.26-p1/bin/bfort to generate
> > Fortran stubs
> >
> > =
> >
> > =
> >  Trying to download /home/balay/tmp/pkg-triangle for
> > TRIANGLE
> >
> > =
> >
> > =
> >   Compiling Triangle; this may take several minutes
> >
> > =
> >
> > =
> >   Installing Triangle; this may take several minutes
> >
> > =
> > TESTING: checklsame from
> > config.packages.BlasLapack(config/BuildSystem/config/packages/BlasLapack.py:691)
> >
> > ...
> > ..
> >
> >
> > On Fri, 4 Nov 2022, Mike Michell wrote:
> >
> > > Hi,
> > >
> > > I need to install PETSc and its dependencies to a linux system, which
> > does
> > > not allow git clone from online. Thus I need to install all the
> > > dependencies by having their source files. First I downloaded and
> > installed
> > > all the dependencies by relying on PETSc on my local linux (which means I
> > > used --download=triangle), then tar all of them, and brought them to the
> > > cluster.
> > >
> > > There is an issue with Triangle. I can do make (or cmake using the
> > > CMakeList file that Triangle 1.6 provides, although PETSc --download
> > > provides Triangle 1.3) and can get "libtriangle.a". But during the PETSc
> > > configure step, it fails with the error message below:
> > >
> > > {$Triangle_Home}/build/libtriangle.a(triangle.c.o): In function
> > `poolinit':
> > > triangle.c:(.text+0x15aa): undefined reference to `PetscTrMalloc'
> > > {$Triangle_Home}/build/libtriangle.a(triangle.c.o): In function
> > > `pooldeinit':
> > > triangle.c:(.text+0x1708): undefined reference to `PetscTrFree'
> > > ...
> > >
> > > It seems that I need to let Triangle know that it will be used by PETSc
> > to
> > > enable those functions when I install Triangle. Is this correct
> > > understanding? If so, how can I configure, install, and link Triangle
> > with
> > > PETSc?
> > >
> > > I have seen some PETSc related commands in configure.py in the root
> > > directory of Triangle downloaded by PETSc, but it is not clear how this
> > > python script is related or can be used by user like me.
> > >
> > > Thanks,
> > > Mike
> > >
> >
> >
> 



Re: [petsc-users] Installing Triangle for PETSc by not using --download

2022-11-04 Thread Mike Michell
Thank you very much. It seems that --download-package={downloaded_dir} is
the right way to let PETSc know the source files and let it configures &
installs everything as it wants.
If I try --with-packages-download-dir, PETSc again tries to connect and get
the external packages from online, which I cannot do.

Thanks,


> Can you try the --with-packages-download-dir option?
>
> It tells you the URL to download - and then PETSc configure does the
> install.
>
> Satish
>
> 
>
> balay@p1 /home/balay/petsc (release =)
> $ ./configure --with-packages-download-dir=$HOME/tmp --download-triangle
> Download the following packages to /home/balay/tmp
>
> triangle ['git://https://bitbucket.org/petsc/pkg-triangle', '
> https://bitbucket.org/petsc/pkg-triangle/get/v1.3-p2.tar.gz']
>
> Then run the script again
>
> balay@p1 /home/balay/petsc (release =)
> $ pushd $HOME/tmp
> ~/tmp ~/petsc
> balay@p1 /home/balay/tmp
> $ git clone -q https://bitbucket.org/petsc/pkg-triangle
> balay@p1 /home/balay/tmp
> $ popd
> ~/petsc
> balay@p1 /home/balay/petsc (release =)
> $ ./configure --with-packages-download-dir=$HOME/tmp --download-triangle
>
> =
>  Configuring PETSc to compile on your system
>
> =
>
> =
> Running /home/balay/soft/sowing-1.1.26-p1/bin/bfort to generate
> Fortran stubs
>
> =
>
> =
>  Trying to download /home/balay/tmp/pkg-triangle for
> TRIANGLE
>
> =
>
> =
>   Compiling Triangle; this may take several minutes
>
> =
>
> =
>   Installing Triangle; this may take several minutes
>
> =
> TESTING: checklsame from
> config.packages.BlasLapack(config/BuildSystem/config/packages/BlasLapack.py:691)
>
> ...
> ..
>
>
> On Fri, 4 Nov 2022, Mike Michell wrote:
>
> > Hi,
> >
> > I need to install PETSc and its dependencies to a linux system, which
> does
> > not allow git clone from online. Thus I need to install all the
> > dependencies by having their source files. First I downloaded and
> installed
> > all the dependencies by relying on PETSc on my local linux (which means I
> > used --download=triangle), then tar all of them, and brought them to the
> > cluster.
> >
> > There is an issue with Triangle. I can do make (or cmake using the
> > CMakeList file that Triangle 1.6 provides, although PETSc --download
> > provides Triangle 1.3) and can get "libtriangle.a". But during the PETSc
> > configure step, it fails with the error message below:
> >
> > {$Triangle_Home}/build/libtriangle.a(triangle.c.o): In function
> `poolinit':
> > triangle.c:(.text+0x15aa): undefined reference to `PetscTrMalloc'
> > {$Triangle_Home}/build/libtriangle.a(triangle.c.o): In function
> > `pooldeinit':
> > triangle.c:(.text+0x1708): undefined reference to `PetscTrFree'
> > ...
> >
> > It seems that I need to let Triangle know that it will be used by PETSc
> to
> > enable those functions when I install Triangle. Is this correct
> > understanding? If so, how can I configure, install, and link Triangle
> with
> > PETSc?
> >
> > I have seen some PETSc related commands in configure.py in the root
> > directory of Triangle downloaded by PETSc, but it is not clear how this
> > python script is related or can be used by user like me.
> >
> > Thanks,
> > Mike
> >
>
>


Re: [petsc-users] Installing Triangle for PETSc by not using --download

2022-11-04 Thread Satish Balay via petsc-users
Can you try the --with-packages-download-dir option?

It tells you the URL to download - and then PETSc configure does the install.

Satish



balay@p1 /home/balay/petsc (release =)
$ ./configure --with-packages-download-dir=$HOME/tmp --download-triangle
Download the following packages to /home/balay/tmp 

triangle ['git://https://bitbucket.org/petsc/pkg-triangle', 
'https://bitbucket.org/petsc/pkg-triangle/get/v1.3-p2.tar.gz']

Then run the script again

balay@p1 /home/balay/petsc (release =)
$ pushd $HOME/tmp
~/tmp ~/petsc
balay@p1 /home/balay/tmp
$ git clone -q https://bitbucket.org/petsc/pkg-triangle
balay@p1 /home/balay/tmp
$ popd
~/petsc
balay@p1 /home/balay/petsc (release =)
$ ./configure --with-packages-download-dir=$HOME/tmp --download-triangle
=
 Configuring PETSc to compile on your system
=
=
Running /home/balay/soft/sowing-1.1.26-p1/bin/bfort to generate Fortran 
stubs
=
=
 Trying to download /home/balay/tmp/pkg-triangle for TRIANGLE
=
=
  Compiling Triangle; this may take several minutes
=
=
  Installing Triangle; this may take several minutes
=
TESTING: checklsame from 
config.packages.BlasLapack(config/BuildSystem/config/packages/BlasLapack.py:691)

...
..


On Fri, 4 Nov 2022, Mike Michell wrote:

> Hi,
> 
> I need to install PETSc and its dependencies to a linux system, which does
> not allow git clone from online. Thus I need to install all the
> dependencies by having their source files. First I downloaded and installed
> all the dependencies by relying on PETSc on my local linux (which means I
> used --download=triangle), then tar all of them, and brought them to the
> cluster.
> 
> There is an issue with Triangle. I can do make (or cmake using the
> CMakeList file that Triangle 1.6 provides, although PETSc --download
> provides Triangle 1.3) and can get "libtriangle.a". But during the PETSc
> configure step, it fails with the error message below:
> 
> {$Triangle_Home}/build/libtriangle.a(triangle.c.o): In function `poolinit':
> triangle.c:(.text+0x15aa): undefined reference to `PetscTrMalloc'
> {$Triangle_Home}/build/libtriangle.a(triangle.c.o): In function
> `pooldeinit':
> triangle.c:(.text+0x1708): undefined reference to `PetscTrFree'
> ...
> 
> It seems that I need to let Triangle know that it will be used by PETSc to
> enable those functions when I install Triangle. Is this correct
> understanding? If so, how can I configure, install, and link Triangle with
> PETSc?
> 
> I have seen some PETSc related commands in configure.py in the root
> directory of Triangle downloaded by PETSc, but it is not clear how this
> python script is related or can be used by user like me.
> 
> Thanks,
> Mike
> 



Re: [petsc-users] PCMGSetResidual and fortran

2022-11-04 Thread Barry Smith


  Steven,

Could you please send your test code. It is possible there is a bug in our 
Fortran interface since we do not test it for this functionality. 

  Barry


> On Nov 4, 2022, at 10:50 AM, Steven Dargaville  
> wrote:
> 
> Hi all
> 
> I have a quick question regarding the use of PCMGSetResidual within fortran 
> code. I'm calling PCMGSetResidual from within fortran: 
> 
> call PCMGSetResidual(pc_mg, petsc_level, mg_residual, coarse_matrix ierr) 
> 
> and just for testing purposes I've written a trivial residual evaluation 
> routine:
> 
> subroutine mg_residual(mat, b, x, r, ierr)
>   !!< Compute the residual
> 
>   ! ~~
>   type(tMat) :: mat
>   type(tVec) :: b, x, r
>   PetscErrorCode :: ierr
>   ! ~~
> 
>   print *, "inside residual evaluation"
>   call MatResidual(mat, b, x, r, ierr)
>   
>end subroutine
> 
> The problem I am having is that this segfaults when the residual routine is 
> called. Valgrind shows that it is failing in the fortran interface in 
> ftn-custom/zmgfuncf.c, with the message:
> 
> ==24742== Invalid read of size 8
> ==24742==at 0x5B7CBC0: ourresidualfunction (in 
> /home/projects/dependencies/petsc_main/arch-linux-c-opt/lib/libpetsc.so.3.015.0)
> ==24742==by 0x5B6D804: PCMGMCycle_Private (in 
> /home/projects/dependencies/petsc_main/arch-linux-c-opt/lib/libpetsc.so.3.015.0)
> 
> ==24742== Process terminating with default action of signal 11 (SIGSEGV)
> ==24742==  Access not within mapped region at address 0x0
> ==24742==at 0x5B7CBC0: ourresidualfunction (in 
> /home/sdargavi/projects/dependencies/petsc_main/arch-linux-c-opt/lib/libpetsc.so.3.015.0)
> ==24742==by 0x5B6D804: PCMGMCycle_Private (in 
> /home/sdargavi/projects/dependencies/petsc_main/arch-linux-c-opt/lib/libpetsc.so.3.015.0)
> 
> I'm guessing this is because the fortran_func_pointers isn't pointing to the 
> mg_residual routine, but I am not sure why. I noticed that in the C code of 
> PCMGSetResidual that it calls MatDestroy on the A matrix in mg_levels and 
> replaces it with the mat passed in:
> 
> if (mat) PetscObjectReference((PetscObject)mat);
> MatDestroy([l]->A);
> mglevels[l]->A = mat
> 
> so I modified my code to call PCMGSetResidual either before the operators are 
> set, or after but passing in an extra copy, but this doesn't seem to help.
> 
> I'm guessing I'm doing something silly, but just wondering if anyone had any 
> ideas? Thanks for your help
> Steven



[petsc-users] Installing Triangle for PETSc by not using --download

2022-11-04 Thread Mike Michell
Hi,

I need to install PETSc and its dependencies to a linux system, which does
not allow git clone from online. Thus I need to install all the
dependencies by having their source files. First I downloaded and installed
all the dependencies by relying on PETSc on my local linux (which means I
used --download=triangle), then tar all of them, and brought them to the
cluster.

There is an issue with Triangle. I can do make (or cmake using the
CMakeList file that Triangle 1.6 provides, although PETSc --download
provides Triangle 1.3) and can get "libtriangle.a". But during the PETSc
configure step, it fails with the error message below:

{$Triangle_Home}/build/libtriangle.a(triangle.c.o): In function `poolinit':
triangle.c:(.text+0x15aa): undefined reference to `PetscTrMalloc'
{$Triangle_Home}/build/libtriangle.a(triangle.c.o): In function
`pooldeinit':
triangle.c:(.text+0x1708): undefined reference to `PetscTrFree'
...

It seems that I need to let Triangle know that it will be used by PETSc to
enable those functions when I install Triangle. Is this correct
understanding? If so, how can I configure, install, and link Triangle with
PETSc?

I have seen some PETSc related commands in configure.py in the root
directory of Triangle downloaded by PETSc, but it is not clear how this
python script is related or can be used by user like me.

Thanks,
Mike


Re: [petsc-users] On the usage of MatSetValuesBlocked

2022-11-04 Thread Edoardo alinovi
Yes,

I did not set the block size for the vector... Missed it!

I think I have nailed the way to handle block matrix/vectors, I am moving
now on to solve the next facy error which is a ksp_diverged_its 

thanks gents for the support with this block madness :)


Re: [petsc-users] On the usage of MatSetValuesBlocked

2022-11-04 Thread Barry Smith



> On Nov 4, 2022, at 6:55 AM, Edoardo alinovi  wrote:
> 
> Thanks Matt,
> 
> I have found out that setValuesblocked will work if I do:
> 
> call MatCreateVecs(A, x, y, ierr)
> call setValuesBlocked(x, nblocks, varray, ierr) 

  Ah, likely the block size for the vector was not correct, leading to the 
memory corruption. MatCreateVecs() creates a vector compatible with the matrix, 
same block size and parallel layout so you don't need to worry about setting 
those values yourself.

  Barry

> 
> However, there is nogetValuesBlocked. Not the end of the world, it is handy 
> to set and get stuff by block and not by single entry :)
> 
> Cheers



[petsc-users] PCMGSetResidual and fortran

2022-11-04 Thread Steven Dargaville
Hi all

I have a quick question regarding the use of PCMGSetResidual within fortran
code. I'm calling PCMGSetResidual from within fortran:

call PCMGSetResidual(pc_mg, petsc_level, mg_residual, coarse_matrix ierr)

and just for testing purposes I've written a trivial residual evaluation
routine:

subroutine mg_residual(mat, b, x, r, ierr)
  !!< Compute the residual

  ! ~~
  type(tMat) :: mat
  type(tVec) :: b, x, r
  PetscErrorCode :: ierr
  ! ~~

  print *, "inside residual evaluation"
  call MatResidual(mat, b, x, r, ierr)

   end subroutine

The problem I am having is that this segfaults when the residual routine is
called. Valgrind shows that it is failing in the fortran interface in
ftn-custom/zmgfuncf.c, with the message:

==24742== Invalid read of size 8
==24742==at 0x5B7CBC0: ourresidualfunction (in
/home/projects/dependencies/petsc_main/arch-linux-c-opt/lib/libpetsc.so.3.015.0)
==24742==by 0x5B6D804: PCMGMCycle_Private (in
/home/projects/dependencies/petsc_main/arch-linux-c-opt/lib/libpetsc.so.3.015.0)

==24742== Process terminating with default action of signal 11 (SIGSEGV)
==24742==  Access not within mapped region at address 0x0
==24742==at 0x5B7CBC0: ourresidualfunction (in
/home/sdargavi/projects/dependencies/petsc_main/arch-linux-c-opt/lib/libpetsc.so.3.015.0)
==24742==by 0x5B6D804: PCMGMCycle_Private (in
/home/sdargavi/projects/dependencies/petsc_main/arch-linux-c-opt/lib/libpetsc.so.3.015.0)

I'm guessing this is because the fortran_func_pointers isn't pointing to
the mg_residual routine, but I am not sure why. I noticed that in the C
code of PCMGSetResidual that it calls MatDestroy on the A matrix in
mg_levels and replaces it with the mat passed in:

if (mat) PetscObjectReference((PetscObject)mat);
MatDestroy([l]->A);
mglevels[l]->A = mat

so I modified my code to call PCMGSetResidual either before the operators
are set, or after but passing in an extra copy, but this doesn't seem to
help.

I'm guessing I'm doing something silly, but just wondering if anyone had
any ideas? Thanks for your help
Steven


Re: [petsc-users] locate DMSwarm particles with respect to a background DMDA mesh

2022-11-04 Thread Matthew Knepley
On Fri, Nov 4, 2022 at 7:46 AM Matteo Semplice <
matteo.sempl...@uninsubria.it> wrote:

> On 04/11/2022 02:43, Matthew Knepley wrote:
>
> On Thu, Nov 3, 2022 at 8:36 PM Matthew Knepley  wrote:
>
>> On Thu, Oct 27, 2022 at 11:57 AM Semplice Matteo <
>> matteo.sempl...@uninsubria.it> wrote:
>>
>>> Dear Petsc developers,
>>> I am trying to use a DMSwarm to locate a cloud of points with
>>> respect to a background mesh. In the real application the points will be
>>> loaded from disk, but I have created a small demo in which
>>>
>>>- each processor creates Npart particles, all within the domain
>>>covered by the mesh, but not all in the local portion of the mesh
>>>- migrate the particles
>>>
>>> After migration most particles are not any more in the DMSwarm (how many
>>> and which ones seems to depend on the number of cpus, but it never happens
>>> that all particle survive the migration process).
>>>
>>> I am clearly missing some step, since I'd expect that a DMDA would be
>>> able to locate particles without the need to go through a DMShell as it is
>>> done in src/dm/tutorials/swarm_ex3.c.html
>>> 
>>>
>>> I attach my demo code.
>>>
>>> Could someone give me a hint?
>>>
>>
>> Thanks for sending this. I found the problem. Someone has some overly
>> fancy code inside DMDA to figure out the local bounding box from the
>> coordinates.
>> It is broken for DM_BOUNDARY_GHOSTED, but we never tested with this. I
>> will fix it.
>>
>
> Okay, I think this fix is correct
>
>   https://gitlab.com/petsc/petsc/-/merge_requests/5802
> 
>
> I incorporated your test as src/dm/impls/da/tests/ex1.c. Can you take a
> look and see if this fixes your issue?
>
> Yes, we have tested 2d and 3d, with various combinations of DM_BOUNDARY_*
> along different directions and it works like a charm.
>
> On a side note, neither DMSwarmViewXDMF nor DMSwarmMigrate seem to be
> implemented for 1d: I get
>
> [0]PETSC ERROR: No support for this operation for this object type
>   
>   [0]PETSC
> ERROR: Support not provided for 1D
>
> However, currently I have no need for this feature.
>
> Finally, if the test is meant to stay in the source, you may remove the
> call to DMSwarmRegisterPetscDatatypeField as in the attached patch.
>
> Thanks a lot!!
>
>
Thanks! Glad it works.

   Matt


> Matteo and Silvia
>
>
>   Thanks,
>
>  Matt
>
>
>>   Thanks,
>>
>>  Matt
>>
>>
>>> Best
>>> Matteo
>>>
>>>
>>
>> --
>> 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/
>> 
>>
>
>
> --
> 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/
> 
>
> --
> Prof. Matteo Semplice
> Università degli Studi dell’Insubria
> Dipartimento di Scienza e Alta Tecnologia – DiSAT
> Professore Associato
> Via Valleggio, 11 – 22100 Como (CO) – Italia
> tel.: +39 031 2386316
>
>

-- 
What most experimenters take for granted before they begin their
experiments is 

Re: [petsc-users] locate DMSwarm particles with respect to a background DMDA mesh

2022-11-04 Thread Matteo Semplice

On 04/11/2022 02:43, Matthew Knepley wrote:

On Thu, Nov 3, 2022 at 8:36 PM Matthew Knepley  wrote:

On Thu, Oct 27, 2022 at 11:57 AM Semplice Matteo
 wrote:

Dear Petsc developers,
I am trying to use a DMSwarm to locate a cloud of points with
respect to a background mesh. In the real application the
points will be loaded from disk, but I have created a small
demo in which

  * each processor creates Npart particles, all within the
domain covered by the mesh, but not all in the local
portion of the mesh
  * migrate the particles

After migration most particles are not any more in the DMSwarm
(how many and which ones seems to depend on the number of
cpus, but it never happens that all particle survive the
migration process).

I am clearly missing some step, since I'd expect that a DMDA
would be able to locate particles without the need to go
through a DMShell as it is done in
src/dm/tutorials/swarm_ex3.c.html



I attach my demo code.

Could someone give me a hint?


Thanks for sending this. I found the problem. Someone has some
overly fancy code inside DMDA to figure out the local bounding box
from the coordinates.
It is broken for DM_BOUNDARY_GHOSTED, but we never tested with
this. I will fix it.


Okay, I think this fix is correct

https://gitlab.com/petsc/petsc/-/merge_requests/5802 



I incorporated your test as src/dm/impls/da/tests/ex1.c. Can you take 
a look and see if this fixes your issue?


Yes, we have tested 2d and 3d, with various combinations of 
DM_BOUNDARY_* along different directions and it works like a charm.


On a side note, neither DMSwarmViewXDMF nor DMSwarmMigrate seem to be 
implemented for 1d: I get


[0]PETSC ERROR: No support for this operation for this object 
type[0]PETSC ERROR: Support not provided for 1D


However, currently I have no need for this feature.

Finally, if the test is meant to stay in the source, you may remove the 
call to DMSwarmRegisterPetscDatatypeField as in the attached patch.


Thanks a lot!!

    Matteo and Silvia



  Thanks,

     Matt

  Thanks,

     Matt

Best
    Matteo



-- 
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/





--
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/ 



--
Prof. Matteo Semplice
Università degli Studi dell’Insubria
Dipartimento di Scienza e Alta Tecnologia – DiSAT
Professore Associato
Via Valleggio, 11 – 22100 Como (CO) – Italia
tel.: +39 031 2386316
diff --git a/src/dm/impls/da/tests/ex1.c b/src/dm/impls/da/tests/ex1.c
index d7d77ead3d5..3926aeaa52f 100644
--- a/src/dm/impls/da/tests/ex1.c
+++ b/src/dm/impls/da/tests/ex1.c
@@ -53,7 +53,6 @@ int main(int argc, char **argv)
   PetscCall(DMSetFromOptions(sw));
   PetscCall(DMSwarmSetCellDM(sw, dm));
   PetscCall(DMSwarmInitializeFieldRegister(sw));
-  

Re: [petsc-users] Report Bug TaoALMM class

2022-11-04 Thread Stephan Köhler

Barry,

this is a nonartificial code.  This is a problem in the ALMM subsolver.  
I want to solve a problem with a TaoALMM solver what then happens is:


TaoSolve(tao)    /* TaoALMM solver */
   |
   |
   |>   This calls the TaoALMM subsolver routine

 TaoSolve(subsolver)
   |
   |
   |--->   The subsolver does not correctly 
work, at least with an Armijo line search, since the solution is 
overwritten within the line search.
   In my case, the subsolver does 
not make any progress although it is possible.


To get to my real problem you can simply change line 268 to if(0) (from 
if(1) -> if(0)) and line 317 from // ierr = TaoSolve(tao); 
CHKERRQ(ierr);  ---> ierr = TaoSolve(tao); CHKERRQ(ierr);
What you can see is that the solver does not make any progress, but it 
should make progress.


To be honest, I do not really know why the option 
-tao_almm_subsolver_tao_ls_monitor has know effect if the ALMM solver is 
called and not the subsolver. I also do not know why 
-tao_almm_subsolver_tao_view prints as termination reason for the subsolver


 Solution converged:    ||g(X)|| <= gatol

This is obviously not the case.  I set the tolerance
-tao_almm_subsolver_tao_gatol 1e-8 \
-tao_almm_subsolver_tao_grtol 1e-8 \

I encountered this and then I looked into the ALMM class and therefore I 
tried to call the subsolver (previous example).


I attach the updated programm and also the options.

Stephan






On 03.11.22 22:15, Barry Smith wrote:


  Thanks for your response and the code. I understand the potential 
problem and how your code demonstrates a bug if the 
TaoALMMSubsolverObjective() is used in the manner you use in the 
example where you directly call TaoComputeObjective() multiple times 
line a line search code might.


  What I don't have or understand is how to reproduce the problem in a 
real code that uses Tao. That is where the Tao Armijo line search code 
has a problem when it is used (somehow) in a Tao solver with ALMM. You 
suggest "If you have an example for your own, you can switch the 
Armijo line search by the option -tao_ls_type armijo.  The thing is 
that it will cause no problems if the line search accepts the steps 
with step length one."  I don't see how to do this if I use -tao_type 
almm I cannot use -tao_ls_type armijo; that is the option -tao_ls_type 
doesn't seem to me to be usable in the context of almm (since almm 
internally does directly its own trust region approach for 
globalization). If we remove the if (1) code from your example, is 
there some Tao options I can use to get the bug to appear inside the 
Tao solve?


I'll try to explain again, I agree that the fact that the Tao solution 
is aliased (within the ALMM solver) is a problem with repeated calls 
to TaoComputeObjective() but I cannot see how these repeated calls 
could ever happen in the use of TaoSolve() with the ALMM solver. That 
is when is this "design problem" a true problem as opposed to just a 
potential problem that can be demonstrated in artificial code?


The reason I need to understand the non-artificial situation it breaks 
things is to come up with an appropriate correction for the current code.


  Barry







On Nov 3, 2022, at 12:46 PM, Stephan Köhler 
 wrote:


Barry,

so far, I have not experimented with trust-region methods, but I can 
imagine that this "design feature" causes no problem for trust-region 
methods, if the old point is saved and after the trust-region check 
fails the old point is copied to the actual point.  But the 
implementation of the Armijo line search method does not work that 
way.  Here, the actual point will always be overwritten.  Only if the 
line search fails, then the old point is restored, but then the 
TaoSolve method ends with a line search failure.


If you have an example for your own, you can switch the Armijo line 
search by the option -tao_ls_type armijo.  The thing is that it will 
cause no problems if the line search accepts the steps with step 
length one.
It is also possible that, by luck, it will cause no problems, if the 
"excessive" step brings a reduction of the objective


Otherwise, I attach my example, which is not minimal, but here you 
can see that it causes problems.  You need to set the paths to the 
PETSc library in the makefile.  You find the options for this problem 
in the run_test_tao_neohooke.sh script.

The import part begins at line 292 in test_tao_neohooke.cpp

Stephan

On 02.11.22 19:04, Barry Smith wrote:

   Stephan,

 I have located the troublesome line in TaoSetUp_ALMM() it has the line

   auglag->Px = tao->solution;

and in alma.h it has

Vec  Px, LgradX, Ce, Ci, G; /* aliased vectors (do not destroy!) */

Now auglag->P in some situations alias auglag->P  and in some cases auglag->Px 
serves to hold a portion of auglag->P. So then in 

Re: [petsc-users] On the usage of MatSetValuesBlocked

2022-11-04 Thread Edoardo alinovi
Thanks Matt,

I have found out that setValuesblocked will work if I do:

call MatCreateVecs(A, x, y, ierr)
call setValuesBlocked(x, nblocks, varray, ierr)

However, there is nogetValuesBlocked. Not the end of the world, it is handy
to set and get stuff by block and not by single entry :)

Cheers


Re: [petsc-users] On the usage of MatSetValuesBlocked

2022-11-04 Thread Matthew Knepley
On Fri, Nov 4, 2022 at 4:32 AM Edoardo alinovi 
wrote:

> It is working like a charm now!
>
> Is it mandatory to use VecSetValuesBlocked to assemble the rhs? Does the
> Vec need to be of any other type than VECMPI?
>

SetValuesBlocked() is never required. You can always use the normal
versions, but you would have to supply all the indices, not just the block
indices.

  Thanks,

 Matt


> I am assembling it like this:
> brhs(1:3-bdim) = this%Ueqn%bC(iElement,1:3-bdim)
> brhs(4-bdim) = this%Peqn%bC(iElement,1)
> call VecSetValuesBlocked(this%rhs, 1,
> mesh%cellGlobalAddr(iElement)-1, brhs, INSERT_VALUES, ierr)
>
> But I am getting into troubles:
>
> [0]PETSC ERROR: - Error Message
> --
> [0]PETSC ERROR: *PetscSegBufferAlloc_Private*
> [0]PETSC ERROR: See https://petsc.org/release/faq/ for trouble shooting.
> [0]PETSC ERROR: Petsc Release Version 3.18.0, Sep 30, 2022
> [0]PETSC ERROR: flubio_coupled on a gnu named alienware by edo Fri Nov  4
> 09:31:03 2022
> [0]PETSC ERROR: Configure options PETSC_ARCH=gnu FOPTFLAGS=-O3
> COPTFLAGS=-O3 CXXOPTFLAGS=-O3 -with-debugging=no -download-fblaslapack=1
> -download-superlu_dist -download-mumps -download-hypre -download-metis
> -download-parmetis -download-scalapack -download-ml -download-slepc
> -download-hpddm -download-cmake
> -with-mpi-dir=/home/edo/software/openmpi-4.1.1/build/
> [0]PETSC ERROR: #1 PetscMallocAlign() at
> /home/edo/software/petsc-3.18.0/src/sys/memory/mal.c:55
> [0]PETSC ERROR: #2 PetscSegBufferAlloc_Private() at
> /home/edo/software/petsc-3.18.0/src/sys/utils/segbuffer.c:31
> [0]PETSC ERROR: #3 PetscSegBufferGet() at
> /home/edo/software/petsc-3.18.0/src/sys/utils/segbuffer.c:94
> [1]PETSC ERROR: - Error Message
> --
> [1]PETSC ERROR: General MPI error
> [1]PETSC ERROR: MPI error 1 MPI_ERR_BUFFER: invalid buffer pointer
> [1]PETSC ERROR: See https://petsc.org/release/faq/ for trouble shooting.
> [1]PETSC ERROR: Petsc Release Version 3.18.0, Sep 30, 2022
> [1]PETSC ERROR: flubio_coupled on a gnu named alienware by edo Fri Nov  4
> 09:31:03 2022
> [1]PETSC ERROR: Configure options PETSC_ARCH=gnu FOPTFLAGS=-O3
> COPTFLAGS=-O3 CXXOPTFLAGS=-O3 -with-debugging=no -download-fblaslapack=1
> -download-superlu_dist -download-mumps -download-hypre -download-metis
> -download-parmetis -download-scalapack -download-ml -download-slepc
> -download-hpddm -download-cmake
> -with-mpi-dir=/home/edo/software/openmpi-4.1.1/build/
> [1]PETSC ERROR: #1 VecAssemblySend_MPI_Private() at
> /home/edo/software/petsc-3.18.0/src/vec/vec/impls/mpi/pbvec.c:133
> [1]PETSC ERROR: #2 PetscCommBuildTwoSidedFReq_Reference() at
> /home/edo/software/petsc-3.18.0/src/sys/utils/mpits.c:314
> [1]PETSC ERROR: #3 PetscCommBuildTwoSidedFReq() at
> /home/edo/software/petsc-3.18.0/src/sys/utils/mpits.c:526
> [1]PETSC ERROR: [0]PETSC ERROR: #4 VecAssemblyRecv_MPI_Private() at
> /home/edo/software/petsc-3.18.0/src/vec/vec/impls/mpi/pbvec.c:164
> [0]PETSC ERROR: #5 PetscCommBuildTwoSidedFReq_Reference() at
> /home/edo/software/petsc-3.18.0/src/sys/utils/mpits.c:320
> [0]PETSC ERROR: #6 PetscCommBuildTwoSidedFReq() at
> /home/edo/software/petsc-3.18.0/src/sys/utils/mpits.c:526
> [0]PETSC ERROR: #7 VecAssemblyBegin_MPI_BTS() at
> /home/edo/software/petsc-3.18.0/src/vec/vec/impls/mpi/pbvec.c:238
> #4 VecAssemblyBegin_MPI_BTS() at
> /home/edo/software/petsc-3.18.0/src/vec/vec/impls/mpi/pbvec.c:238
> [1]PETSC ERROR: #5 VecAssemblyBegin() at
> /home/edo/software/petsc-3.18.0/src/vec/vec/interface/vector.c:124
> [1]PETSC ERROR: #6 VecAssemblyEnd_MPI_BTS() at
> /home/edo/software/petsc-3.18.0/src/vec/vec/impls/mpi/pbvec.c:337
> [1]PETSC ERROR: #7 VecAssemblyEnd() at
> /home/edo/software/petsc-3.18.0/src/vec/vec/interface/vector.c:158
> [1]PETSC ERROR: #8 VecView() at
> /home/edo/software/petsc-3.18.0/src/vec/vec/interface/vector.c:719
> [0]PETSC ERROR: #8 VecAssemblyBegin() at
> /home/edo/software/petsc-3.18.0/src/vec/vec/interface/vector.c:124
> Vec Object: 2 MPI processes
>
>

-- 
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/ 


Re: [petsc-users] On the usage of MatSetValuesBlocked

2022-11-04 Thread Edoardo alinovi
It is working like a charm now!

Is it mandatory to use VecSetValuesBlocked to assemble the rhs? Does the
Vec need to be of any other type than VECMPI?

I am assembling it like this:
brhs(1:3-bdim) = this%Ueqn%bC(iElement,1:3-bdim)
brhs(4-bdim) = this%Peqn%bC(iElement,1)
call VecSetValuesBlocked(this%rhs, 1,
mesh%cellGlobalAddr(iElement)-1, brhs, INSERT_VALUES, ierr)

But I am getting into troubles:

[0]PETSC ERROR: - Error Message
--
[0]PETSC ERROR: *PetscSegBufferAlloc_Private*
[0]PETSC ERROR: See https://petsc.org/release/faq/ for trouble shooting.
[0]PETSC ERROR: Petsc Release Version 3.18.0, Sep 30, 2022
[0]PETSC ERROR: flubio_coupled on a gnu named alienware by edo Fri Nov  4
09:31:03 2022
[0]PETSC ERROR: Configure options PETSC_ARCH=gnu FOPTFLAGS=-O3
COPTFLAGS=-O3 CXXOPTFLAGS=-O3 -with-debugging=no -download-fblaslapack=1
-download-superlu_dist -download-mumps -download-hypre -download-metis
-download-parmetis -download-scalapack -download-ml -download-slepc
-download-hpddm -download-cmake
-with-mpi-dir=/home/edo/software/openmpi-4.1.1/build/
[0]PETSC ERROR: #1 PetscMallocAlign() at
/home/edo/software/petsc-3.18.0/src/sys/memory/mal.c:55
[0]PETSC ERROR: #2 PetscSegBufferAlloc_Private() at
/home/edo/software/petsc-3.18.0/src/sys/utils/segbuffer.c:31
[0]PETSC ERROR: #3 PetscSegBufferGet() at
/home/edo/software/petsc-3.18.0/src/sys/utils/segbuffer.c:94
[1]PETSC ERROR: - Error Message
--
[1]PETSC ERROR: General MPI error
[1]PETSC ERROR: MPI error 1 MPI_ERR_BUFFER: invalid buffer pointer
[1]PETSC ERROR: See https://petsc.org/release/faq/ for trouble shooting.
[1]PETSC ERROR: Petsc Release Version 3.18.0, Sep 30, 2022
[1]PETSC ERROR: flubio_coupled on a gnu named alienware by edo Fri Nov  4
09:31:03 2022
[1]PETSC ERROR: Configure options PETSC_ARCH=gnu FOPTFLAGS=-O3
COPTFLAGS=-O3 CXXOPTFLAGS=-O3 -with-debugging=no -download-fblaslapack=1
-download-superlu_dist -download-mumps -download-hypre -download-metis
-download-parmetis -download-scalapack -download-ml -download-slepc
-download-hpddm -download-cmake
-with-mpi-dir=/home/edo/software/openmpi-4.1.1/build/
[1]PETSC ERROR: #1 VecAssemblySend_MPI_Private() at
/home/edo/software/petsc-3.18.0/src/vec/vec/impls/mpi/pbvec.c:133
[1]PETSC ERROR: #2 PetscCommBuildTwoSidedFReq_Reference() at
/home/edo/software/petsc-3.18.0/src/sys/utils/mpits.c:314
[1]PETSC ERROR: #3 PetscCommBuildTwoSidedFReq() at
/home/edo/software/petsc-3.18.0/src/sys/utils/mpits.c:526
[1]PETSC ERROR: [0]PETSC ERROR: #4 VecAssemblyRecv_MPI_Private() at
/home/edo/software/petsc-3.18.0/src/vec/vec/impls/mpi/pbvec.c:164
[0]PETSC ERROR: #5 PetscCommBuildTwoSidedFReq_Reference() at
/home/edo/software/petsc-3.18.0/src/sys/utils/mpits.c:320
[0]PETSC ERROR: #6 PetscCommBuildTwoSidedFReq() at
/home/edo/software/petsc-3.18.0/src/sys/utils/mpits.c:526
[0]PETSC ERROR: #7 VecAssemblyBegin_MPI_BTS() at
/home/edo/software/petsc-3.18.0/src/vec/vec/impls/mpi/pbvec.c:238
#4 VecAssemblyBegin_MPI_BTS() at
/home/edo/software/petsc-3.18.0/src/vec/vec/impls/mpi/pbvec.c:238
[1]PETSC ERROR: #5 VecAssemblyBegin() at
/home/edo/software/petsc-3.18.0/src/vec/vec/interface/vector.c:124
[1]PETSC ERROR: #6 VecAssemblyEnd_MPI_BTS() at
/home/edo/software/petsc-3.18.0/src/vec/vec/impls/mpi/pbvec.c:337
[1]PETSC ERROR: #7 VecAssemblyEnd() at
/home/edo/software/petsc-3.18.0/src/vec/vec/interface/vector.c:158
[1]PETSC ERROR: #8 VecView() at
/home/edo/software/petsc-3.18.0/src/vec/vec/interface/vector.c:719
[0]PETSC ERROR: #8 VecAssemblyBegin() at
/home/edo/software/petsc-3.18.0/src/vec/vec/interface/vector.c:124
Vec Object: 2 MPI processes


Re: [petsc-users] On the usage of MatSetValuesBlocked

2022-11-04 Thread Edoardo alinovi
Barry,

Thanks, yes, I should pass 1 and not 3 For some reason I have
misunderstood the wording in the documentation and I have interpreted m and
n as the number of row and columns of the block to insert, while I need to
think of everything as divided by bs... Now I am with you!!!

Many thanks and sorry to have been so dump! 