Re: [petsc-users] Bug report VecNorm

2023-12-11 Thread Matthew Knepley
We already merged the fix.

  Thanks,

Matt

On Mon, Dec 11, 2023 at 6:00 AM Barry Smith  wrote:

>
>I don't fully understand your code and what it is trying to
> demonstrate, but VecGetArrayWrite is Logically Collective. Having
>
>   if(rank == 0)
>   {
> PetscCall(VecGetArrayWrite(vec, ));
> PetscCall(VecRestoreArrayWrite(vec, ));
>   }
>
> is not allowed.  The reason is that VecRestoreArrayWrite() changes the
> PetscObjectState of the vector, and this state must be changed consistently
> across all MPI processes that share the vector.
>
>
>
> On Dec 10, 2023, at 2:40 AM, Stephan Köhler <
> stephan.koeh...@math.tu-freiberg.de> wrote:
>
> Dear PETSc/Tao team,
>
> there is a bug in the voector interface:  In the function
> VecNorm, see, eg.
> https://petsc.org/release/src/vec/vec/interface/rvector.c.html#VecNorm
> line 197 the check for consistency in line 214 is done on the wrong
> communicator.  The  communicator should be PETSC_COMM_SELF.
> Otherwise the program may hang when PetscCheck is executed.
>
> Please find a minimal example attached.
>
>
> Kind regards,
> Stephan Köhler
>
> --
> Stephan Köhler
> TU Bergakademie Freiberg
> Institut für numerische Mathematik und Optimierung
>
> Akademiestraße 6
> 09599 Freiberg
> Gebäudeteil Mittelbau, Zimmer 2.07
>
> Telefon: +49 (0)3731 39-3188 (Büro)
>
> 
>
>
>

-- 
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] Bug report VecNorm

2023-12-10 Thread Jed Brown
Pierre Jolivet  writes:

>> On 10 Dec 2023, at 8:40 AM, Stephan Köhler 
>>  wrote:
>> 
>> Dear PETSc/Tao team, 
>> 
>> there is a bug in the voector interface:  In the function 
>> VecNorm, see, eg. 
>> https://petsc.org/release/src/vec/vec/interface/rvector.c.html#VecNorm line 
>> 197 the check for consistency in line 214 is done on the wrong communicator. 
>>  The  communicator should be PETSC_COMM_SELF.
>> Otherwise the program may hang when PetscCheck is executed.
>
> I think the communicator should not be changed, but instead, the 
> check/conditional should be changed, à la PetscValidLogicalCollectiveBool().

I agree -- it's no extra cost to discover collectively whether all, none, or 
some have the norm. In this case, it could be a MPI_SUM, in which case the 
error message could report how many processes took each path.


Re: [petsc-users] Bug report VecNorm

2023-12-10 Thread Pierre Jolivet


> On 10 Dec 2023, at 8:40 AM, Stephan Köhler 
>  wrote:
> 
> Dear PETSc/Tao team, 
> 
> there is a bug in the voector interface:  In the function 
> VecNorm, see, eg. 
> https://petsc.org/release/src/vec/vec/interface/rvector.c.html#VecNorm line 
> 197 the check for consistency in line 214 is done on the wrong communicator.  
> The  communicator should be PETSC_COMM_SELF.
> Otherwise the program may hang when PetscCheck is executed.

I think the communicator should not be changed, but instead, the 
check/conditional should be changed, à la PetscValidLogicalCollectiveBool().

Thanks,
Pierre

> Please find a minimal example attached.
> 
> 
> Kind regards, 
> Stephan Köhler
> -- 
> Stephan Köhler
> TU Bergakademie Freiberg
> Institut für numerische Mathematik und Optimierung
> 
> Akademiestraße 6
> 09599 Freiberg
> Gebäudeteil Mittelbau, Zimmer 2.07
> 
> Telefon: +49 (0)3731 39-3188 (Büro)
> 



Re: [petsc-users] Bug report VecNorm

2023-12-10 Thread Matthew Knepley
On Sun, Dec 10, 2023 at 12:57 PM Matthew Knepley  wrote:

> On Sun, Dec 10, 2023 at 12:54 PM Matthew Knepley 
> wrote:
>
>> On Sun, Dec 10, 2023 at 2:41 AM Stephan Köhler <
>> stephan.koeh...@math.tu-freiberg.de> wrote:
>>
>>> Dear PETSc/Tao team,
>>>
>>> there is a bug in the voector interface:  In the function
>>> VecNorm, see, eg.
>>> https://petsc.org/release/src/vec/vec/interface/rvector.c.html#VecNorm
>>> line 197 the check for consistency in line 214 is done on the wrong
>>> communicator.  The  communicator should be PETSC_COMM_SELF.
>>> Otherwise the program may hang when PetscCheck is executed.
>>>
>>> Please find a minimal example attached.
>>>
>>
>> This is entirely right. I will fix it.
>>
>
> Here is the MR.
>

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

  Thanks,

Matt


>   Thanks,
>
> Matt
>
>
>>   Thanks,
>>
>>  Matt
>>
>>
>>>
>>>
>>> Kind regards,
>>> Stephan Köhler
>>>
>>> --
>>> Stephan Köhler
>>> TU Bergakademie Freiberg
>>> Institut für numerische Mathematik und Optimierung
>>>
>>> Akademiestraße 6
>>> 09599 Freiberg
>>> Gebäudeteil Mittelbau, Zimmer 2.07
>>>
>>> Telefon: +49 (0)3731 39-3188 (Büro)
>>>
>>>
>>
>> --
>> 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/
> 
>


-- 
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] Bug report VecNorm

2023-12-10 Thread Matthew Knepley
On Sun, Dec 10, 2023 at 12:54 PM Matthew Knepley  wrote:

> On Sun, Dec 10, 2023 at 2:41 AM Stephan Köhler <
> stephan.koeh...@math.tu-freiberg.de> wrote:
>
>> Dear PETSc/Tao team,
>>
>> there is a bug in the voector interface:  In the function
>> VecNorm, see, eg.
>> https://petsc.org/release/src/vec/vec/interface/rvector.c.html#VecNorm
>> line 197 the check for consistency in line 214 is done on the wrong
>> communicator.  The  communicator should be PETSC_COMM_SELF.
>> Otherwise the program may hang when PetscCheck is executed.
>>
>> Please find a minimal example attached.
>>
>
> This is entirely right. I will fix it.
>

Here is the MR.

  Thanks,

Matt


>   Thanks,
>
>  Matt
>
>
>>
>>
>> Kind regards,
>> Stephan Köhler
>>
>> --
>> Stephan Köhler
>> TU Bergakademie Freiberg
>> Institut für numerische Mathematik und Optimierung
>>
>> Akademiestraße 6
>> 09599 Freiberg
>> Gebäudeteil Mittelbau, Zimmer 2.07
>>
>> Telefon: +49 (0)3731 39-3188 (Büro)
>>
>>
>
> --
> 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/ 


Re: [petsc-users] Bug report VecNorm

2023-12-10 Thread Matthew Knepley
On Sun, Dec 10, 2023 at 2:41 AM Stephan Köhler <
stephan.koeh...@math.tu-freiberg.de> wrote:

> Dear PETSc/Tao team,
>
> there is a bug in the voector interface:  In the function
> VecNorm, see, eg.
> https://petsc.org/release/src/vec/vec/interface/rvector.c.html#VecNorm
> line 197 the check for consistency in line 214 is done on the wrong
> communicator.  The  communicator should be PETSC_COMM_SELF.
> Otherwise the program may hang when PetscCheck is executed.
>
> Please find a minimal example attached.
>

This is entirely right. I will fix it.

  Thanks,

 Matt


>
>
> Kind regards,
> Stephan Köhler
>
> --
> Stephan Köhler
> TU Bergakademie Freiberg
> Institut für numerische Mathematik und Optimierung
>
> Akademiestraße 6
> 09599 Freiberg
> Gebäudeteil Mittelbau, Zimmer 2.07
>
> Telefon: +49 (0)3731 39-3188 (Büro)
>
>

-- 
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] Bug report VecNorm

2023-12-10 Thread Barry Smith

   I don't fully understand your code and what it is trying to demonstrate, but 
VecGetArrayWrite is Logically Collective. Having 

  if(rank == 0)
  {
PetscCall(VecGetArrayWrite(vec, ));
PetscCall(VecRestoreArrayWrite(vec, ));
  }

is not allowed.  The reason is that VecRestoreArrayWrite() changes the 
PetscObjectState of the vector, and this state must be changed consistently 
across all MPI processes that share the vector. 



> On Dec 10, 2023, at 2:40 AM, Stephan Köhler 
>  wrote:
> 
> Dear PETSc/Tao team, 
> 
> there is a bug in the voector interface:  In the function 
> VecNorm, see, eg. 
> https://petsc.org/release/src/vec/vec/interface/rvector.c.html#VecNorm line 
> 197 the check for consistency in line 214 is done on the wrong communicator.  
> The  communicator should be PETSC_COMM_SELF.
> Otherwise the program may hang when PetscCheck is executed.
> 
> Please find a minimal example attached.
> 
> 
> Kind regards, 
> Stephan Köhler
> -- 
> Stephan Köhler
> TU Bergakademie Freiberg
> Institut für numerische Mathematik und Optimierung
> 
> Akademiestraße 6
> 09599 Freiberg
> Gebäudeteil Mittelbau, Zimmer 2.07
> 
> Telefon: +49 (0)3731 39-3188 (Büro)
> 



[petsc-users] Bug report VecNorm

2023-12-09 Thread Stephan Köhler

Dear PETSc/Tao team,

there is a bug in the voector interface:  In the function
VecNorm, see, eg. 
https://petsc.org/release/src/vec/vec/interface/rvector.c.html#VecNorm 
line 197 the check for consistency in line 214 is done on the wrong 
communicator.  The communicator should be PETSC_COMM_SELF.

Otherwise the program may hang when PetscCheck is executed.

Please find a minimal example attached.


Kind regards,
Stephan Köhler

--
Stephan Köhler
TU Bergakademie Freiberg
Institut für numerische Mathematik und Optimierung

Akademiestraße 6
09599 Freiberg
Gebäudeteil Mittelbau, Zimmer 2.07

Telefon: +49 (0)3731 39-3188 (Büro)

#include "petscvec.h"

int main(int argc, char **args)
{
  PetscMPIInt size, rank;
  Vec vec;
  PetscReal   norm;
  PetscBool   flg = PETSC_FALSE, minflg = PETSC_FALSE;
  MPI_Commcomm;
  PetscScalar *xx;

  PetscCall(PetscInitialize(, , PETSC_NULLPTR, PETSC_NULLPTR));

  comm = PETSC_COMM_WORLD;
  PetscCallMPI(MPI_Comm_size(comm, ));
  PetscCallMPI(MPI_Comm_rank(comm, ));
  PetscCheck(size > 1, comm, PETSC_ERR_ARG_WRONG, "example should be called with more than 1 MPI rank.");

  PetscCall(VecCreateMPI(comm, (rank+1)*10, PETSC_DETERMINE, ));
  PetscCall(VecSet(vec, 1.0));
  PetscCall(VecNorm(vec, NORM_INFINITY, ));

  PetscSynchronizedPrintf(PETSC_COMM_WORLD, "rank = %d, size = %d, norm = %lf\n", rank, size, norm);
  PetscSynchronizedFlush(comm, PETSC_STDOUT);

  if(rank == 0)
  {
PetscCall(VecGetArrayWrite(vec, ));
PetscCall(VecRestoreArrayWrite(vec, ));
  }

  PetscCall(VecNormAvailable(vec, NORM_INFINITY, , ));

  PetscSynchronizedPrintf(comm, "rank = %d, size = %d, flg = %d, norm = %lf\n", rank, size, flg, norm);
  PetscSynchronizedFlush(comm, PETSC_STDOUT);

  PetscCall(MPIU_Allreduce(, , 1, MPIU_BOOL, MPI_LAND, PetscObjectComm((PetscObject)vec)));
  /* wrong */
  PetscCheck(flg == minflg, PetscObjectComm((PetscObject)vec), PETSC_ERR_ARG_WRONGSTATE, "Some MPI processes have cached norm, others do not. This may happen when some MPI processes call VecGetArray() and some others do not.");
  /* this is correct */
  // PetscCheck(flg == minflg, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Some MPI processes have cached norm, others do not. This may happen when some MPI processes call VecGetArray() and some others do not.");

  PetscCall(VecDestroy());

  PetscFinalize();

  return 0;

}


OpenPGP_0xC9BF2C20DFE9F713.asc
Description: OpenPGP public key


OpenPGP_signature.asc
Description: OpenPGP digital signature