[petsc-users] Different behavior of code on different machines

2019-07-20 Thread Yuyun Yang via petsc-users
Hello team,

I'm encountering a problem with my code's behavior on multiple processors. When 
I run it on my personal computer it works just fine, but when I use it on our 
computing cluster it produces an error (in one of the root-finding functions, 
an assert statement is not satisfied) and aborts.

If I just run on one processor then both machines can run the code just fine, 
but they give different results (maybe due to roundoff errors).

I'm not sure how to proceed with debugging (since I usually do it on my own 
computer which didn't seem to encounter a bug) and would appreciate your 
advice. Thank you!

Best regards,
Yuyun


Re: [petsc-users] Question on KSPSetReusePreconditioner

2019-04-18 Thread Yuyun Yang via petsc-users
I see, thanks for the helpful answers!

Best regards,
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>

From: Smith, Barry F. 
Sent: Thursday, April 18, 2019 3:51:27 PM
To: Yuyun Yang
Cc: petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] Question on KSPSetReusePreconditioner



> On Apr 18, 2019, at 10:44 AM, Yuyun Yang via petsc-users 
>  wrote:
>
> Hello team,
>
> I have a question on when I should be setting KSPSetReusePreconditioner to 
> PETSC_TRUE or PETSC_FALSE. It made a pretty big difference in the solutions I 
> get when I ran my code testing both settings, so is recalculating the 
> preconditioner better since it will make the convergence faster and the 
> solution more accurate?

   Reusing the preconditioner should have no significant impact on the accuracy 
of the solution to the linear system. The answers will be different but that 
should only be up to the tolerance you provided with -ksp_rtol   But after many 
time-steps the final "answer" to the time dependent problem may be very 
different with different preconditioning approaches due to accumulation of 
different round-offs. But if both preconditioner approaches solve the linear 
system to the same accuracy then neither answer is more correct than the other.

> On the other hand, if the operator is updated every time step (but same 
> nonzero pattern), will reconstructing the pc become time-consuming?

  Whether to reuse the preconditioner depends completely on the problem. Reuse 
means more linear iterations but less setup time (for the preconditioner). So 
the relative cost of iterations to setup time dictates the optimal use of 
KSPSetReusePreconditioner() and can only be determined by making some timing 
runs with different choices and picking the one that seems fastest for your 
problem.

   Barry

>
> Thank you!
> Yuyun



Re: [petsc-users] Question on KSPSetReusePreconditioner

2019-04-18 Thread Yuyun Yang via petsc-users
Let’s say I’m using HYPRE’s boomeramg preconditioner. Could we say anything 
about convergence/pc construction time if the matrix changes significantly from 
one solve to the next vs. slightly changes?

Thanks,
Yuyun

From: Matthew Knepley 
Sent: Thursday, April 18, 2019 9:32 AM
To: Yuyun Yang 
Cc: petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] Question on KSPSetReusePreconditioner

On Thu, Apr 18, 2019 at 11:44 AM Yuyun Yang via petsc-users 
mailto:petsc-users@mcs.anl.gov>> wrote:
Hello team,

I have a question on when I should be setting KSPSetReusePreconditioner to 
PETSC_TRUE or PETSC_FALSE. It made a pretty big difference in the solutions I 
get when I ran my code testing both settings, so is recalculating the 
preconditioner better since it will make the convergence faster and the 
solution more accurate? On the other hand, if the operator is updated every 
time step (but same nonzero pattern), will reconstructing the pc become 
time-consuming?

We cannot say anything since it (at least) depends on a) how much your matrix 
changes from one solve to the next, and b)  what preconditioner you are reusing.

  Thanks,

Matt


Thank you!
Yuyun


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


[petsc-users] Question on KSPSetReusePreconditioner

2019-04-18 Thread Yuyun Yang via petsc-users
Hello team,

I have a question on when I should be setting KSPSetReusePreconditioner to 
PETSC_TRUE or PETSC_FALSE. It made a pretty big difference in the solutions I 
get when I ran my code testing both settings, so is recalculating the 
preconditioner better since it will make the convergence faster and the 
solution more accurate? On the other hand, if the operator is updated every 
time step (but same nonzero pattern), will reconstructing the pc become 
time-consuming?

Thank you!
Yuyun


Re: [petsc-users] Using -malloc_dump to examine memory leak

2019-04-18 Thread Yuyun Yang via petsc-users
Oh thank you, sorry I probably missed that!

-Original Message-
From: Smith, Barry F.  
Sent: Thursday, April 18, 2019 8:36 AM
To: Yuyun Yang 
Cc: petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] Using -malloc_dump to examine memory leak


   Please see my mail from yesterday; perhaps it did not get through

 On Apr 16, 2019, at 11:56 PM, Yuyun Yang  wrote:
> 
> 
> So using -objects_dump showed nothing below the line:
> The following objects were never freed
> -
> Does that mean I’ve freed all the objects? If so, why would -malloc_dump give 
> me a bunch of messages?

 No idea. If you have messages from -malloc_dump then memory has not been freed 
and almost always this is due to undestroyed objects. Presumably you didn't 
turn off logging in ./configure (nobody does that). If you use the option 
-objects_dump this is processed in PetscOptionsCheckInitial_Private() which is 
called from PetscInitialize() with #if defined(PETSC_USE_LOG)  ierr = 
PetscOptionsHasName(NULL,NULL,"-objects_dump",&PetscObjectsLog);CHKERRQ(ierr);
#endif
then in inherit.c each object creation gets logged with

PetscErrorCode  PetscHeaderCreate_Private(PetscObject h,PetscClassId 
classid,const char class_name[],const char descr[],const char mansec[],
 MPI_Comm 
comm,PetscObjectDestroyFunction destroy,PetscObjectViewFunction view) {  static 
PetscInt idcnt = 1;  PetscErrorCode  ierr; #if defined(PETSC_USE_LOG)
 PetscObject *newPetscObjects;
 PetscInt newPetscObjectsMaxCounts,i;
#endif

 PetscFunctionBegin;
 h->classid   = classid;
 h->type  = 0;
 h->class_name= (char*)class_name;
 h->description   = (char*)descr;
 h->mansec= (char*)mansec;
 h->prefix= 0;
 h->refct = 1;
#if defined(PETSC_HAVE_SAWS)
 h->amsmem= PETSC_FALSE;
#endif
 h->id= idcnt++;
 h->parentid  = 0;
 h->qlist = 0;
 h->olist = 0;
 h->bops->destroy = destroy;
 h->bops->view= view;
 h->bops->getcomm = PetscObjectGetComm_Petsc;
 h->bops->compose = PetscObjectCompose_Petsc;
 h->bops->query   = PetscObjectQuery_Petsc;
 h->bops->composefunction = PetscObjectComposeFunction_Petsc;
 h->bops->queryfunction   = PetscObjectQueryFunction_Petsc;

 ierr = PetscCommDuplicate(comm,&h->comm,&h->tag);CHKERRQ(ierr);

#if defined(PETSC_USE_LOG)
 /* Keep a record of object created */
 if (PetscObjectsLog) {
   PetscObjectsCounts++;
   for (i=0; i 
> I also ran valgrind, and am getting the following error when using 
> --track-origins=yes:
> Uninitialised value was created by a stack allocation
> ==617==at 0x417D66: ComputeVel_qd::computeVel(double*, double, int&, int) 
> (fault.cpp:953)
> 
> The first argument of this function is a Petsc array (obtained from 
> VecGetArray, and after calling this function, VecRestoreArray was called on 
> that same object). I can’t think of a way why valgrind thinks there is an 
> uninitialized value. Is this by any chance related to the -malloc_dump 
> messages?

 Should be unrelated to the -malloc_dump message.

 A "stack allocation" is usually a local variable, while the value from 
VecGetArray() is from the heap. Check the use of all your local variables in 
this function.

 Barry


> On Apr 18, 2019, at 10:06 AM, Yuyun Yang  wrote:
> 
> Just wanted to follow up on this question, thanks for your time!
> 
> Best,
> Yuyun
> 
> Get Outlook for iOS
> _
> From: Yuyun Yang 
> Sent: Tuesday, April 16, 2019 21:56
> Subject: RE: [petsc-users] Using -malloc_dump to examine memory leak
> To: Yuyun Yang , Smith, Barry F. 
> 
> 
> 
> So using -objects_dump showed nothing below the line:
> The following objects were never freed
> -
> Does that mean I’ve freed all the objects? If so, why would -malloc_dump give 
> me a bunch of messages?
>  
> I also ran valgrind, and am getting the following error when using 
> --track-origins=yes:
> Uninitialised value was created by a stack allocation
> ==617==at 0x417D66: ComputeVel_qd::computeVel(double*, double, int&, int) 
> (fault.cpp:953)
>  
> The first argument of this function is a Petsc array (obtained from 
> VecGetArray, and after calling this function, VecRestoreArray was called on 
> that same object). I can’t think of a way why valgrind thinks there is an 
> uninitialized value. Is this by any chance related to the -malloc_dump 
> messages?
>  
> Thanks for your help on this.
>  
> Best regards,
> Yuyun
>  
> From: petsc-use

Re: [petsc-users] Using -malloc_dump to examine memory leak

2019-04-18 Thread Yuyun Yang via petsc-users
Just wanted to follow up on this question, thanks for your time!

Best,
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>
_
From: Yuyun Yang mailto:yyan...@stanford.edu>>
Sent: Tuesday, April 16, 2019 21:56
Subject: RE: [petsc-users] Using -malloc_dump to examine memory leak
To: Yuyun Yang mailto:yyan...@stanford.edu>>, Smith, 
Barry F. mailto:bsm...@mcs.anl.gov>>


So using -objects_dump showed nothing below the line:
The following objects were never freed
-
Does that mean I’ve freed all the objects? If so, why would -malloc_dump give 
me a bunch of messages?

I also ran valgrind, and am getting the following error when using 
--track-origins=yes:
Uninitialised value was created by a stack allocation
==617==at 0x417D66: ComputeVel_qd::computeVel(double*, double, int&, int) 
(fault.cpp:953)

The first argument of this function is a Petsc array (obtained from 
VecGetArray, and after calling this function, VecRestoreArray was called on 
that same object). I can’t think of a way why valgrind thinks there is an 
uninitialized value. Is this by any chance related to the -malloc_dump messages?

Thanks for your help on this.

Best regards,
Yuyun

From: petsc-users 
mailto:petsc-users-boun...@mcs.anl.gov>> On 
Behalf Of Yuyun Yang via petsc-users
Sent: Tuesday, April 16, 2019 7:30 AM
To: Smith, Barry F. mailto:bsm...@mcs.anl.gov>>
Cc: petsc-users@mcs.anl.gov<mailto:petsc-users@mcs.anl.gov>
Subject: Re: [petsc-users] Using -malloc_dump to examine memory leak

Great, thank you for the advice!

Best regards,
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>

From: Smith, Barry F. mailto:bsm...@mcs.anl.gov>>
Sent: Tuesday, April 16, 2019 5:54:15 AM
To: Yuyun Yang
Cc: petsc-users@mcs.anl.gov<mailto:petsc-users@mcs.anl.gov>
Subject: Re: [petsc-users] Using -malloc_dump to examine memory leak


  Please try the flag -options_dump this tries to give a much more concise view 
of what objects have not been freed. For example I commented
out the last VecDestroy() in src/snes/examples/tutorials/ex19.c and then 
obtained:

./ex19 -objects_dump
lid velocity = 0.0625, prandtl # = 1., grashof # = 1.
Number of SNES iterations = 2
The following objects were never freed
-
[0] DM da DM_0x8400_0
  [0]  DMDACreate2d() in /Users/barrysmith/Src/petsc/src/dm/impls/da/da2.c
  [0]  main() in 
/Users/barrysmith/Src/petsc/src/snes/examples/tutorials/ex19.c
[0] Vec seq Vec_0x8400_6
  [0]  DMCreateGlobalVector() in 
/Users/barrysmith/Src/petsc/src/dm/interface/dm.c
  [0]  main() in 
/Users/barrysmith/Src/petsc/src/snes/examples/tutorials/ex19.c

Now I just need to look at the calls to DMCreateGlobalVector and DMDACreate2d 
in main to see what I did not free.

Note that since PETSc objects may hold references to other PETSc objects some 
items may not be freed for which you DID call destroy on.
For example because the unfreed vector holds a reference to the DM the DM is 
listed as not freed. Once you properly destroy the vector you'll
not that the DM is no longer listed as non freed.

It can be a little overwhelming at first to figure out what objects have not 
been freed. We recommending setting the environmental variable
export PETSC_OPTIONS=-malloc_test so that every run of your code reports memory 
issues and you can keep them under control from
the beginning (when the code is small and growing) rather than wait until the 
code is large and there are many unfreed objects to chase down.

   Good luck



   Barry


> On Apr 16, 2019, at 1:14 AM, Yuyun Yang via petsc-users 
> mailto:petsc-users@mcs.anl.gov>> wrote:
>
> Hello team,
>
> I’m trying to use the options -malloc_dump and -malloc_debug to examine 
> memory leaks. The messages however, are quite generic, and don’t really tell 
> me where the problems occur, for example:
>
> [ 0]1520 bytes VecCreate() line 35 in 
> /home/yyy910805/petsc/src/vec/vec/interface/veccreate.c
>   [0]  PetscMallocA() line 35 in 
> /home/yyy910805/petsc/src/sys/memory/mal.c
>   [0]  VecCreate() line 30 in 
> /home/yyy910805/petsc/src/vec/vec/interface/veccreate.c
>   [0]  VecDuplicate_Seq() line 804 in 
> /home/yyy910805/petsc/src/vec/vec/impls/seq/bvec2.c
>   [0]  VecDuplicate() line 375 in 
> /home/yyy910805/petsc/src/vec/vec/interface/vector.c
>
> The code is huge, so going through every single VecCreate/VecDuplicate and 
> VecDestroy is going to be time-consuming. Meanwhile, running valgrind gave me 
> some uninitialized values errors that don’t seem to be related to the above 
> message (or maybe they are?).
>
> How can I use this option to debug effectively?
>
> Thanks a lot,
> Yuyun




Re: [petsc-users] Using -malloc_dump to examine memory leak

2019-04-16 Thread Yuyun Yang via petsc-users
Great, thank you for the advice!

Best regards,
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>

From: Smith, Barry F. 
Sent: Tuesday, April 16, 2019 5:54:15 AM
To: Yuyun Yang
Cc: petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] Using -malloc_dump to examine memory leak


  Please try the flag -options_dump this tries to give a much more concise view 
of what objects have not been freed. For example I commented
out the last VecDestroy() in src/snes/examples/tutorials/ex19.c and then 
obtained:

./ex19 -objects_dump
lid velocity = 0.0625, prandtl # = 1., grashof # = 1.
Number of SNES iterations = 2
The following objects were never freed
-
[0] DM da DM_0x8400_0
  [0]  DMDACreate2d() in /Users/barrysmith/Src/petsc/src/dm/impls/da/da2.c
  [0]  main() in 
/Users/barrysmith/Src/petsc/src/snes/examples/tutorials/ex19.c
[0] Vec seq Vec_0x8400_6
  [0]  DMCreateGlobalVector() in 
/Users/barrysmith/Src/petsc/src/dm/interface/dm.c
  [0]  main() in 
/Users/barrysmith/Src/petsc/src/snes/examples/tutorials/ex19.c

Now I just need to look at the calls to DMCreateGlobalVector and DMDACreate2d 
in main to see what I did not free.

Note that since PETSc objects may hold references to other PETSc objects some 
items may not be freed for which you DID call destroy on.
For example because the unfreed vector holds a reference to the DM the DM is 
listed as not freed. Once you properly destroy the vector you'll
not that the DM is no longer listed as non freed.

It can be a little overwhelming at first to figure out what objects have not 
been freed. We recommending setting the environmental variable
export PETSC_OPTIONS=-malloc_test so that every run of your code reports memory 
issues and you can keep them under control from
the beginning (when the code is small and growing) rather than wait until the 
code is large and there are many unfreed objects to chase down.

   Good luck



   Barry


> On Apr 16, 2019, at 1:14 AM, Yuyun Yang via petsc-users 
>  wrote:
>
> Hello team,
>
> I’m trying to use the options -malloc_dump and -malloc_debug to examine 
> memory leaks. The messages however, are quite generic, and don’t really tell 
> me where the problems occur, for example:
>
> [ 0]1520 bytes VecCreate() line 35 in 
> /home/yyy910805/petsc/src/vec/vec/interface/veccreate.c
>   [0]  PetscMallocA() line 35 in 
> /home/yyy910805/petsc/src/sys/memory/mal.c
>   [0]  VecCreate() line 30 in 
> /home/yyy910805/petsc/src/vec/vec/interface/veccreate.c
>   [0]  VecDuplicate_Seq() line 804 in 
> /home/yyy910805/petsc/src/vec/vec/impls/seq/bvec2.c
>   [0]  VecDuplicate() line 375 in 
> /home/yyy910805/petsc/src/vec/vec/interface/vector.c
>
> The code is huge, so going through every single VecCreate/VecDuplicate and 
> VecDestroy is going to be time-consuming. Meanwhile, running valgrind gave me 
> some uninitialized values errors that don’t seem to be related to the above 
> message (or maybe they are?).
>
> How can I use this option to debug effectively?
>
> Thanks a lot,
> Yuyun



[petsc-users] Using -malloc_dump to examine memory leak

2019-04-15 Thread Yuyun Yang via petsc-users
Hello team,

I'm trying to use the options -malloc_dump and -malloc_debug to examine memory 
leaks. The messages however, are quite generic, and don't really tell me where 
the problems occur, for example:

[ 0]1520 bytes VecCreate() line 35 in 
/home/yyy910805/petsc/src/vec/vec/interface/veccreate.c
  [0]  PetscMallocA() line 35 in /home/yyy910805/petsc/src/sys/memory/mal.c
  [0]  VecCreate() line 30 in 
/home/yyy910805/petsc/src/vec/vec/interface/veccreate.c
  [0]  VecDuplicate_Seq() line 804 in 
/home/yyy910805/petsc/src/vec/vec/impls/seq/bvec2.c
  [0]  VecDuplicate() line 375 in 
/home/yyy910805/petsc/src/vec/vec/interface/vector.c

The code is huge, so going through every single VecCreate/VecDuplicate and 
VecDestroy is going to be time-consuming. Meanwhile, running valgrind gave me 
some uninitialized values errors that don't seem to be related to the above 
message (or maybe they are?).

How can I use this option to debug effectively?

Thanks a lot,
Yuyun


Re: [petsc-users] Question about KSP, and makefile linking MPICH

2019-04-13 Thread Yuyun Yang via petsc-users
I tried using another linear solver (via command line options) and the 
binaryoutput file was produced, but nothing was produced for MumpsCholesky. 
Does that mean it didn't even do a single linear solve?

Best regards,
Yuyun

-Original Message-
From: Smith, Barry F.  
Sent: Saturday, April 13, 2019 7:08 PM
To: Yuyun Yang 
Cc: petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] Question about KSP, and makefile linking MPICH


  It will be in the directory where the program is run. 

  Perhaps you are not calling KSPSetFromOptions()? This is where it is checked.

   Barry


> On Apr 13, 2019, at 7:24 PM, Yuyun Yang  wrote:
> 
> I tried doing -ksp_view_mat binary, but I don't see the binaryoutput file 
> being produced in my output or source file directories. Is it located 
> somewhere else?
> 
> Best regards,
> Yuyun
> 
> -Original Message-
> From: Smith, Barry F. 
> Sent: Thursday, April 11, 2019 10:21 PM
> To: Yuyun Yang 
> Cc: petsc-users@mcs.anl.gov
> Subject: Re: [petsc-users] Question about KSP, and makefile linking 
> MPICH
> 
> 
>  Ok, still a little odd. PCSetOperators() which is called internally by 
> KSPSetOperators() checks if the matrix has changed size and generates an 
> error. Similar if you set a different matrix from before it resets the 
> computation of the preconditioner. So, in theory, your situation should never 
> occur.
> 
>   Barry
> 
> 
>> On Apr 12, 2019, at 12:01 AM, Yuyun Yang  wrote:
>> 
>> I think this problem arose because I did not reset the ksp for 
>> solving a different problem! It's not giving me an error anymore now 
>> that I added the reset, so it's all good :)
>> 
>> Thanks,
>> Yuyun
>> 
>> Get Outlook for iOS
>> From: Smith, Barry F. 
>> Sent: Thursday, April 11, 2019 9:21:11 PM
>> To: Yuyun Yang
>> Cc: petsc-users@mcs.anl.gov
>> Subject: Re: [petsc-users] Question about KSP, and makefile linking 
>> MPICH
>> 
>> 
>>   Ahh, I just realized one other thing we can try. Run the program that 
>> crashes with -ksp_mat_view binary  this will produce a file called 
>> binaryoutput, send that file to petsc-ma...@mcs.anl.gov and we'll see if we 
>> can get MUMPS to mis-behave with it also.
>> 
>>   Barry
>> 
>> 
>> 
>>> On Apr 11, 2019, at 11:17 PM, Yuyun Yang  wrote:
>>> 
>>> Thanks Barry for the detailed answers!
>>> 
>>> Regarding the problem with valgrind, this is the only error produced, and 
>>> if I allow it to run further, the program would break (at a later function 
>>> I get NaN for some of the values being calculated, and I've put an assert 
>>> to prevent NaN results). I will take a look at it in the debugger. This is 
>>> for testing, but for bigger problems I won't end up using Cholesky, so it's 
>>> not really a big issue.
>>> 
>>> Thanks again for the timely help!
>>> Yuyun
>>> 
>>> Get Outlook for iOS
>>> From: Smith, Barry F. 
>>> Sent: Thursday, April 11, 2019 6:44:54 PM
>>> To: Yuyun Yang
>>> Cc: petsc-users@mcs.anl.gov
>>> Subject: Re: [petsc-users] Question about KSP, and makefile linking 
>>> MPICH
>>> 
>>> 
>>> 
>>>> On Apr 11, 2019, at 5:44 PM, Yuyun Yang via petsc-users 
>>>>  wrote:
>>>> 
>>>> Hello team,
>>>> 
>>>> I’d like to check if it’s ok to use the same ksp object and change its 
>>>> operator (the matrix A) later on in the code to solve a different problem?
>>> 
>>>   Do you mean call KSPSetOperators() with one matrix and then later 
>>> call it with a different matrix? This is ok if the two matrices are 
>>> the same size and have the same parallel layout. But if the matrices 
>>> are different size, have different parallel layout then you need to 
>>> destroy the KSP and create a new one or call KSPReset() in between 
>>> for example
>>> 
>>>  KSPSetFromOptions(ksp);
>>>  KSPSetOperators(ksp,A,A);
>>>  KSPSolve(ksp,b,x);
>>>  KSPReset(ksp);
>>>  KSPSetOperators(ksp,B,B);
>>>  KSPSolve(ksp,newb,newx);
>>> 
>>>> 
>>>> Also, I know I’ve asked this before about linking to MPICH when I 
>>>> call mpirun, instead of using my computer’s default MPI, but I want 
>>>> to check again. The same problem was solved on my cluster by using 
>>>> a different CLINKER (called mpiicc) in the Makefile and a different 
>>>> intel compiler, which will link my compi

Re: [petsc-users] Question about KSP, and makefile linking MPICH

2019-04-13 Thread Yuyun Yang via petsc-users
I tried doing -ksp_view_mat binary, but I don't see the binaryoutput file being 
produced in my output or source file directories. Is it located somewhere else?

Best regards,
Yuyun

-Original Message-
From: Smith, Barry F.  
Sent: Thursday, April 11, 2019 10:21 PM
To: Yuyun Yang 
Cc: petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] Question about KSP, and makefile linking MPICH


  Ok, still a little odd. PCSetOperators() which is called internally by 
KSPSetOperators() checks if the matrix has changed size and generates an error. 
Similar if you set a different matrix from before it resets the computation of 
the preconditioner. So, in theory, your situation should never occur.

   Barry


> On Apr 12, 2019, at 12:01 AM, Yuyun Yang  wrote:
> 
> I think this problem arose because I did not reset the ksp for solving 
> a different problem! It's not giving me an error anymore now that I 
> added the reset, so it's all good :)
> 
> Thanks,
> Yuyun
> 
> Get Outlook for iOS
> From: Smith, Barry F. 
> Sent: Thursday, April 11, 2019 9:21:11 PM
> To: Yuyun Yang
> Cc: petsc-users@mcs.anl.gov
> Subject: Re: [petsc-users] Question about KSP, and makefile linking 
> MPICH
>  
> 
>Ahh, I just realized one other thing we can try. Run the program that 
> crashes with -ksp_mat_view binary  this will produce a file called 
> binaryoutput, send that file to petsc-ma...@mcs.anl.gov and we'll see if we 
> can get MUMPS to mis-behave with it also.
> 
>Barry
> 
> 
> 
> > On Apr 11, 2019, at 11:17 PM, Yuyun Yang  wrote:
> > 
> > Thanks Barry for the detailed answers!
> > 
> > Regarding the problem with valgrind, this is the only error produced, and 
> > if I allow it to run further, the program would break (at a later function 
> > I get NaN for some of the values being calculated, and I've put an assert 
> > to prevent NaN results). I will take a look at it in the debugger. This is 
> > for testing, but for bigger problems I won't end up using Cholesky, so it's 
> > not really a big issue.
> > 
> > Thanks again for the timely help!
> > Yuyun
> > 
> > Get Outlook for iOS
> > From: Smith, Barry F. 
> > Sent: Thursday, April 11, 2019 6:44:54 PM
> > To: Yuyun Yang
> > Cc: petsc-users@mcs.anl.gov
> > Subject: Re: [petsc-users] Question about KSP, and makefile linking 
> > MPICH
> >  
> > 
> > 
> > > On Apr 11, 2019, at 5:44 PM, Yuyun Yang via petsc-users 
> > >  wrote:
> > > 
> > > Hello team,
> > >  
> > > I’d like to check if it’s ok to use the same ksp object and change its 
> > > operator (the matrix A) later on in the code to solve a different problem?
> > 
> >Do you mean call KSPSetOperators() with one matrix and then later 
> > call it with a different matrix? This is ok if the two matrices are 
> > the same size and have the same parallel layout. But if the matrices 
> > are different size, have different parallel layout then you need to 
> > destroy the KSP and create a new one or call KSPReset() in between 
> > for example
> > 
> >   KSPSetFromOptions(ksp);
> >   KSPSetOperators(ksp,A,A);
> >   KSPSolve(ksp,b,x); 
> >   KSPReset(ksp);
> >   KSPSetOperators(ksp,B,B);
> >   KSPSolve(ksp,newb,newx);
> > 
> > >  
> > > Also, I know I’ve asked this before about linking to MPICH when I 
> > > call mpirun, instead of using my computer’s default MPI, but I 
> > > want to check again. The same problem was solved on my cluster by 
> > > using a different CLINKER (called mpiicc) in the Makefile and a 
> > > different intel compiler, which will link my compiled code with 
> > > MPICH. Is there a similar thing I can do on my own computer, 
> > > instead of having to use a very long path to locate the MPICH I 
> > > configured with PETSc, and then calling the executable? (I tried 
> > > making CLINKER = mpiicc on my own computer but that didn’t work.)
> > 
> > Are you asking how you can avoid something like
> > 
> >   /home/me/petsc/arch-myarch/bin/mpiexec -n 2 ./mycode ?
> > 
> >You can add /home/me/petsc/arch-myarch/bin to the beginning of 
> > your PATH, for example with bash put the following into your 
> > ~/.bashrc file
> > 
> >   export PATH=/home/me/petsc/arch-myarch/bin:$PATH
> >   mpiexec -n 2 ./mycode
> > 
> > >  
> > > The final question is related to valgrind. I have defined a setupKSP 
> > > function to do all the solver/pc setup. It seems like there is a problem 
> > 

Re: [petsc-users] Question about KSP, and makefile linking MPICH

2019-04-11 Thread Yuyun Yang via petsc-users
I think this problem arose because I did not reset the ksp for solving a 
different problem! It's not giving me an error anymore now that I added the 
reset, so it's all good :)

Thanks,
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>

From: Smith, Barry F. 
Sent: Thursday, April 11, 2019 9:21:11 PM
To: Yuyun Yang
Cc: petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] Question about KSP, and makefile linking MPICH


   Ahh, I just realized one other thing we can try. Run the program that 
crashes with -ksp_mat_view binary  this will produce a file called 
binaryoutput, send that file to petsc-ma...@mcs.anl.gov and we'll see if we can 
get MUMPS to mis-behave with it also.

   Barry



> On Apr 11, 2019, at 11:17 PM, Yuyun Yang  wrote:
>
> Thanks Barry for the detailed answers!
>
> Regarding the problem with valgrind, this is the only error produced, and if 
> I allow it to run further, the program would break (at a later function I get 
> NaN for some of the values being calculated, and I've put an assert to 
> prevent NaN results). I will take a look at it in the debugger. This is for 
> testing, but for bigger problems I won't end up using Cholesky, so it's not 
> really a big issue.
>
> Thanks again for the timely help!
> Yuyun
>
> Get Outlook for iOS
> From: Smith, Barry F. 
> Sent: Thursday, April 11, 2019 6:44:54 PM
> To: Yuyun Yang
> Cc: petsc-users@mcs.anl.gov
> Subject: Re: [petsc-users] Question about KSP, and makefile linking MPICH
>
>
>
> > On Apr 11, 2019, at 5:44 PM, Yuyun Yang via petsc-users 
> >  wrote:
> >
> > Hello team,
> >
> > I’d like to check if it’s ok to use the same ksp object and change its 
> > operator (the matrix A) later on in the code to solve a different problem?
>
>Do you mean call KSPSetOperators() with one matrix and then later call it 
> with a different matrix? This is ok if the two matrices are the same size and 
> have the same parallel layout. But if the matrices are different size, have 
> different parallel layout then you need to destroy the KSP and create a new 
> one or call KSPReset() in between for example
>
>   KSPSetFromOptions(ksp);
>   KSPSetOperators(ksp,A,A);
>   KSPSolve(ksp,b,x);
>   KSPReset(ksp);
>   KSPSetOperators(ksp,B,B);
>   KSPSolve(ksp,newb,newx);
>
> >
> > Also, I know I’ve asked this before about linking to MPICH when I call 
> > mpirun, instead of using my computer’s default MPI, but I want to check 
> > again. The same problem was solved on my cluster by using a different 
> > CLINKER (called mpiicc) in the Makefile and a different intel compiler, 
> > which will link my compiled code with MPICH. Is there a similar thing I can 
> > do on my own computer, instead of having to use a very long path to locate 
> > the MPICH I configured with PETSc, and then calling the executable? (I 
> > tried making CLINKER = mpiicc on my own computer but that didn’t work.)
>
> Are you asking how you can avoid something like
>
>   /home/me/petsc/arch-myarch/bin/mpiexec -n 2 ./mycode ?
>
>You can add /home/me/petsc/arch-myarch/bin to the beginning of your PATH, 
> for example with bash put the following into your ~/.bashrc file
>
>   export PATH=/home/me/petsc/arch-myarch/bin:$PATH
>   mpiexec -n 2 ./mycode
>
> >
> > The final question is related to valgrind. I have defined a setupKSP 
> > function to do all the solver/pc setup. It seems like there is a problem 
> > with memory allocation but I don’t really understand why. This only happens 
> > for MUMPSCHOLESKY though (running CG, AMG etc. was fine):
> >
> > ==830== Invalid read of size 8
> > ==830==at 0x6977C95: dmumps_ana_o_ (dana_aux.F:2054)
> > ==830==by 0x6913B5A: dmumps_ana_driver_ (dana_driver.F:390)
> > ==830==by 0x68C152C: dmumps_ (dmumps_driver.F:1213)
> > ==830==by 0x68BBE1C: dmumps_f77_ (dmumps_f77.F:267)
> > ==830==by 0x68BA4EB: dmumps_c (mumps_c.c:417)
> > ==830==by 0x5A070D6: MatCholeskyFactorSymbolic_MUMPS (mumps.c:1654)
> > ==830==by 0x54071F2: MatCholeskyFactorSymbolic (matrix.c:3179)
> > ==830==by 0x614AFE9: PCSetUp_Cholesky (cholesky.c:88)
> > ==830==by 0x62BA574: PCSetUp (precon.c:932)
> > ==830==by 0x640BB29: KSPSetUp (itfunc.c:391)
> > ==830==by 0x4A1192: PressureEq::setupKSP(_p_KSP*&, _p_PC*&, _p_Mat*&) 
> > (pressureEq.cpp:834)
> > ==830==by 0x4A1258: 
> > PressureEq::computeInitialSteadyStatePressure(Domain&) (pressureEq.cpp:862)
> >
> > ==830==  Address 0xb8149c0 is 0 bytes after a block of size 7,872 alloc'd
> >
> > ==830==

Re: [petsc-users] Question about KSP, and makefile linking MPICH

2019-04-11 Thread Yuyun Yang via petsc-users
Thanks Barry for the detailed answers!

Regarding the problem with valgrind, this is the only error produced, and if I 
allow it to run further, the program would break (at a later function I get NaN 
for some of the values being calculated, and I've put an assert to prevent NaN 
results). I will take a look at it in the debugger. This is for testing, but 
for bigger problems I won't end up using Cholesky, so it's not really a big 
issue.

Thanks again for the timely help!
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>

From: Smith, Barry F. 
Sent: Thursday, April 11, 2019 6:44:54 PM
To: Yuyun Yang
Cc: petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] Question about KSP, and makefile linking MPICH



> On Apr 11, 2019, at 5:44 PM, Yuyun Yang via petsc-users 
>  wrote:
>
> Hello team,
>
> I’d like to check if it’s ok to use the same ksp object and change its 
> operator (the matrix A) later on in the code to solve a different problem?

   Do you mean call KSPSetOperators() with one matrix and then later call it 
with a different matrix? This is ok if the two matrices are the same size and 
have the same parallel layout. But if the matrices are different size, have 
different parallel layout then you need to destroy the KSP and create a new one 
or call KSPReset() in between for example

  KSPSetFromOptions(ksp);
  KSPSetOperators(ksp,A,A);
  KSPSolve(ksp,b,x);
  KSPReset(ksp);
  KSPSetOperators(ksp,B,B);
  KSPSolve(ksp,newb,newx);

>
> Also, I know I’ve asked this before about linking to MPICH when I call 
> mpirun, instead of using my computer’s default MPI, but I want to check 
> again. The same problem was solved on my cluster by using a different CLINKER 
> (called mpiicc) in the Makefile and a different intel compiler, which will 
> link my compiled code with MPICH. Is there a similar thing I can do on my own 
> computer, instead of having to use a very long path to locate the MPICH I 
> configured with PETSc, and then calling the executable? (I tried making 
> CLINKER = mpiicc on my own computer but that didn’t work.)

Are you asking how you can avoid something like

  /home/me/petsc/arch-myarch/bin/mpiexec -n 2 ./mycode ?

   You can add /home/me/petsc/arch-myarch/bin to the beginning of your PATH, 
for example with bash put the following into your ~/.bashrc file

  export PATH=/home/me/petsc/arch-myarch/bin:$PATH
  mpiexec -n 2 ./mycode

>
> The final question is related to valgrind. I have defined a setupKSP function 
> to do all the solver/pc setup. It seems like there is a problem with memory 
> allocation but I don’t really understand why. This only happens for 
> MUMPSCHOLESKY though (running CG, AMG etc. was fine):
>
> ==830== Invalid read of size 8
> ==830==at 0x6977C95: dmumps_ana_o_ (dana_aux.F:2054)
> ==830==by 0x6913B5A: dmumps_ana_driver_ (dana_driver.F:390)
> ==830==by 0x68C152C: dmumps_ (dmumps_driver.F:1213)
> ==830==by 0x68BBE1C: dmumps_f77_ (dmumps_f77.F:267)
> ==830==by 0x68BA4EB: dmumps_c (mumps_c.c:417)
> ==830==by 0x5A070D6: MatCholeskyFactorSymbolic_MUMPS (mumps.c:1654)
> ==830==by 0x54071F2: MatCholeskyFactorSymbolic (matrix.c:3179)
> ==830==by 0x614AFE9: PCSetUp_Cholesky (cholesky.c:88)
> ==830==by 0x62BA574: PCSetUp (precon.c:932)
> ==830==by 0x640BB29: KSPSetUp (itfunc.c:391)
> ==830==by 0x4A1192: PressureEq::setupKSP(_p_KSP*&, _p_PC*&, _p_Mat*&) 
> (pressureEq.cpp:834)
> ==830==by 0x4A1258: 
> PressureEq::computeInitialSteadyStatePressure(Domain&) (pressureEq.cpp:862)
>
> ==830==  Address 0xb8149c0 is 0 bytes after a block of size 7,872 alloc'd
>
> ==830==at 0x4C2FFC6: memalign (in 
> /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==830==by 0x500E7E0: PetscMallocAlign (mal.c:41)
> ==830==by 0x59F8A16: MatConvertToTriples_seqaij_seqsbaij (mumps.c:402)
> ==830==by 0x5A06B53: MatCholeskyFactorSymbolic_MUMPS (mumps.c:1618)
> ==830==by 0x54071F2: MatCholeskyFactorSymbolic (matrix.c:3179)
> ==830==by 0x614AFE9: PCSetUp_Cholesky (cholesky.c:88)
> ==830==by 0x62BA574: PCSetUp (precon.c:932)
> ==830==by 0x640BB29: KSPSetUp (itfunc.c:391)
> ==830==by 0x4A1192: PressureEq::setupKSP(_p_KSP*&, _p_PC*&, _p_Mat*&) 
> (pressureEq.cpp:834)
> ==830==by 0x4A1258: 
> PressureEq::computeInitialSteadyStatePressure(Domain&) (pressureEq.cpp:862)
> ==830==by 0x49B809: PressureEq::PressureEq(Domain&) (pressureEq.cpp:62)
> ==830==by 0x4A88E9: 
> StrikeSlip_LinearElastic_qd::StrikeSlip_LinearElastic_qd(Domain&) 
> (strikeSlip_linearElastic_qd.cpp:57)

   This is curious. The line in the MUMPS code where valgrind detects a problem 
is

K = 1_8
THEMIN = ZERO
DO
 

[petsc-users] Question about KSP, and makefile linking MPICH

2019-04-11 Thread Yuyun Yang via petsc-users
Hello team,

I'd like to check if it's ok to use the same ksp object and change its operator 
(the matrix A) later on in the code to solve a different problem?

Also, I know I've asked this before about linking to MPICH when I call mpirun, 
instead of using my computer's default MPI, but I want to check again. The same 
problem was solved on my cluster by using a different CLINKER (called mpiicc) 
in the Makefile and a different intel compiler, which will link my compiled 
code with MPICH. Is there a similar thing I can do on my own computer, instead 
of having to use a very long path to locate the MPICH I configured with PETSc, 
and then calling the executable? (I tried making CLINKER = mpiicc on my own 
computer but that didn't work.)

The final question is related to valgrind. I have defined a setupKSP function 
to do all the solver/pc setup. It seems like there is a problem with memory 
allocation but I don't really understand why. This only happens for 
MUMPSCHOLESKY though (running CG, AMG etc. was fine):

==830== Invalid read of size 8
==830==at 0x6977C95: dmumps_ana_o_ (dana_aux.F:2054)
==830==by 0x6913B5A: dmumps_ana_driver_ (dana_driver.F:390)
==830==by 0x68C152C: dmumps_ (dmumps_driver.F:1213)
==830==by 0x68BBE1C: dmumps_f77_ (dmumps_f77.F:267)
==830==by 0x68BA4EB: dmumps_c (mumps_c.c:417)
==830==by 0x5A070D6: MatCholeskyFactorSymbolic_MUMPS (mumps.c:1654)
==830==by 0x54071F2: MatCholeskyFactorSymbolic (matrix.c:3179)
==830==by 0x614AFE9: PCSetUp_Cholesky (cholesky.c:88)
==830==by 0x62BA574: PCSetUp (precon.c:932)
==830==by 0x640BB29: KSPSetUp (itfunc.c:391)
==830==by 0x4A1192: PressureEq::setupKSP(_p_KSP*&, _p_PC*&, _p_Mat*&) 
(pressureEq.cpp:834)
==830==by 0x4A1258: PressureEq::computeInitialSteadyStatePressure(Domain&) 
(pressureEq.cpp:862)

==830==  Address 0xb8149c0 is 0 bytes after a block of size 7,872 alloc'd

==830==at 0x4C2FFC6: memalign (in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==830==by 0x500E7E0: PetscMallocAlign (mal.c:41)
==830==by 0x59F8A16: MatConvertToTriples_seqaij_seqsbaij (mumps.c:402)
==830==by 0x5A06B53: MatCholeskyFactorSymbolic_MUMPS (mumps.c:1618)
==830==by 0x54071F2: MatCholeskyFactorSymbolic (matrix.c:3179)
==830==by 0x614AFE9: PCSetUp_Cholesky (cholesky.c:88)
==830==by 0x62BA574: PCSetUp (precon.c:932)
==830==by 0x640BB29: KSPSetUp (itfunc.c:391)
==830==by 0x4A1192: PressureEq::setupKSP(_p_KSP*&, _p_PC*&, _p_Mat*&) 
(pressureEq.cpp:834)
==830==by 0x4A1258: PressureEq::computeInitialSteadyStatePressure(Domain&) 
(pressureEq.cpp:862)
==830==by 0x49B809: PressureEq::PressureEq(Domain&) (pressureEq.cpp:62)
==830==by 0x4A88E9: 
StrikeSlip_LinearElastic_qd::StrikeSlip_LinearElastic_qd(Domain&) 
(strikeSlip_linearElastic_qd.cpp:57)

Thank you!
Yuyun


Re: [petsc-users] ASCIIRead error for multiple processors

2019-04-05 Thread Yuyun Yang via petsc-users
Ok great, thanks for the explanation!

Best,
Yuyun

From: Matthew Knepley 
Sent: Friday, April 5, 2019 7:31 AM
To: Yuyun Yang 
Cc: Smith, Barry F. ; petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] ASCIIRead error for multiple processors

On Fri, Apr 5, 2019 at 10:27 AM Yuyun Yang 
mailto:yyan...@stanford.edu>> wrote:
Hmm ok. Then should I use this function or not when I'm reading the input? It's 
probably still going to give me the same error and unable to proceed?

I'd like to know if I should use something else to work around this problem.

No, what you do is

  if (!rank) {
PetscViewerASCIIRead();
MPI_Bcast();
  } else {
MPI_Bcast();
  }

  Thanks,

 Matt

Thanks,
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>

From: Matthew Knepley mailto:knep...@gmail.com>>
Sent: Friday, April 5, 2019 5:16:12 AM
To: Yuyun Yang
Cc: Smith, Barry F.; petsc-users@mcs.anl.gov<mailto:petsc-users@mcs.anl.gov>
Subject: Re: [petsc-users] ASCIIRead error for multiple processors

On Thu, Apr 4, 2019 at 10:56 PM Yuyun Yang 
mailto:yyan...@stanford.edu>> wrote:
So do I call MPI_Bcast right after I call PetscViewerASCIIRead? Is that going 
to prevent the other processors from trying to read the same file but were 
unable to?

No, all this does is replicate data from process 0 on the other processes.

   Matt

Thanks,
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>

From: Matthew Knepley mailto:knep...@gmail.com>>
Sent: Thursday, April 4, 2019 7:30:20 PM
To: Yuyun Yang
Cc: Smith, Barry F.; petsc-users@mcs.anl.gov<mailto:petsc-users@mcs.anl.gov>
Subject: Re: [petsc-users] ASCIIRead error for multiple processors

On Thu, Apr 4, 2019 at 9:19 PM Yuyun Yang via petsc-users 
mailto:petsc-users@mcs.anl.gov>> wrote:
We are probably not going to use hundreds of processors, but i think it would 
be good to just have processor 0 read the input and broadcast that to all the 
other processors. Would that be a possible fix? And what would you suggest to 
work around this problem for now?

Explicitly call MPI_Bcast().

   Matt

Thanks!
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>

From: Smith, Barry F. mailto:bsm...@mcs.anl.gov>>
Sent: Thursday, April 4, 2019 3:07:37 PM
To: Yuyun Yang
Cc: petsc-users@mcs.anl.gov<mailto:petsc-users@mcs.anl.gov>
Subject: Re: [petsc-users] ASCIIRead error for multiple processors


   Currently PetscViewerFileSetName_ASCII() only opens the file on process 0 
(for read or write) thus when you call PetscViewerASCIIRead() from any process 
but the first it will be reading from an fd that has not been set and you could 
get unpredictable results.

   The implementation and documentation for PetscViewerASCIIRead() is buggy.

   There are two possible fixes we could make

1) have PetscViewerFileSetName_ASCII()  open the file for reading on all 
processes or
2) have PetscViewerASCIIRead() generate an error if the process is not rank == 0

   Barry

Note that using PetscViewerASCIIRead() from a handful of processes is probably 
fine but having hundreds or thousands of processes open the same ASCII file and 
reading from it will likely not be scalable.




> On Apr 4, 2019, at 3:15 PM, Yuyun Yang via petsc-users 
> mailto:petsc-users@mcs.anl.gov>> wrote:
>
> Hello team,
>
> I’m trying to use PetscViewerASCIIRead() to read in a single interger/scalar 
> value from an input file. It works for one processor. However, when running 
> on multiple processors, I’m getting the below error:
>
> [1]PETSC ERROR: Invalid argument
> [1]PETSC ERROR: Insufficient data, read only 0 < 1 items
> [1]PETSC ERROR: #1 PetscViewerASCIIRead() line 1054 in 
> /usr/local/CLAB-2/petsc-3.6/src/sys/classes/viewer/impls/ascii/filev.c
>
> Is there something wrong with how I’m implementing this, or ASCIIRead does 
> not work with multiple processors?
>
> Thanks,
> Yuyun


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


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


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


Re: [petsc-users] ASCIIRead error for multiple processors

2019-04-05 Thread Yuyun Yang via petsc-users
Hmm ok. Then should I use this function or not when I'm reading the input? It's 
probably still going to give me the same error and unable to proceed?

I'd like to know if I should use something else to work around this problem.

Thanks,
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>

From: Matthew Knepley 
Sent: Friday, April 5, 2019 5:16:12 AM
To: Yuyun Yang
Cc: Smith, Barry F.; petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] ASCIIRead error for multiple processors

On Thu, Apr 4, 2019 at 10:56 PM Yuyun Yang 
mailto:yyan...@stanford.edu>> wrote:
So do I call MPI_Bcast right after I call PetscViewerASCIIRead? Is that going 
to prevent the other processors from trying to read the same file but were 
unable to?

No, all this does is replicate data from process 0 on the other processes.

   Matt

Thanks,
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>

From: Matthew Knepley mailto:knep...@gmail.com>>
Sent: Thursday, April 4, 2019 7:30:20 PM
To: Yuyun Yang
Cc: Smith, Barry F.; petsc-users@mcs.anl.gov<mailto:petsc-users@mcs.anl.gov>
Subject: Re: [petsc-users] ASCIIRead error for multiple processors

On Thu, Apr 4, 2019 at 9:19 PM Yuyun Yang via petsc-users 
mailto:petsc-users@mcs.anl.gov>> wrote:
We are probably not going to use hundreds of processors, but i think it would 
be good to just have processor 0 read the input and broadcast that to all the 
other processors. Would that be a possible fix? And what would you suggest to 
work around this problem for now?

Explicitly call MPI_Bcast().

   Matt

Thanks!
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>

From: Smith, Barry F. mailto:bsm...@mcs.anl.gov>>
Sent: Thursday, April 4, 2019 3:07:37 PM
To: Yuyun Yang
Cc: petsc-users@mcs.anl.gov<mailto:petsc-users@mcs.anl.gov>
Subject: Re: [petsc-users] ASCIIRead error for multiple processors


   Currently PetscViewerFileSetName_ASCII() only opens the file on process 0 
(for read or write) thus when you call PetscViewerASCIIRead() from any process 
but the first it will be reading from an fd that has not been set and you could 
get unpredictable results.

   The implementation and documentation for PetscViewerASCIIRead() is buggy.

   There are two possible fixes we could make

1) have PetscViewerFileSetName_ASCII()  open the file for reading on all 
processes or
2) have PetscViewerASCIIRead() generate an error if the process is not rank == 0

   Barry

Note that using PetscViewerASCIIRead() from a handful of processes is probably 
fine but having hundreds or thousands of processes open the same ASCII file and 
reading from it will likely not be scalable.




> On Apr 4, 2019, at 3:15 PM, Yuyun Yang via petsc-users 
> mailto:petsc-users@mcs.anl.gov>> wrote:
>
> Hello team,
>
> I’m trying to use PetscViewerASCIIRead() to read in a single interger/scalar 
> value from an input file. It works for one processor. However, when running 
> on multiple processors, I’m getting the below error:
>
> [1]PETSC ERROR: Invalid argument
> [1]PETSC ERROR: Insufficient data, read only 0 < 1 items
> [1]PETSC ERROR: #1 PetscViewerASCIIRead() line 1054 in 
> /usr/local/CLAB-2/petsc-3.6/src/sys/classes/viewer/impls/ascii/filev.c
>
> Is there something wrong with how I’m implementing this, or ASCIIRead does 
> not work with multiple processors?
>
> Thanks,
> Yuyun



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


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


Re: [petsc-users] ASCIIRead error for multiple processors

2019-04-04 Thread Yuyun Yang via petsc-users
So do I call MPI_Bcast right after I call PetscViewerASCIIRead? Is that going 
to prevent the other processors from trying to read the same file but were 
unable to?

Thanks,
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>

From: Matthew Knepley 
Sent: Thursday, April 4, 2019 7:30:20 PM
To: Yuyun Yang
Cc: Smith, Barry F.; petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] ASCIIRead error for multiple processors

On Thu, Apr 4, 2019 at 9:19 PM Yuyun Yang via petsc-users 
mailto:petsc-users@mcs.anl.gov>> wrote:
We are probably not going to use hundreds of processors, but i think it would 
be good to just have processor 0 read the input and broadcast that to all the 
other processors. Would that be a possible fix? And what would you suggest to 
work around this problem for now?

Explicitly call MPI_Bcast().

   Matt

Thanks!
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>

From: Smith, Barry F. mailto:bsm...@mcs.anl.gov>>
Sent: Thursday, April 4, 2019 3:07:37 PM
To: Yuyun Yang
Cc: petsc-users@mcs.anl.gov<mailto:petsc-users@mcs.anl.gov>
Subject: Re: [petsc-users] ASCIIRead error for multiple processors


   Currently PetscViewerFileSetName_ASCII() only opens the file on process 0 
(for read or write) thus when you call PetscViewerASCIIRead() from any process 
but the first it will be reading from an fd that has not been set and you could 
get unpredictable results.

   The implementation and documentation for PetscViewerASCIIRead() is buggy.

   There are two possible fixes we could make

1) have PetscViewerFileSetName_ASCII()  open the file for reading on all 
processes or
2) have PetscViewerASCIIRead() generate an error if the process is not rank == 0

   Barry

Note that using PetscViewerASCIIRead() from a handful of processes is probably 
fine but having hundreds or thousands of processes open the same ASCII file and 
reading from it will likely not be scalable.




> On Apr 4, 2019, at 3:15 PM, Yuyun Yang via petsc-users 
> mailto:petsc-users@mcs.anl.gov>> wrote:
>
> Hello team,
>
> I’m trying to use PetscViewerASCIIRead() to read in a single interger/scalar 
> value from an input file. It works for one processor. However, when running 
> on multiple processors, I’m getting the below error:
>
> [1]PETSC ERROR: Invalid argument
> [1]PETSC ERROR: Insufficient data, read only 0 < 1 items
> [1]PETSC ERROR: #1 PetscViewerASCIIRead() line 1054 in 
> /usr/local/CLAB-2/petsc-3.6/src/sys/classes/viewer/impls/ascii/filev.c
>
> Is there something wrong with how I’m implementing this, or ASCIIRead does 
> not work with multiple processors?
>
> Thanks,
> Yuyun



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


Re: [petsc-users] ASCIIRead error for multiple processors

2019-04-04 Thread Yuyun Yang via petsc-users
We are probably not going to use hundreds of processors, but i think it would 
be good to just have processor 0 read the input and broadcast that to all the 
other processors. Would that be a possible fix? And what would you suggest to 
work around this problem for now?

Thanks!
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>

From: Smith, Barry F. 
Sent: Thursday, April 4, 2019 3:07:37 PM
To: Yuyun Yang
Cc: petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] ASCIIRead error for multiple processors


   Currently PetscViewerFileSetName_ASCII() only opens the file on process 0 
(for read or write) thus when you call PetscViewerASCIIRead() from any process 
but the first it will be reading from an fd that has not been set and you could 
get unpredictable results.

   The implementation and documentation for PetscViewerASCIIRead() is buggy.

   There are two possible fixes we could make

1) have PetscViewerFileSetName_ASCII()  open the file for reading on all 
processes or
2) have PetscViewerASCIIRead() generate an error if the process is not rank == 0

   Barry

Note that using PetscViewerASCIIRead() from a handful of processes is probably 
fine but having hundreds or thousands of processes open the same ASCII file and 
reading from it will likely not be scalable.




> On Apr 4, 2019, at 3:15 PM, Yuyun Yang via petsc-users 
>  wrote:
>
> Hello team,
>
> I’m trying to use PetscViewerASCIIRead() to read in a single interger/scalar 
> value from an input file. It works for one processor. However, when running 
> on multiple processors, I’m getting the below error:
>
> [1]PETSC ERROR: Invalid argument
> [1]PETSC ERROR: Insufficient data, read only 0 < 1 items
> [1]PETSC ERROR: #1 PetscViewerASCIIRead() line 1054 in 
> /usr/local/CLAB-2/petsc-3.6/src/sys/classes/viewer/impls/ascii/filev.c
>
> Is there something wrong with how I’m implementing this, or ASCIIRead does 
> not work with multiple processors?
>
> Thanks,
> Yuyun



[petsc-users] ASCIIRead error for multiple processors

2019-04-04 Thread Yuyun Yang via petsc-users
Hello team,

I'm trying to use PetscViewerASCIIRead() to read in a single interger/scalar 
value from an input file. It works for one processor. However, when running on 
multiple processors, I'm getting the below error:

[1]PETSC ERROR: Invalid argument
[1]PETSC ERROR: Insufficient data, read only 0 < 1 items
[1]PETSC ERROR: #1 PetscViewerASCIIRead() line 1054 in 
/usr/local/CLAB-2/petsc-3.6/src/sys/classes/viewer/impls/ascii/filev.c

Is there something wrong with how I'm implementing this, or ASCIIRead does not 
work with multiple processors?

Thanks,
Yuyun


Re: [petsc-users] Saving Vecs/Mats in HDF5 and visualizing in Matlab

2019-03-19 Thread Yuyun Yang via petsc-users
Sounds good, thanks for the advice!

-Original Message-
From: Jed Brown  
Sent: Tuesday, March 19, 2019 1:23 PM
To: Yuyun Yang ; zakaryah ; 
petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] Saving Vecs/Mats in HDF5 and visualizing in Matlab

Yuyun Yang via petsc-users  writes:

> It's simply for visualization purposes. I wasn't sure if HDF5 would perform 
> better than binary, and what specific functions are needed to load the PETSc 
> vectors/matrices, so wanted to ask for some advice here. Since Matt mentioned 
> it's not likely to be much faster than binary, I guess there is no need to 
> make the change?

There is no speed benefit.  The advantage of HDF5 is that it supports better 
metadata, including the data types and sizes.  The PETSc data format is quick, 
dirty, and fast.



Re: [petsc-users] Saving Vecs/Mats in HDF5 and visualizing in Matlab

2019-03-19 Thread Yuyun Yang via petsc-users
It's simply for visualization purposes. I wasn't sure if HDF5 would perform 
better than binary, and what specific functions are needed to load the PETSc 
vectors/matrices, so wanted to ask for some advice here. Since Matt mentioned 
it's not likely to be much faster than binary, I guess there is no need to make 
the change?

So running h5read will load the vector from the hdf5 file directly to a Matlab 
vector? And similarly so for matrices?

Thanks,
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>

From: petsc-users  on behalf of zakaryah via 
petsc-users 
Sent: Tuesday, March 19, 2019 11:54:02 AM
To: petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] Saving Vecs/Mats in HDF5 and visualizing in Matlab

Hi Yuyun,

I'm not sure exactly what you want to do but I use Matlab to work with and 
visualize HDF5 files from PETSc all the time.  Matlab has h5info and h5read 
routines, then I visualize with my own routines.  Is there something specific 
you need from Matlab?

On Tue, Mar 19, 2019 at 1:18 PM Yuyun Yang via petsc-users 
mailto:petsc-users@mcs.anl.gov>> wrote:
Got it, thanks!

From: Matthew Knepley mailto:knep...@gmail.com>>
Sent: Tuesday, March 19, 2019 10:10 AM
To: Yuyun Yang mailto:yyan...@stanford.edu>>
Cc: petsc-users@mcs.anl.gov<mailto:petsc-users@mcs.anl.gov>
Subject: Re: [petsc-users] Saving Vecs/Mats in HDF5 and visualizing in Matlab

On Tue, Mar 19, 2019 at 11:58 AM Yuyun Yang via petsc-users 
mailto:petsc-users@mcs.anl.gov>> wrote:
Hello team,

Currently we’re using the PETSc binary file format to save Vecs and Mats and 
visualize them in Matlab. It looks like HDF5 works more efficiently with large 
data sets (faster I/O), and we’re wondering if PETSc Vecs/Mats saved in HDF5 
viewer can be visualized in Matlab as well?

We do not have code for that. I am using Paraview to look at HDF5 since 
everything I do is on 2D and 3D meshes. Note that HDF5 is not likely to have 
faster I/O than the PETSc binary.

  Thanks,

Matt


Thanks for your help,
Yuyun


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


Re: [petsc-users] Saving Vecs/Mats in HDF5 and visualizing in Matlab

2019-03-19 Thread Yuyun Yang via petsc-users
Got it, thanks!

From: Matthew Knepley 
Sent: Tuesday, March 19, 2019 10:10 AM
To: Yuyun Yang 
Cc: petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] Saving Vecs/Mats in HDF5 and visualizing in Matlab

On Tue, Mar 19, 2019 at 11:58 AM Yuyun Yang via petsc-users 
mailto:petsc-users@mcs.anl.gov>> wrote:
Hello team,

Currently we’re using the PETSc binary file format to save Vecs and Mats and 
visualize them in Matlab. It looks like HDF5 works more efficiently with large 
data sets (faster I/O), and we’re wondering if PETSc Vecs/Mats saved in HDF5 
viewer can be visualized in Matlab as well?

We do not have code for that. I am using Paraview to look at HDF5 since 
everything I do is on 2D and 3D meshes. Note that HDF5 is not likely to have 
faster I/O than the PETSc binary.

  Thanks,

Matt


Thanks for your help,
Yuyun


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


[petsc-users] Saving Vecs/Mats in HDF5 and visualizing in Matlab

2019-03-19 Thread Yuyun Yang via petsc-users
Hello team,

Currently we're using the PETSc binary file format to save Vecs and Mats and 
visualize them in Matlab. It looks like HDF5 works more efficiently with large 
data sets (faster I/O), and we're wondering if PETSc Vecs/Mats saved in HDF5 
viewer can be visualized in Matlab as well?

Thanks for your help,
Yuyun


Re: [petsc-users] Using PETSc with GPU

2019-03-15 Thread Yuyun Yang via petsc-users
Good point, thank you so much for the advice! I'll take that into consideration.

Best regards,
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>

From: Jed Brown 
Sent: Friday, March 15, 2019 7:06:29 PM
To: Yuyun Yang; Smith, Barry F.
Cc: petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] Using PETSc with GPU

Yuyun Yang via petsc-users  writes:

> Currently we are forming the sparse matrices explicitly, but I think the goal 
> is to move towards matrix-free methods and use a stencil, which I suppose is 
> good to use GPUs for and more efficient. On the other hand, I've also read 
> about matrix-free operations in the manual just on the CPUs. Would there be 
> any benefit then to switching to GPU (looks like matrix-free in PETSc is 
> rather straightforward to use, whereas writing the kernel function for GPU 
> stencil would require quite a lot of work)?

It all depends what kind of computation happens in there and how well
you can implement it for the GPU.  It's important to have a clear idea
of what you expect to achieve.  For example, if you write an excellent
GPU implementation of your SNES residual/matrix-free Jacobian, it might
be 2-3x faster than a good CPU implementation on hardware of similar
cost ($ or Watt).  But you still need preconditioning, which is usually
at least half the work, and perhaps a preconditioner runs the same speed
on GPU and CPU (CPU version often converges a bit faster;
preconditioning operations are often less amenable to GPUs).  So after
all that effort, and now with code that is likely harder to maintain,
you go from 4 seconds per solve to 3 seconds per solve on hardware of
the same cost.  Is that worth it?

Maybe, but you probably want that to be in the critical path for your
research and/or customers.


Re: [petsc-users] Using PETSc with GPU

2019-03-15 Thread Yuyun Yang via petsc-users
Currently we are forming the sparse matrices explicitly, but I think the goal 
is to move towards matrix-free methods and use a stencil, which I suppose is 
good to use GPUs for and more efficient. On the other hand, I've also read 
about matrix-free operations in the manual just on the CPUs. Would there be any 
benefit then to switching to GPU (looks like matrix-free in PETSc is rather 
straightforward to use, whereas writing the kernel function for GPU stencil 
would require quite a lot of work)?

Thanks!
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>

From: Smith, Barry F. 
Sent: Friday, March 15, 2019 5:43:23 PM
To: Yuyun Yang
Cc: Matthew Knepley; petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] Using PETSc with GPU



> On Mar 15, 2019, at 7:33 PM, Yuyun Yang via petsc-users 
>  wrote:
>
> Thanks Matt, I've seen that page, but there isn't that much documentation, 
> and there is only one CUDA example, so I wanted to check if there may be more 
> references or examples somewhere else. We have very large linear systems that 
> need to be solved every time step, and which involves matrix-matrix 
> multiplications,

where do these matrix-matrix multiplications appear? Are you providing a 
"matrix-free" based operator for your linear system where you apply 
matrix-vector operations via a subroutine call? Or are you explicitly forming 
sparse matrices and using them to define the operator?



> so we thought GPU could have some benefits, but we are unsure how difficult 
> it is to migrate parts of the code to GPU with PETSc. From that webpage it 
> seems like we only need to specify the Vec / Mat option on the command line 
> and maybe change a few functions to have CUDA? The CUDA example however also 
> involves using thrust and programming a kernel function, so I want to make 
> sure I know how this works before trying to implement.

   How much, if any, CUDA/GPU code you have to write depends on what you want 
to have done on the GPU. If you provide a sparse matrix and only want  the 
system solve to take place on the GPU then you don't need to write any CUDA/GPU 
code, you just use the "CUDA" vector and matrix class. If you are doing 
"matrix-free" solves and you provide the routine that performs the 
matrix-vector product then you need to write/optimize that routine for CUDA/GPU.

   Barry

>
> Thanks a lot,
> Yuyun
>
> Get Outlook for iOS
> From: Matthew Knepley 
> Sent: Friday, March 15, 2019 2:54:02 PM
> To: Yuyun Yang
> Cc: petsc-users@mcs.anl.gov
> Subject: Re: [petsc-users] Using PETSc with GPU
>
> On Fri, Mar 15, 2019 at 5:30 PM Yuyun Yang via petsc-users 
>  wrote:
> Hello team,
>
>
>
> Our group is thinking of using GPUs for the linear solves in our code, which 
> is written in PETSc. I was reading the 2013 book chapter on implementation of 
> PETSc using GPUs but wonder if there is any more updated reference that I 
> check out? I also saw one example cuda code online (using thrust), but would 
> like to check with you if there is a more complete documentation of how the 
> GPU implementation is done?
>
>
> Have you seen this page? https://www.mcs.anl.gov/petsc/features/gpus.html
>
> Also, before using GPUs, I would take some time to understand what you think 
> the possible benefit can be.
> For example, there is almost no benefit is you use BLAS1, and you would have 
> a huge maintenance burden
> with a different toolchain. This is also largely true for SpMV, since the 
> bandwidth difference between CPUs
> and GPUs is now not much. So you really should have some kind of flop 
> intensive (BLAS3-like) work in there
> somewhere or its hard to see your motivation.
>
>   Thanks,
>
>  Matt
>
>
> Thanks very much!
>
>
>
> Best regards,
>
> Yuyun
>
>
>
> --
> 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] Using PETSc with GPU

2019-03-15 Thread Yuyun Yang via petsc-users
Thanks Matt, I've seen that page, but there isn't that much documentation, and 
there is only one CUDA example, so I wanted to check if there may be more 
references or examples somewhere else. We have very large linear systems that 
need to be solved every time step, and which involves matrix-matrix 
multiplications, so we thought GPU could have some benefits, but we are unsure 
how difficult it is to migrate parts of the code to GPU with PETSc. From that 
webpage it seems like we only need to specify the Vec / Mat option on the 
command line and maybe change a few functions to have CUDA? The CUDA example 
however also involves using thrust and programming a kernel function, so I want 
to make sure I know how this works before trying to implement.

Thanks a lot,
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>

From: Matthew Knepley 
Sent: Friday, March 15, 2019 2:54:02 PM
To: Yuyun Yang
Cc: petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] Using PETSc with GPU

On Fri, Mar 15, 2019 at 5:30 PM Yuyun Yang via petsc-users 
mailto:petsc-users@mcs.anl.gov>> wrote:
Hello team,

Our group is thinking of using GPUs for the linear solves in our code, which is 
written in PETSc. I was reading the 2013 book chapter on implementation of 
PETSc using GPUs but wonder if there is any more updated reference that I check 
out? I also saw one example cuda code online (using thrust), but would like to 
check with you if there is a more complete documentation of how the GPU 
implementation is done?

Have you seen this page? https://www.mcs.anl.gov/petsc/features/gpus.html

Also, before using GPUs, I would take some time to understand what you think 
the possible benefit can be.
For example, there is almost no benefit is you use BLAS1, and you would have a 
huge maintenance burden
with a different toolchain. This is also largely true for SpMV, since the 
bandwidth difference between CPUs
and GPUs is now not much. So you really should have some kind of flop intensive 
(BLAS3-like) work in there
somewhere or its hard to see your motivation.

  Thanks,

 Matt


Thanks very much!

Best regards,
Yuyun


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


[petsc-users] Using PETSc with GPU

2019-03-15 Thread Yuyun Yang via petsc-users
Hello team,

Our group is thinking of using GPUs for the linear solves in our code, which is 
written in PETSc. I was reading the 2013 book chapter on implementation of 
PETSc using GPUs but wonder if there is any more updated reference that I check 
out? I also saw one example cuda code online (using thrust), but would like to 
check with you if there is a more complete documentation of how the GPU 
implementation is done?

Thanks very much!

Best regards,
Yuyun


[petsc-users] Conceptual question about DMDA

2019-03-11 Thread Yuyun Yang via petsc-users
Hello team,

May I know for what types of computations is DMDA better to use compared to 
regular Vec/Mat? It is more complicated in terms of usage, thus so far I've 
only used Vec/Mat. Would DMDA improve the performance of solving large linear 
systems (say for variable grid spacing as a result of coordinate transforms, 
with finite difference method)? What considerations should go into implementing 
it?

Thank you very much!
Yuyun


Re: [petsc-users] Append vector to existing file

2019-03-08 Thread Yuyun Yang via petsc-users
I see, thank you!
Yuyun

From: Matthew Knepley 
Sent: Friday, March 8, 2019 4:51 PM
To: Yuyun Yang 
Cc: petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] Append vector to existing file

On Fri, Mar 8, 2019 at 5:53 PM Yuyun Yang via petsc-users 
mailto:petsc-users@mcs.anl.gov>> wrote:
Hello team,

This is a very simple question, but I just want to be sure I understand how the 
viewer works. I have a file with some vectors already written into it. Now I’m 
calling PetscViewerASCIIOpen, setting the format and then the file mode into 
append:
  PetscViewer viewer;
  ierr = PetscViewerASCIIOpen(PETSC_COMM_WORLD, filename.c_str(), &viewer);

ASCIIOpen() is a simplified interface. For append, I think you need

  PetscViewerCreate()
  PetscViewerSetType()
  PetscViewerFileSetMode()
  PetscViewerFileSetName()
  PetscViewerPushFormat()

Matt

  ierr = PetscViewerPushFormat(viewer, PETSC_VIEWER_ASCII_MATLAB); 
CHKERRQ(ierr);
ierr = PetscViewerFileSetMode(viewer, FILE_MODE_APPEND); CHKERRQ(ierr);

After which I call VecView to append some new vectors to the existing file. But 
this operation is clearing out my existing file and writing it with new 
information. Does the append mode happen to not work with this type of viewer, 
or am I missing something here?

Thanks a lot,
Yuyun


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


[petsc-users] Append vector to existing file

2019-03-08 Thread Yuyun Yang via petsc-users
Hello team,

This is a very simple question, but I just want to be sure I understand how the 
viewer works. I have a file with some vectors already written into it. Now I'm 
calling PetscViewerASCIIOpen, setting the format and then the file mode into 
append:
  PetscViewer viewer;
  ierr = PetscViewerASCIIOpen(PETSC_COMM_WORLD, filename.c_str(), &viewer);
  ierr = PetscViewerPushFormat(viewer, PETSC_VIEWER_ASCII_MATLAB); 
CHKERRQ(ierr);
ierr = PetscViewerFileSetMode(viewer, FILE_MODE_APPEND); CHKERRQ(ierr);

After which I call VecView to append some new vectors to the existing file. But 
this operation is clearing out my existing file and writing it with new 
information. Does the append mode happen to not work with this type of viewer, 
or am I missing something here?

Thanks a lot,
Yuyun


Re: [petsc-users] AddressSanitizer: attempting free on address which was not malloc()-ed

2019-03-03 Thread Yuyun Yang via petsc-users
Oh interesting, so I need to add those extra brackets around my class object 
and function calls. I thought the destructor is automatically at Finalize.

Thanks!
Yuyun

-Original Message-
From: Jed Brown  
Sent: Sunday, March 3, 2019 2:19 PM
To: Yuyun Yang ; Matthew Knepley 
Cc: petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed

If you run this with MPICH, it prints

  Attempting to use an MPI routine after finalizing MPICH

You need to ensure that the C++ class destructor is called before 
PetscFinalize.  For example, like this:

diff --git i/test_domain.cpp w/test_domain.cpp index 0cfe22f..23545f2 100644
--- i/test_domain.cpp
+++ w/test_domain.cpp
@@ -8,11 +8,12 @@ int main(int argc, char **argv) {
   PetscErrorCode ierr = 0;
   PetscInitialize(&argc, &argv, NULL, NULL);
 
-  Domain d;
+  {
+Domain d;
 
-  ierr = d.setFields(); CHKERRQ(ierr);
-  ierr = d.setScatters(); CHKERRQ(ierr);
-  
+ierr = d.setFields(); CHKERRQ(ierr);
+ierr = d.setScatters(); CHKERRQ(ierr);  }
   PetscFinalize();
   return ierr;
 }


Yuyun Yang via petsc-users  writes:

> Yes, please see the attached files for a minimal example. Thanks a lot!
>
> Best regards,
> Yuyun
>
> From: Matthew Knepley 
> Sent: Sunday, March 3, 2019 12:46 PM
> To: Yuyun Yang 
> Cc: Zhang, Junchao ; petsc-users@mcs.anl.gov
> Subject: Re: [petsc-users] AddressSanitizer: attempting free on 
> address which was not malloc()-ed
>
> On Sun, Mar 3, 2019 at 3:05 PM Yuyun Yang 
> mailto:yyan...@stanford.edu>> wrote:
> Actually, I tried just creating a domain object (since the address sanitizer 
> was complaining about that code to start with). Simply creating that object 
> gave me a core dump, so I suppose the issue must be there. I got the 
> following message when running the code with -objects_dump flag on the 
> command line, but couldn’t find a problem with the code (I’ve attached it 
> here with only the relevant functions).
>
> I think what we are going to need from you is a minimal example that 
> has the error. I am guessing you have a logic bug in the C++, which we cannot 
> debug by looking.
>
>   Thanks,
>
>  Matt
>
> Thanks a lot for your help!
>
> The following objects were never freed
> -
> [0] Vec seq y
>   [0]  VecCreate() in 
> /home/yyy910805/petsc/src/vec/vec/interface/veccreate.c
> [0] Vec seq Vec_0x8400_0
>   [0]  VecCreate() in 
> /home/yyy910805/petsc/src/vec/vec/interface/veccreate.c
> [0] Vec seq Vec_0x8400_1
>   [0]  VecCreate() in 
> /home/yyy910805/petsc/src/vec/vec/interface/veccreate.c
> [0] VecScatter seq VecScatter_0x8400_2
>   [0]  VecScatterCreate() in 
> /home/yyy910805/petsc/src/vec/vscat/interface/vscreate.c
> [0] VecScatter seq VecScatter_0x8400_3
>   [0]  VecScatterCreate() in 
> /home/yyy910805/petsc/src/vec/vscat/interface/vscreate.c
> [0] VecScatter seq VecScatter_0x8400_4
>   [0]  VecScatterCreate() in 
> /home/yyy910805/petsc/src/vec/vscat/interface/vscreate.c
> [0] VecScatter seq VecScatter_0x8400_5
>   [0]  VecScatterCreate() in 
> /home/yyy910805/petsc/src/vec/vscat/interface/vscreate.c
> Attempting to use an MPI routine after finalizing MPICH
>
> --
> --
> -
> From: Matthew Knepley mailto:knep...@gmail.com>>
> Sent: Sunday, March 3, 2019 11:28 AM
> To: Yuyun Yang mailto:yyan...@stanford.edu>>
> Cc: Zhang, Junchao mailto:jczh...@mcs.anl.gov>>; 
> petsc-users@mcs.anl.gov<mailto:petsc-users@mcs.anl.gov>
> Subject: Re: [petsc-users] AddressSanitizer: attempting free on 
> address which was not malloc()-ed
>
> On Sun, Mar 3, 2019 at 1:03 PM Yuyun Yang via petsc-users 
> mailto:petsc-users@mcs.anl.gov>> wrote:
> I tried compiling without the sanitizer and running on valgrind. Got a bunch 
> of errors “Uninitialised value was created by a stack allocation at 0x41B280: 
> ComputeVel_qd::computeVel(double*, double, int&, int)”.
>
> There is no memory management code here, so other parts of the code must be 
> relevant.
>
>   Thanks,
>
> Matt
>
>
> HEAP SUMMARY:
> ==74== in use at exit: 96,637 bytes in 91 blocks
> ==74==   total heap usage: 47,774 allocs, 47,522 frees, 308,253,653 bytes 
> allocated
> LEAK SUMMARY:
> ==74==definitely lost: 0 bytes in 0 blocks
> ==74==indirectly lost: 0 bytes in 0 blocks
> ==74==  possibly lost: 0 bytes in 0 blocks
> ==74==still reachable: 96,637 bytes in 91 blocks
> ==74== suppressed: 0 bytes in 0 blocks
>
&

Re: [petsc-users] AddressSanitizer: attempting free on address which was not malloc()-ed

2019-03-03 Thread Yuyun Yang via petsc-users
Yes, please see the attached files for a minimal example. Thanks a lot!

Best regards,
Yuyun

From: Matthew Knepley 
Sent: Sunday, March 3, 2019 12:46 PM
To: Yuyun Yang 
Cc: Zhang, Junchao ; petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed

On Sun, Mar 3, 2019 at 3:05 PM Yuyun Yang 
mailto:yyan...@stanford.edu>> wrote:
Actually, I tried just creating a domain object (since the address sanitizer 
was complaining about that code to start with). Simply creating that object 
gave me a core dump, so I suppose the issue must be there. I got the following 
message when running the code with -objects_dump flag on the command line, but 
couldn’t find a problem with the code (I’ve attached it here with only the 
relevant functions).

I think what we are going to need from you is a minimal example that has the 
error. I am guessing you have a logic
bug in the C++, which we cannot debug by looking.

  Thanks,

 Matt

Thanks a lot for your help!

The following objects were never freed
-
[0] Vec seq y
  [0]  VecCreate() in 
/home/yyy910805/petsc/src/vec/vec/interface/veccreate.c
[0] Vec seq Vec_0x8400_0
  [0]  VecCreate() in 
/home/yyy910805/petsc/src/vec/vec/interface/veccreate.c
[0] Vec seq Vec_0x8400_1
  [0]  VecCreate() in 
/home/yyy910805/petsc/src/vec/vec/interface/veccreate.c
[0] VecScatter seq VecScatter_0x8400_2
  [0]  VecScatterCreate() in 
/home/yyy910805/petsc/src/vec/vscat/interface/vscreate.c
[0] VecScatter seq VecScatter_0x8400_3
  [0]  VecScatterCreate() in 
/home/yyy910805/petsc/src/vec/vscat/interface/vscreate.c
[0] VecScatter seq VecScatter_0x8400_4
  [0]  VecScatterCreate() in 
/home/yyy910805/petsc/src/vec/vscat/interface/vscreate.c
[0] VecScatter seq VecScatter_0x8400_5
  [0]  VecScatterCreate() in 
/home/yyy910805/petsc/src/vec/vscat/interface/vscreate.c
Attempting to use an MPI routine after finalizing MPICH

-
From: Matthew Knepley mailto:knep...@gmail.com>>
Sent: Sunday, March 3, 2019 11:28 AM
To: Yuyun Yang mailto:yyan...@stanford.edu>>
Cc: Zhang, Junchao mailto:jczh...@mcs.anl.gov>>; 
petsc-users@mcs.anl.gov<mailto:petsc-users@mcs.anl.gov>
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed

On Sun, Mar 3, 2019 at 1:03 PM Yuyun Yang via petsc-users 
mailto:petsc-users@mcs.anl.gov>> wrote:
I tried compiling without the sanitizer and running on valgrind. Got a bunch of 
errors “Uninitialised value was created by a stack allocation at 0x41B280: 
ComputeVel_qd::computeVel(double*, double, int&, int)”.

There is no memory management code here, so other parts of the code must be 
relevant.

  Thanks,

Matt


HEAP SUMMARY:
==74== in use at exit: 96,637 bytes in 91 blocks
==74==   total heap usage: 47,774 allocs, 47,522 frees, 308,253,653 bytes 
allocated
LEAK SUMMARY:
==74==definitely lost: 0 bytes in 0 blocks
==74==indirectly lost: 0 bytes in 0 blocks
==74==  possibly lost: 0 bytes in 0 blocks
==74==still reachable: 96,637 bytes in 91 blocks
==74== suppressed: 0 bytes in 0 blocks

The error is located in the attached code (I’ve extracted only the relevant 
functions), but I couldn’t figure out what is wrong. Is this causing the memory 
corruption/double free error that happens when I execute the code?

Thanks a lot for your help.

Best regards,
Yuyun

From: Zhang, Junchao mailto:jczh...@mcs.anl.gov>>
Sent: Friday, March 1, 2019 7:36 AM
To: Yuyun Yang mailto:yyan...@stanford.edu>>
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed


On Fri, Mar 1, 2019 at 1:02 AM Yuyun Yang 
mailto:yyan...@stanford.edu>> wrote:
Actually, I also saw a line at the beginning of valgrind saying "shadow memory 
range interleaves with an existing memory mapping. ASan cannot proceed 
properly. ABORTING." I guess the code didn't really run through valgrind since 
it aborted. Should I remove the address sanitizer flag when compiling?
From the message, it seems ASan (not valgrind) aborted. You can try to compile 
without sanitizer and then run with valgrind. If no problem, then it is 
probably a sanitizer issue.


Get Outlook for iOS<https://aka.ms/o0ukef>

From: Yuyun Yang
Sent: Thursday, February 28, 2019 10:54:57 PM
To: Zhang, Junchao
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed

Hmm, still getting the same error from address sanitizer even though valgrind 
shows no errors and no leaks are possible.

Should I ignore that error? My results did run alright.

Best,
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>
__

Re: [petsc-users] AddressSanitizer: attempting free on address which was not malloc()-ed

2019-03-03 Thread Yuyun Yang via petsc-users
Actually, I tried just creating a domain object (since the address sanitizer 
was complaining about that code to start with). Simply creating that object 
gave me a core dump, so I suppose the issue must be there. I got the following 
message when running the code with -objects_dump flag on the command line, but 
couldn’t find a problem with the code (I’ve attached it here with only the 
relevant functions).

Thanks a lot for your help!

The following objects were never freed
-
[0] Vec seq y
  [0]  VecCreate() in 
/home/yyy910805/petsc/src/vec/vec/interface/veccreate.c
[0] Vec seq Vec_0x8400_0
  [0]  VecCreate() in 
/home/yyy910805/petsc/src/vec/vec/interface/veccreate.c
[0] Vec seq Vec_0x8400_1
  [0]  VecCreate() in 
/home/yyy910805/petsc/src/vec/vec/interface/veccreate.c
[0] VecScatter seq VecScatter_0x8400_2
  [0]  VecScatterCreate() in 
/home/yyy910805/petsc/src/vec/vscat/interface/vscreate.c
[0] VecScatter seq VecScatter_0x8400_3
  [0]  VecScatterCreate() in 
/home/yyy910805/petsc/src/vec/vscat/interface/vscreate.c
[0] VecScatter seq VecScatter_0x8400_4
  [0]  VecScatterCreate() in 
/home/yyy910805/petsc/src/vec/vscat/interface/vscreate.c
[0] VecScatter seq VecScatter_0x8400_5
  [0]  VecScatterCreate() in 
/home/yyy910805/petsc/src/vec/vscat/interface/vscreate.c
Attempting to use an MPI routine after finalizing MPICH

-
From: Matthew Knepley 
Sent: Sunday, March 3, 2019 11:28 AM
To: Yuyun Yang 
Cc: Zhang, Junchao ; petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed

On Sun, Mar 3, 2019 at 1:03 PM Yuyun Yang via petsc-users 
mailto:petsc-users@mcs.anl.gov>> wrote:
I tried compiling without the sanitizer and running on valgrind. Got a bunch of 
errors “Uninitialised value was created by a stack allocation at 0x41B280: 
ComputeVel_qd::computeVel(double*, double, int&, int)”.

There is no memory management code here, so other parts of the code must be 
relevant.

  Thanks,

Matt


HEAP SUMMARY:
==74== in use at exit: 96,637 bytes in 91 blocks
==74==   total heap usage: 47,774 allocs, 47,522 frees, 308,253,653 bytes 
allocated
LEAK SUMMARY:
==74==definitely lost: 0 bytes in 0 blocks
==74==indirectly lost: 0 bytes in 0 blocks
==74==  possibly lost: 0 bytes in 0 blocks
==74==still reachable: 96,637 bytes in 91 blocks
==74== suppressed: 0 bytes in 0 blocks

The error is located in the attached code (I’ve extracted only the relevant 
functions), but I couldn’t figure out what is wrong. Is this causing the memory 
corruption/double free error that happens when I execute the code?

Thanks a lot for your help.

Best regards,
Yuyun

From: Zhang, Junchao mailto:jczh...@mcs.anl.gov>>
Sent: Friday, March 1, 2019 7:36 AM
To: Yuyun Yang mailto:yyan...@stanford.edu>>
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed


On Fri, Mar 1, 2019 at 1:02 AM Yuyun Yang 
mailto:yyan...@stanford.edu>> wrote:
Actually, I also saw a line at the beginning of valgrind saying "shadow memory 
range interleaves with an existing memory mapping. ASan cannot proceed 
properly. ABORTING." I guess the code didn't really run through valgrind since 
it aborted. Should I remove the address sanitizer flag when compiling?
From the message, it seems ASan (not valgrind) aborted. You can try to compile 
without sanitizer and then run with valgrind. If no problem, then it is 
probably a sanitizer issue.


Get Outlook for iOS<https://aka.ms/o0ukef>

From: Yuyun Yang
Sent: Thursday, February 28, 2019 10:54:57 PM
To: Zhang, Junchao
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed

Hmm, still getting the same error from address sanitizer even though valgrind 
shows no errors and no leaks are possible.

Should I ignore that error? My results did run alright.

Best,
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>

From: Zhang, Junchao mailto:jczh...@mcs.anl.gov>>
Sent: Wednesday, February 27, 2019 8:27:17 PM
To: Yuyun Yang
Cc: Matthew Knepley; petsc-users@mcs.anl.gov<mailto:petsc-users@mcs.anl.gov>
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed

Try the following to see if you can catch the bug easily: 1) Get error code for 
each petsc function and check it with CHKERRQ; 2) Link your code with a petsc 
library with debugging enabled (configured with --with-debugging=1); 3) Run 
your code with valgrind

--Junchao Zhang


On Wed, Feb 27, 2019 at 9:04 PM Yuyun Yang 
mailto:yyan...@stanford.edu>> wrote:
Hi Junchao,

This code actually involves

Re: [petsc-users] AddressSanitizer: attempting free on address which was not malloc()-ed

2019-03-03 Thread Yuyun Yang via petsc-users
I tried compiling without the sanitizer and running on valgrind. Got a bunch of 
errors “Uninitialised value was created by a stack allocation at 0x41B280: 
ComputeVel_qd::computeVel(double*, double, int&, int)”.

HEAP SUMMARY:
==74== in use at exit: 96,637 bytes in 91 blocks
==74==   total heap usage: 47,774 allocs, 47,522 frees, 308,253,653 bytes 
allocated
LEAK SUMMARY:
==74==definitely lost: 0 bytes in 0 blocks
==74==indirectly lost: 0 bytes in 0 blocks
==74==  possibly lost: 0 bytes in 0 blocks
==74==still reachable: 96,637 bytes in 91 blocks
==74== suppressed: 0 bytes in 0 blocks

The error is located in the attached code (I’ve extracted only the relevant 
functions), but I couldn’t figure out what is wrong. Is this causing the memory 
corruption/double free error that happens when I execute the code?

Thanks a lot for your help.

Best regards,
Yuyun

From: Zhang, Junchao 
Sent: Friday, March 1, 2019 7:36 AM
To: Yuyun Yang 
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed


On Fri, Mar 1, 2019 at 1:02 AM Yuyun Yang 
mailto:yyan...@stanford.edu>> wrote:
Actually, I also saw a line at the beginning of valgrind saying "shadow memory 
range interleaves with an existing memory mapping. ASan cannot proceed 
properly. ABORTING." I guess the code didn't really run through valgrind since 
it aborted. Should I remove the address sanitizer flag when compiling?
From the message, it seems ASan (not valgrind) aborted. You can try to compile 
without sanitizer and then run with valgrind. If no problem, then it is 
probably a sanitizer issue.


Get Outlook for iOS<https://aka.ms/o0ukef>

From: Yuyun Yang
Sent: Thursday, February 28, 2019 10:54:57 PM
To: Zhang, Junchao
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed

Hmm, still getting the same error from address sanitizer even though valgrind 
shows no errors and no leaks are possible.

Should I ignore that error? My results did run alright.

Best,
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>

From: Zhang, Junchao mailto:jczh...@mcs.anl.gov>>
Sent: Wednesday, February 27, 2019 8:27:17 PM
To: Yuyun Yang
Cc: Matthew Knepley; petsc-users@mcs.anl.gov<mailto:petsc-users@mcs.anl.gov>
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed

Try the following to see if you can catch the bug easily: 1) Get error code for 
each petsc function and check it with CHKERRQ; 2) Link your code with a petsc 
library with debugging enabled (configured with --with-debugging=1); 3) Run 
your code with valgrind

--Junchao Zhang


On Wed, Feb 27, 2019 at 9:04 PM Yuyun Yang 
mailto:yyan...@stanford.edu>> wrote:
Hi Junchao,

This code actually involves a lot of classes and is pretty big. Might be an 
overkill for me to send everything to you. I'd like to know if I see this sort 
of error message, which points to this domain file, is it possible that the 
problem happens in another file (whose operations are linked to this one)? If 
so, I'll debug a little more and maybe send you more useful information later.

Best regards,
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>

From: Zhang, Junchao mailto:jczh...@mcs.anl.gov>>
Sent: Wednesday, February 27, 2019 6:24:13 PM
To: Yuyun Yang
Cc: Matthew Knepley; petsc-users@mcs.anl.gov<mailto:petsc-users@mcs.anl.gov>
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed

Could you provide a compilable and runnable test so I can try it?
--Junchao Zhang


On Wed, Feb 27, 2019 at 7:34 PM Yuyun Yang 
mailto:yyan...@stanford.edu>> wrote:
Thanks, I fixed that, but I’m not actually calling the testScatters() function 
in my implementation (in the constructor, the only functions I called are 
setFields and setScatters). So the problem couldn’t have been that?

Best,
Yuyun

From: Zhang, Junchao mailto:jczh...@mcs.anl.gov>>
Sent: Wednesday, February 27, 2019 10:50 AM
To: Yuyun Yang mailto:yyan...@stanford.edu>>
Cc: Matthew Knepley mailto:knep...@gmail.com>>; 
petsc-users@mcs.anl.gov<mailto:petsc-users@mcs.anl.gov>
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed


On Wed, Feb 27, 2019 at 10:41 AM Yuyun Yang via petsc-users 
mailto:petsc-users@mcs.anl.gov>> wrote:
I called VecDestroy() in the destructor for this object – is that not the right 
way to do it?
In Domain::testScatters(), you have many VecDuplicate(,&out), You need to 
VecDestroy(&out) before doing new VecDuplicate(,&out);
How do I implement CHECK ALL RETURN CODES?
For each PETSc function, do ierr = ...;  CHKERRQ(ierr);

From: Matthew Knepley mailto:knep...@gmail.com>>
Sent: Wednesday, February 27, 

Re: [petsc-users] AddressSanitizer: attempting free on address which was not malloc()-ed

2019-02-27 Thread Yuyun Yang via petsc-users
Ok, will do that. Thanks a lot!

Get Outlook for iOS<https://aka.ms/o0ukef>

From: Zhang, Junchao 
Sent: Wednesday, February 27, 2019 8:27:17 PM
To: Yuyun Yang
Cc: Matthew Knepley; petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed

Try the following to see if you can catch the bug easily: 1) Get error code for 
each petsc function and check it with CHKERRQ; 2) Link your code with a petsc 
library with debugging enabled (configured with --with-debugging=1); 3) Run 
your code with valgrind

--Junchao Zhang


On Wed, Feb 27, 2019 at 9:04 PM Yuyun Yang 
mailto:yyan...@stanford.edu>> wrote:
Hi Junchao,

This code actually involves a lot of classes and is pretty big. Might be an 
overkill for me to send everything to you. I'd like to know if I see this sort 
of error message, which points to this domain file, is it possible that the 
problem happens in another file (whose operations are linked to this one)? If 
so, I'll debug a little more and maybe send you more useful information later.

Best regards,
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>

From: Zhang, Junchao mailto:jczh...@mcs.anl.gov>>
Sent: Wednesday, February 27, 2019 6:24:13 PM
To: Yuyun Yang
Cc: Matthew Knepley; petsc-users@mcs.anl.gov<mailto:petsc-users@mcs.anl.gov>
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed

Could you provide a compilable and runnable test so I can try it?
--Junchao Zhang


On Wed, Feb 27, 2019 at 7:34 PM Yuyun Yang 
mailto:yyan...@stanford.edu>> wrote:
Thanks, I fixed that, but I’m not actually calling the testScatters() function 
in my implementation (in the constructor, the only functions I called are 
setFields and setScatters). So the problem couldn’t have been that?

Best,
Yuyun

From: Zhang, Junchao mailto:jczh...@mcs.anl.gov>>
Sent: Wednesday, February 27, 2019 10:50 AM
To: Yuyun Yang mailto:yyan...@stanford.edu>>
Cc: Matthew Knepley mailto:knep...@gmail.com>>; 
petsc-users@mcs.anl.gov<mailto:petsc-users@mcs.anl.gov>
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed


On Wed, Feb 27, 2019 at 10:41 AM Yuyun Yang via petsc-users 
mailto:petsc-users@mcs.anl.gov>> wrote:
I called VecDestroy() in the destructor for this object – is that not the right 
way to do it?
In Domain::testScatters(), you have many VecDuplicate(,&out), You need to 
VecDestroy(&out) before doing new VecDuplicate(,&out);
How do I implement CHECK ALL RETURN CODES?
For each PETSc function, do ierr = ...;  CHKERRQ(ierr);

From: Matthew Knepley mailto:knep...@gmail.com>>
Sent: Wednesday, February 27, 2019 7:24 AM
To: Yuyun Yang mailto:yyan...@stanford.edu>>
Cc: petsc-users@mcs.anl.gov<mailto:petsc-users@mcs.anl.gov>
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed

You call VecDuplicate() a bunch, but VecDestroy() only once in the bottom 
function. This is wrong.
Also, CHECK ALL RETURN CODES. This is the fastest way to find errors.

   Matt

On Wed, Feb 27, 2019 at 2:06 AM Yuyun Yang via petsc-users 
mailto:petsc-users@mcs.anl.gov>> wrote:
Hello team,

I ran into the address sanitizer error that I hope you could help me with. I 
don’t really know what’s wrong with the way the code frees memory. The relevant 
code file is attached. The line number following domain.cpp specifically 
referenced to the vector _q, which seems a little odd, since some other vectors 
are constructed and freed the same way.

==1719==ERROR: AddressSanitizer: attempting free on address which was not 
malloc()-ed: 0x61f076c0 in thread T0
#0 0x7fbf195282ca in __interceptor_free 
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x982ca)
#1 0x7fbf1706f895 in PetscFreeAlign 
/home/yyy910805/petsc/src/sys/memory/mal.c:87
#2 0x7fbf1731a898 in VecDestroy_Seq 
/home/yyy910805/petsc/src/vec/vec/impls/seq/bvec2.c:788
#3 0x7fbf1735f795 in VecDestroy 
/home/yyy910805/petsc/src/vec/vec/interface/vector.c:408
#4 0x40dd0a in Domain::~Domain() 
/home/yyy910805/scycle/source/domain.cpp:132
#5 0x40b479 in main /home/yyy910805/scycle/source/main.cpp:242
#6 0x7fbf14d2082f in __libc_start_main 
(/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#7 0x4075d8 in _start (/home/yyy910805/scycle/source/main+0x4075d8)

0x61f076c0 is located 1600 bytes inside of 3220-byte region 
[0x61f07080,0x61f07d14)
allocated by thread T0 here:
#0 0x7fbf19528b32 in __interceptor_memalign 
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98b32)
#1 0x7fbf1706f7e0 in PetscMallocAlign 
/home/yyy910805/petsc/src/sys/memory/mal.c:41
#2 0x7fbf17073022 in PetscTrMallocDefault 
/home/yyy910805/petsc/src/sys/memory/mtr.c:183
#3 0x7fbf170710a1 in PetscMallocA 
/home/yyy910805/petsc/src/sys/memory

Re: [petsc-users] AddressSanitizer: attempting free on address which was not malloc()-ed

2019-02-27 Thread Yuyun Yang via petsc-users
Hi Junchao,

This code actually involves a lot of classes and is pretty big. Might be an 
overkill for me to send everything to you. I'd like to know if I see this sort 
of error message, which points to this domain file, is it possible that the 
problem happens in another file (whose operations are linked to this one)? If 
so, I'll debug a little more and maybe send you more useful information later.

Best regards,
Yuyun

Get Outlook for iOS<https://aka.ms/o0ukef>

From: Zhang, Junchao 
Sent: Wednesday, February 27, 2019 6:24:13 PM
To: Yuyun Yang
Cc: Matthew Knepley; petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed

Could you provide a compilable and runnable test so I can try it?
--Junchao Zhang


On Wed, Feb 27, 2019 at 7:34 PM Yuyun Yang 
mailto:yyan...@stanford.edu>> wrote:
Thanks, I fixed that, but I’m not actually calling the testScatters() function 
in my implementation (in the constructor, the only functions I called are 
setFields and setScatters). So the problem couldn’t have been that?

Best,
Yuyun

From: Zhang, Junchao mailto:jczh...@mcs.anl.gov>>
Sent: Wednesday, February 27, 2019 10:50 AM
To: Yuyun Yang mailto:yyan...@stanford.edu>>
Cc: Matthew Knepley mailto:knep...@gmail.com>>; 
petsc-users@mcs.anl.gov<mailto:petsc-users@mcs.anl.gov>
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed


On Wed, Feb 27, 2019 at 10:41 AM Yuyun Yang via petsc-users 
mailto:petsc-users@mcs.anl.gov>> wrote:
I called VecDestroy() in the destructor for this object – is that not the right 
way to do it?
In Domain::testScatters(), you have many VecDuplicate(,&out), You need to 
VecDestroy(&out) before doing new VecDuplicate(,&out);
How do I implement CHECK ALL RETURN CODES?
For each PETSc function, do ierr = ...;  CHKERRQ(ierr);

From: Matthew Knepley mailto:knep...@gmail.com>>
Sent: Wednesday, February 27, 2019 7:24 AM
To: Yuyun Yang mailto:yyan...@stanford.edu>>
Cc: petsc-users@mcs.anl.gov<mailto:petsc-users@mcs.anl.gov>
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed

You call VecDuplicate() a bunch, but VecDestroy() only once in the bottom 
function. This is wrong.
Also, CHECK ALL RETURN CODES. This is the fastest way to find errors.

   Matt

On Wed, Feb 27, 2019 at 2:06 AM Yuyun Yang via petsc-users 
mailto:petsc-users@mcs.anl.gov>> wrote:
Hello team,

I ran into the address sanitizer error that I hope you could help me with. I 
don’t really know what’s wrong with the way the code frees memory. The relevant 
code file is attached. The line number following domain.cpp specifically 
referenced to the vector _q, which seems a little odd, since some other vectors 
are constructed and freed the same way.

==1719==ERROR: AddressSanitizer: attempting free on address which was not 
malloc()-ed: 0x61f076c0 in thread T0
#0 0x7fbf195282ca in __interceptor_free 
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x982ca)
#1 0x7fbf1706f895 in PetscFreeAlign 
/home/yyy910805/petsc/src/sys/memory/mal.c:87
#2 0x7fbf1731a898 in VecDestroy_Seq 
/home/yyy910805/petsc/src/vec/vec/impls/seq/bvec2.c:788
#3 0x7fbf1735f795 in VecDestroy 
/home/yyy910805/petsc/src/vec/vec/interface/vector.c:408
#4 0x40dd0a in Domain::~Domain() 
/home/yyy910805/scycle/source/domain.cpp:132
#5 0x40b479 in main /home/yyy910805/scycle/source/main.cpp:242
#6 0x7fbf14d2082f in __libc_start_main 
(/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#7 0x4075d8 in _start (/home/yyy910805/scycle/source/main+0x4075d8)

0x61f076c0 is located 1600 bytes inside of 3220-byte region 
[0x61f07080,0x61f07d14)
allocated by thread T0 here:
#0 0x7fbf19528b32 in __interceptor_memalign 
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98b32)
#1 0x7fbf1706f7e0 in PetscMallocAlign 
/home/yyy910805/petsc/src/sys/memory/mal.c:41
#2 0x7fbf17073022 in PetscTrMallocDefault 
/home/yyy910805/petsc/src/sys/memory/mtr.c:183
#3 0x7fbf170710a1 in PetscMallocA 
/home/yyy910805/petsc/src/sys/memory/mal.c:397
#4 0x7fbf17326fb0 in VecCreate_Seq 
/home/yyy910805/petsc/src/vec/vec/impls/seq/bvec3.c:35
#5 0x7fbf1736f560 in VecSetType 
/home/yyy910805/petsc/src/vec/vec/interface/vecreg.c:51
#6 0x7fbf1731afae in VecDuplicate_Seq 
/home/yyy910805/petsc/src/vec/vec/impls/seq/bvec2.c:807
#7 0x7fbf1735eff7 in VecDuplicate 
/home/yyy910805/petsc/src/vec/vec/interface/vector.c:379
#8 0x4130de in Domain::setFields() 
/home/yyy910805/scycle/source/domain.cpp:431
#9 0x40c60a in Domain::Domain(char const*) 
/home/yyy910805/scycle/source/domain.cpp:57
#10 0x40b433 in main /home/yyy910805/scycle/source/main.cpp:242
#11 0x7fbf14d2082f in __libc_start_main 
(/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

SUMMARY: AddressSanitizer: bad-free ??:0 __intercep

Re: [petsc-users] AddressSanitizer: attempting free on address which was not malloc()-ed

2019-02-27 Thread Yuyun Yang via petsc-users
Thanks, I fixed that, but I’m not actually calling the testScatters() function 
in my implementation (in the constructor, the only functions I called are 
setFields and setScatters). So the problem couldn’t have been that?

Best,
Yuyun

From: Zhang, Junchao 
Sent: Wednesday, February 27, 2019 10:50 AM
To: Yuyun Yang 
Cc: Matthew Knepley ; petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed


On Wed, Feb 27, 2019 at 10:41 AM Yuyun Yang via petsc-users 
mailto:petsc-users@mcs.anl.gov>> wrote:
I called VecDestroy() in the destructor for this object – is that not the right 
way to do it?
In Domain::testScatters(), you have many VecDuplicate(,&out), You need to 
VecDestroy(&out) before doing new VecDuplicate(,&out);
How do I implement CHECK ALL RETURN CODES?
For each PETSc function, do ierr = ...;  CHKERRQ(ierr);

From: Matthew Knepley mailto:knep...@gmail.com>>
Sent: Wednesday, February 27, 2019 7:24 AM
To: Yuyun Yang mailto:yyan...@stanford.edu>>
Cc: petsc-users@mcs.anl.gov<mailto:petsc-users@mcs.anl.gov>
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed

You call VecDuplicate() a bunch, but VecDestroy() only once in the bottom 
function. This is wrong.
Also, CHECK ALL RETURN CODES. This is the fastest way to find errors.

   Matt

On Wed, Feb 27, 2019 at 2:06 AM Yuyun Yang via petsc-users 
mailto:petsc-users@mcs.anl.gov>> wrote:
Hello team,

I ran into the address sanitizer error that I hope you could help me with. I 
don’t really know what’s wrong with the way the code frees memory. The relevant 
code file is attached. The line number following domain.cpp specifically 
referenced to the vector _q, which seems a little odd, since some other vectors 
are constructed and freed the same way.

==1719==ERROR: AddressSanitizer: attempting free on address which was not 
malloc()-ed: 0x61f076c0 in thread T0
#0 0x7fbf195282ca in __interceptor_free 
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x982ca)
#1 0x7fbf1706f895 in PetscFreeAlign 
/home/yyy910805/petsc/src/sys/memory/mal.c:87
#2 0x7fbf1731a898 in VecDestroy_Seq 
/home/yyy910805/petsc/src/vec/vec/impls/seq/bvec2.c:788
#3 0x7fbf1735f795 in VecDestroy 
/home/yyy910805/petsc/src/vec/vec/interface/vector.c:408
#4 0x40dd0a in Domain::~Domain() 
/home/yyy910805/scycle/source/domain.cpp:132
#5 0x40b479 in main /home/yyy910805/scycle/source/main.cpp:242
#6 0x7fbf14d2082f in __libc_start_main 
(/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#7 0x4075d8 in _start (/home/yyy910805/scycle/source/main+0x4075d8)

0x61f076c0 is located 1600 bytes inside of 3220-byte region 
[0x61f07080,0x61f07d14)
allocated by thread T0 here:
#0 0x7fbf19528b32 in __interceptor_memalign 
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98b32)
#1 0x7fbf1706f7e0 in PetscMallocAlign 
/home/yyy910805/petsc/src/sys/memory/mal.c:41
#2 0x7fbf17073022 in PetscTrMallocDefault 
/home/yyy910805/petsc/src/sys/memory/mtr.c:183
#3 0x7fbf170710a1 in PetscMallocA 
/home/yyy910805/petsc/src/sys/memory/mal.c:397
#4 0x7fbf17326fb0 in VecCreate_Seq 
/home/yyy910805/petsc/src/vec/vec/impls/seq/bvec3.c:35
#5 0x7fbf1736f560 in VecSetType 
/home/yyy910805/petsc/src/vec/vec/interface/vecreg.c:51
#6 0x7fbf1731afae in VecDuplicate_Seq 
/home/yyy910805/petsc/src/vec/vec/impls/seq/bvec2.c:807
#7 0x7fbf1735eff7 in VecDuplicate 
/home/yyy910805/petsc/src/vec/vec/interface/vector.c:379
#8 0x4130de in Domain::setFields() 
/home/yyy910805/scycle/source/domain.cpp:431
#9 0x40c60a in Domain::Domain(char const*) 
/home/yyy910805/scycle/source/domain.cpp:57
#10 0x40b433 in main /home/yyy910805/scycle/source/main.cpp:242
#11 0x7fbf14d2082f in __libc_start_main 
(/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

SUMMARY: AddressSanitizer: bad-free ??:0 __interceptor_free
==1719==ABORTING

Thanks very much!
Yuyun


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


Re: [petsc-users] AddressSanitizer: attempting free on address which was not malloc()-ed

2019-02-27 Thread Yuyun Yang via petsc-users
I called VecDestroy() in the destructor for this object – is that not the right 
way to do it?
How do I implement CHECK ALL RETURN CODES?

From: Matthew Knepley 
Sent: Wednesday, February 27, 2019 7:24 AM
To: Yuyun Yang 
Cc: petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] AddressSanitizer: attempting free on address which 
was not malloc()-ed

You call VecDuplicate() a bunch, but VecDestroy() only once in the bottom 
function. This is wrong.
Also, CHECK ALL RETURN CODES. This is the fastest way to find errors.

   Matt

On Wed, Feb 27, 2019 at 2:06 AM Yuyun Yang via petsc-users 
mailto:petsc-users@mcs.anl.gov>> wrote:
Hello team,

I ran into the address sanitizer error that I hope you could help me with. I 
don’t really know what’s wrong with the way the code frees memory. The relevant 
code file is attached. The line number following domain.cpp specifically 
referenced to the vector _q, which seems a little odd, since some other vectors 
are constructed and freed the same way.

==1719==ERROR: AddressSanitizer: attempting free on address which was not 
malloc()-ed: 0x61f076c0 in thread T0
#0 0x7fbf195282ca in __interceptor_free 
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x982ca)
#1 0x7fbf1706f895 in PetscFreeAlign 
/home/yyy910805/petsc/src/sys/memory/mal.c:87
#2 0x7fbf1731a898 in VecDestroy_Seq 
/home/yyy910805/petsc/src/vec/vec/impls/seq/bvec2.c:788
#3 0x7fbf1735f795 in VecDestroy 
/home/yyy910805/petsc/src/vec/vec/interface/vector.c:408
#4 0x40dd0a in Domain::~Domain() 
/home/yyy910805/scycle/source/domain.cpp:132
#5 0x40b479 in main /home/yyy910805/scycle/source/main.cpp:242
#6 0x7fbf14d2082f in __libc_start_main 
(/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#7 0x4075d8 in _start (/home/yyy910805/scycle/source/main+0x4075d8)

0x61f076c0 is located 1600 bytes inside of 3220-byte region 
[0x61f07080,0x61f07d14)
allocated by thread T0 here:
#0 0x7fbf19528b32 in __interceptor_memalign 
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98b32)
#1 0x7fbf1706f7e0 in PetscMallocAlign 
/home/yyy910805/petsc/src/sys/memory/mal.c:41
#2 0x7fbf17073022 in PetscTrMallocDefault 
/home/yyy910805/petsc/src/sys/memory/mtr.c:183
#3 0x7fbf170710a1 in PetscMallocA 
/home/yyy910805/petsc/src/sys/memory/mal.c:397
#4 0x7fbf17326fb0 in VecCreate_Seq 
/home/yyy910805/petsc/src/vec/vec/impls/seq/bvec3.c:35
#5 0x7fbf1736f560 in VecSetType 
/home/yyy910805/petsc/src/vec/vec/interface/vecreg.c:51
#6 0x7fbf1731afae in VecDuplicate_Seq 
/home/yyy910805/petsc/src/vec/vec/impls/seq/bvec2.c:807
#7 0x7fbf1735eff7 in VecDuplicate 
/home/yyy910805/petsc/src/vec/vec/interface/vector.c:379
#8 0x4130de in Domain::setFields() 
/home/yyy910805/scycle/source/domain.cpp:431
#9 0x40c60a in Domain::Domain(char const*) 
/home/yyy910805/scycle/source/domain.cpp:57
#10 0x40b433 in main /home/yyy910805/scycle/source/main.cpp:242
#11 0x7fbf14d2082f in __libc_start_main 
(/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

SUMMARY: AddressSanitizer: bad-free ??:0 __interceptor_free
==1719==ABORTING

Thanks very much!
Yuyun


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


[petsc-users] AddressSanitizer: attempting free on address which was not malloc()-ed

2019-02-26 Thread Yuyun Yang via petsc-users
Hello team,

I ran into the address sanitizer error that I hope you could help me with. I 
don't really know what's wrong with the way the code frees memory. The relevant 
code file is attached. The line number following domain.cpp specifically 
referenced to the vector _q, which seems a little odd, since some other vectors 
are constructed and freed the same way.

==1719==ERROR: AddressSanitizer: attempting free on address which was not 
malloc()-ed: 0x61f076c0 in thread T0
#0 0x7fbf195282ca in __interceptor_free 
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x982ca)
#1 0x7fbf1706f895 in PetscFreeAlign 
/home/yyy910805/petsc/src/sys/memory/mal.c:87
#2 0x7fbf1731a898 in VecDestroy_Seq 
/home/yyy910805/petsc/src/vec/vec/impls/seq/bvec2.c:788
#3 0x7fbf1735f795 in VecDestroy 
/home/yyy910805/petsc/src/vec/vec/interface/vector.c:408
#4 0x40dd0a in Domain::~Domain() 
/home/yyy910805/scycle/source/domain.cpp:132
#5 0x40b479 in main /home/yyy910805/scycle/source/main.cpp:242
#6 0x7fbf14d2082f in __libc_start_main 
(/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#7 0x4075d8 in _start (/home/yyy910805/scycle/source/main+0x4075d8)

0x61f076c0 is located 1600 bytes inside of 3220-byte region 
[0x61f07080,0x61f07d14)
allocated by thread T0 here:
#0 0x7fbf19528b32 in __interceptor_memalign 
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98b32)
#1 0x7fbf1706f7e0 in PetscMallocAlign 
/home/yyy910805/petsc/src/sys/memory/mal.c:41
#2 0x7fbf17073022 in PetscTrMallocDefault 
/home/yyy910805/petsc/src/sys/memory/mtr.c:183
#3 0x7fbf170710a1 in PetscMallocA 
/home/yyy910805/petsc/src/sys/memory/mal.c:397
#4 0x7fbf17326fb0 in VecCreate_Seq 
/home/yyy910805/petsc/src/vec/vec/impls/seq/bvec3.c:35
#5 0x7fbf1736f560 in VecSetType 
/home/yyy910805/petsc/src/vec/vec/interface/vecreg.c:51
#6 0x7fbf1731afae in VecDuplicate_Seq 
/home/yyy910805/petsc/src/vec/vec/impls/seq/bvec2.c:807
#7 0x7fbf1735eff7 in VecDuplicate 
/home/yyy910805/petsc/src/vec/vec/interface/vector.c:379
#8 0x4130de in Domain::setFields() 
/home/yyy910805/scycle/source/domain.cpp:431
#9 0x40c60a in Domain::Domain(char const*) 
/home/yyy910805/scycle/source/domain.cpp:57
#10 0x40b433 in main /home/yyy910805/scycle/source/main.cpp:242
#11 0x7fbf14d2082f in __libc_start_main 
(/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

SUMMARY: AddressSanitizer: bad-free ??:0 __interceptor_free
==1719==ABORTING

Thanks very much!
Yuyun
#include "domain.hpp"

#define FILENAME "sbpOps_fc.cpp"

using namespace std;

// member function definitions including constructor
// first type of constructor with 1 parameter
Domain::Domain(const char *file)
: _file(file),_delim(" = "),_outputDir("data/"),
  _bulkDeformationType("linearElastic"),
  _momentumBalanceType("quasidynamic"),
  _sbpType("mfc_coordTrans"),_operatorType("matrix-based"),
  _sbpCompatibilityType("fullyCompatible"),
  _gridSpacingType("variableGridSpacing"),
  _isMMS(0),_loadICs(0), _inputDir("unspecified_"),
  _order(4),_Ny(-1),_Nz(-1),_Ly(-1),_Lz(-1),
  _vL(1e-9),
  _q(NULL),_r(NULL),_y(NULL),_z(NULL),_y0(NULL),_z0(NULL),_dq(-1),_dr(-1),
  _bCoordTrans(-1)
{
  #if VERBOSE > 1
std::string funcName = "Domain::Domain(const char *file)";
PetscPrintf(PETSC_COMM_WORLD,"Starting %s in 
%s.\n",funcName.c_str(),FILENAME);
  #endif

  // load data from file
  loadData(_file);

  // check domain size and set grid spacing in y direction
  if (_Ny > 1) {
_dq = 1.0 / (_Ny - 1.0);
  }
  else {
_dq = 1;
  }

  // set grid spacing in z-direction
  if (_Nz > 1) {
_dr = 1.0 / (_Nz - 1.0);
  }
  else {
_dr = 1;
  }

  #if VERBOSE > 2 // each processor prints loaded values to screen
PetscMPIInt rank,size;
MPI_Comm_size(PETSC_COMM_WORLD,&size);
MPI_Comm_rank(PETSC_COMM_WORLD,&rank);

for (int Ii = 0; Ii < size; Ii++) {
  view(Ii);
}
  #endif

  checkInput(); // perform some basic value checking to prevent NaNs
  setFields();
  setScatters();

  #if VERBOSE > 1
PetscPrintf(PETSC_COMM_WORLD,"Ending %s in %s\n",funcName.c_str(),FILENAME);
  #endif

}


// second type of constructor with 3 parameters
Domain::Domain(const char *file,PetscInt Ny, PetscInt Nz)
: _file(file),_delim(" = "),_outputDir("data/"),
  _bulkDeformationType("linearElastic"),_momentumBalanceType("quasidynamic"),
  
_sbpType("mfc_coordTrans"),_operatorType("matrix-based"),_sbpCompatibilityType("fullyCompatible"),_gridSpacingType("variableGridSpacing"),
  _isMMS(0),_loadICs(0),_inputDir("unspecified_"),
  _order(4),_Ny(Ny),_Nz(Nz),_Ly(-1),_Lz(-1),
  _vL(1e-9),
  _q(NULL),_r(NULL),_y(NULL),_z(NULL),_y0(NULL),_z0(NULL),_dq(-1),_dr(-1),
  _bCoordTrans(-1)
{
  #if VERBOSE > 1
std::string funcName = "Domain::Domain(const char *file,PetscInt Ny, 
PetscInt Nz)";
PetscPrintf(PETSC_COMM_WORLD,"Starting %s in 
%s.\n",funcName.c_str(),FILENAME);
  #endif

  loadData(_file);

  _Ny = Ny;
  _Nz = Nz;

  if (_Ny > 1) {
_dq = 1.0/(_Ny-1.0);
  }
  else {
_dq 

[petsc-users] Kronecker product

2019-02-25 Thread Yuyun Yang via petsc-users
Hello team,

I'd like to ask whether PETSc has a function to compute the Kronecker product 
of a sparse matrix with an identity matrix? A Google search didn't lead me to a 
manual page (like most of the other PETSc functions), so I'm wondering if this 
has been implemented yet.

Thanks very much!

Best,
Yuyun


Re: [petsc-users] PetscBinaryRead fails

2019-02-18 Thread Yuyun Yang via petsc-users
Oh I see, thanks for confirming it works with an 8-byte file. I didn't generate 
it from a code but just put a random number in a blank file. I thought it would 
automatically be the right size but that isn't the case.


Get Outlook for iOS<https://aka.ms/o0ukef>

From: Smith, Barry F. 
Sent: Monday, February 18, 2019 8:06:16 PM
To: Yuyun Yang
Cc: petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] PetscBinaryRead fails


  I don't know how you got your _test file but it is the wrong size

$ ls -l _test
-rw-r--r--@ 1 barrysmith  staff  6 Feb 18 21:25 _test
~/Src/petsc/test-dir (maint=) arch-basic

it only has 6 bytes but to hold a PETSC_SCALAR (when PetscScalar is real) it 
should have 8 bytes. For example the code

  PetscViewer viewer;
  PetscScalar v;
  int fd;

  PetscViewerBinaryOpen(PETSC_COMM_WORLD, "joe", FILE_MODE_WRITE, &viewer);
PetscViewerBinaryGetDescriptor(viewer, &fd);
PetscBinaryWrite(fd, &value, 1, PETSC_SCALAR,PETSC_FALSE);
PetscViewerDestroy(&viewer);

produces a file with 8 bytes in it

$ ls -l joe
-rw-r--r--  1 barrysmith  staff  8 Feb 18 22:03 joe

which can be read in by your program.

> On Feb 18, 2019, at 9:23 PM, Yuyun Yang  wrote:
>
> I used FILE_MODE_READ. Please see attached file (the function is part of 
> another file therefore all the other include statements; I've extracted it 
> here). The test file only contains one number. My directory is hard-coded 
> into the main function.
>
> Thanks a lot!
> Yuyun
>
> -Original Message-
> From: Smith, Barry F. 
> Sent: Monday, February 18, 2019 6:41 PM
> To: Yuyun Yang 
> Cc: petsc-users@mcs.anl.gov
> Subject: Re: [petsc-users] PetscBinaryRead fails
>
>
>  Send program and data file if you cannot get it to work.
>
>
>> On Feb 18, 2019, at 8:08 PM, Yuyun Yang via petsc-users 
>>  wrote:
>>
>> Hello,
>>
>> I am writing a very simple function just to read in a single value from an 
>> input file (which also just contains one single scalar value). Using 
>> PetscBinaryRead(fd, &value, 1, PETSC_SCALAR) gives me the following error. 
>> Could you help me figure out why?
>>
>> [0]PETSC ERROR: - Error Message
>> --
>> [0]PETSC ERROR: Read from file failed
>> [0]PETSC ERROR: Read past end of file
>> [0]PETSC ERROR: See http://www.mcs.anl.gov/petsc/documentation/faq.html for 
>> trouble shooting.
>> [0]PETSC ERROR: Petsc Release Version 3.10.3, unknown [0]PETSC ERROR:
>> ./output on a arch-linux2-c-debug named DESKTOP-02K82L1.stanford.edu
>> by yyy910805 Mon Feb 18 17:58:30 2019 [0]PETSC ERROR: Configure options 
>> --with-cc=gcc --with-cxx=g++ --with-shared-libraries=1 --download-hdf5 
>> --download-metis --download-parmetis --download-hypre --download-superlu 
>> --download-mumps --download-scalapack --download-mpich 
>> --download-mpich-configure-arguments="--enable-error-messages=all --enable-g"
>> [0]PETSC ERROR: #1 PetscBinaryRead() line 276 in
>> /home/yyy910805/petsc/src/sys/fileio/sysio.c
>> 0.00
>>
>> Thanks a lot!
>> Yuyun
>
> <_test>



Re: [petsc-users] PetscBinaryRead fails

2019-02-18 Thread Yuyun Yang via petsc-users
I used FILE_MODE_READ. Please see attached file (the function is part of 
another file therefore all the other include statements; I've extracted it 
here). The test file only contains one number. My directory is hard-coded into 
the main function.

Thanks a lot!
Yuyun

-Original Message-
From: Smith, Barry F.  
Sent: Monday, February 18, 2019 6:41 PM
To: Yuyun Yang 
Cc: petsc-users@mcs.anl.gov
Subject: Re: [petsc-users] PetscBinaryRead fails


  Send program and data file if you cannot get it to work.


> On Feb 18, 2019, at 8:08 PM, Yuyun Yang via petsc-users 
>  wrote:
> 
> Hello,
>  
> I am writing a very simple function just to read in a single value from an 
> input file (which also just contains one single scalar value). Using 
> PetscBinaryRead(fd, &value, 1, PETSC_SCALAR) gives me the following error. 
> Could you help me figure out why?
>  
> [0]PETSC ERROR: - Error Message 
> --
> [0]PETSC ERROR: Read from file failed
> [0]PETSC ERROR: Read past end of file
> [0]PETSC ERROR: See http://www.mcs.anl.gov/petsc/documentation/faq.html for 
> trouble shooting.
> [0]PETSC ERROR: Petsc Release Version 3.10.3, unknown [0]PETSC ERROR: 
> ./output on a arch-linux2-c-debug named DESKTOP-02K82L1.stanford.edu 
> by yyy910805 Mon Feb 18 17:58:30 2019 [0]PETSC ERROR: Configure options 
> --with-cc=gcc --with-cxx=g++ --with-shared-libraries=1 --download-hdf5 
> --download-metis --download-parmetis --download-hypre --download-superlu 
> --download-mumps --download-scalapack --download-mpich 
> --download-mpich-configure-arguments="--enable-error-messages=all --enable-g"
> [0]PETSC ERROR: #1 PetscBinaryRead() line 276 in 
> /home/yyy910805/petsc/src/sys/fileio/sysio.c
> 0.00
>  
> Thanks a lot!
> Yuyun

//#include "genFuncs.hpp"

#include 
#include 
#include 
#include 
#include 
#include 
#include 

#include 
#include 
#include 

using namespace std;

PetscErrorCode loadValueFromCheckpoint(const string outputDir, const string 
filename, PetscScalar &value) {
  PetscErrorCode ierr = 0;
  #if VERBOSE > 1
  ierr = PetscPrinf(PETSC_COMM_WORLD, "Starting loadValueFromCheckpoint in 
genFuncs.cpp.\n"); CHKERRQ(ierr);
  ierr = PetscPrintf(PETSC_COMM_WORLD, "Attempting to load %s%s\n", 
outputDir.c_str(), filename.c_str()); CHKERRQ(ierr);
  #endif

  string checkpointFile = outputDir + filename;
  bool fileExists = doesFileExist(checkpointFile);
  if (fileExists) {
PetscPrintf(PETSC_COMM_WORLD, "Loading %s\n", filename.c_str());
PetscViewer viewer;
int fd;
PetscViewerBinaryOpen(PETSC_COMM_WORLD, checkpointFile.c_str(), 
FILE_MODE_READ, &viewer);
PetscViewerBinaryGetDescriptor(viewer, &fd);
PetscBinaryRead(fd, &value, 1, PETSC_SCALAR);
PetscViewerDestroy(&viewer);
  }
  else {
PetscPrintf(PETSC_COMM_WORLD, "Warning: %s not found.\n", 
checkpointFile.c_str());
  }

  #if VERBOSE > 1
  ierr = PetscPrintf(PETSC_COMM_WORLD, "Ending loadValueFromCheckpoint in 
%s.\n", filename.c_str()); CHKERRQ(ierr);
  #endif

  return ierr;
}


int main(int argc, char **args) {
  PetscErrorCode ierr = 0;

  ierr = PetscInitialize(&argc, &args, NULL, NULL); CHKERRQ(ierr);

  // directory and filename
  const string outputDir = "/home/yyy910805/";
  const string filename = "_test";
  PetscScalar value = 0;

  loadValueFromCheckpoint(outputDir, filename, value);
  ierr = PetscPrintf(PETSC_COMM_WORLD, " %f\n", value); CHKERRQ(ierr);

  ierr = PetscFinalize(); CHKERRQ(ierr);
  
  return 0;
}


_test
Description: _test


[petsc-users] PetscBinaryRead fails

2019-02-18 Thread Yuyun Yang via petsc-users
Hello,

I am writing a very simple function just to read in a single value from an 
input file (which also just contains one single scalar value). Using 
PetscBinaryRead(fd, &value, 1, PETSC_SCALAR) gives me the following error. 
Could you help me figure out why?

[0]PETSC ERROR: - Error Message 
--
[0]PETSC ERROR: Read from file failed
[0]PETSC ERROR: Read past end of file
[0]PETSC ERROR: See http://www.mcs.anl.gov/petsc/documentation/faq.html for 
trouble shooting.
[0]PETSC ERROR: Petsc Release Version 3.10.3, unknown
[0]PETSC ERROR: ./output on a arch-linux2-c-debug named 
DESKTOP-02K82L1.stanford.edu by yyy910805 Mon Feb 18 17:58:30 2019
[0]PETSC ERROR: Configure options --with-cc=gcc --with-cxx=g++ 
--with-shared-libraries=1 --download-hdf5 --download-metis --download-parmetis 
--download-hypre --download-superlu --download-mumps --download-scalapack 
--download-mpich 
--download-mpich-configure-arguments="--enable-error-messages=all --enable-g"
[0]PETSC ERROR: #1 PetscBinaryRead() line 276 in 
/home/yyy910805/petsc/src/sys/fileio/sysio.c
0.00

Thanks a lot!
Yuyun