[petsc-users] Is it possible to use global variables in Petsc code?

Barry Smith bsmith at mcs.anl.gov
Wed Jul 21 18:41:57 CDT 2010



   Since a PETSc C program is just C, you can, of course, use global variables like you can in any C program.

   We recommend against programming in this way.; any good book on programming should explain why it is a bad idea from the point of view of program maintainability and extensibility.  Given that 99+% of PETSc program run time is taken inside long running routines like matrix and vector operations the overhead of function calls like DAGetInfo() is so small that it is going to be un-measurable, you are trading a more understandable, maintainable and extensible program for a microscopic improvement in run time.

   Barry


On Jul 21, 2010, at 6:19 PM, Li, Zhisong (lizs) wrote:

>  Hi, Petsc Team,
> 
> I wonder if we can utilize a global variable when using PETSc, such as a declaration and definition in the main function:
> 
> extern PetscScalar x, y, z;
>     x = 1.0;
> 
> This should be a regular usage in ANSI C and will help a lot when we have user-defined functions. If it can work, then it will easily replace those functions like DAGetInfo( ) and save running time. But I don't see any examples of using this in PETSc before. And I've tried this but it doesn't work or cannot pass the compiling check.
> 
> 
> Thank you.
> 
> 
> Zhisong Li

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20100721/112b1d85/attachment.htm>


More information about the petsc-users mailing list