[petsc-users] Many warning in my code

Barry Smith bsmith at petsc.dev
Tue Jul 16 11:30:21 CDT 2024


   Recent versions of compilers provide a great deal more warnings and errors than older versions for "sloppy" code, such as assigning a variable but then never using it. The compiler doesn't know if you made a mistake like misspelling a variable name or forgetting to use a variable so it prints warnings that previous versions of the compilers did not.

   The best way to proceed is to go through all the warnings and "fix" your code to prevent the warnings from appearing. It is also possible to tell the compiler to not warn you about some of the problems with extra compiler options (for example passing the compiler flag -Wno-unused-but-set-variable) but that is not a good solution, best to fix the code.

  Barry




> On Jul 16, 2024, at 9:54 AM, Ivan Luthfi <ivanluthfi5 at gmail.com> wrote:
> 
> This Message Is From an External Sender
> This message came from outside your organization.
> Hello guys, 
> I am still trying to compile my old multigrid code. But i get so many warning, one of those warning is like this:
> MsFEM_poisson2D_DMDA.c: In function ‘int main(int, char**)’:
> MsFEM_poisson2D_DMDA.c:185:48: warning: variable ‘finest’ set but not used [-Wunused-but-set-variable]
>   185 |                         PetscInt mg_level = 2, finest;
>       |                                                ^~~~~~
> MsFEM_poisson2D_DMDA.c:56:44: warning: variable ‘pi’ set but not used [-Wunused-but-set-variable]
>    56 |         PetscScalar             a,b,c,d,dt,pi;
>       |                                            ^~
> MsFEM_poisson2D_DMDA.c:57:35: warning: variable ‘Lx’ set but not used [-Wunused-but-set-variable]
>    57 |         PetscInt                M,Lx,Ly,Nx,Ny,Mx,My;
>       |                                   ^~
> MsFEM_poisson2D_DMDA.c:57:38: warning: variable ‘Ly’ set but not used [-Wunused-but-set-variable]
>    57 |         PetscInt                M,Lx,Ly,Nx,Ny,Mx,My;
>       |                                      ^~
> MsFEM_poisson2D_DMDA.c:58:33: warning: variable ‘hx’ set but not used [-Wunused-but-set-variable]
>    58 |         PetscScalar             hx,hy,Hx,Hy;
>       |                                 ^~
> MsFEM_poisson2D_DMDA.c:58:36: warning: variable ‘hy’ set but not used [-Wunused-but-set-variable]
>    58 |         PetscScalar             hx,hy,Hx,Hy;
>       |                                    ^~
> MsFEM_poisson2D_DMDA.c:58:39: warning: variable ‘Hx’ set but not used [-Wunused-but-set-variable]
>    58 |         PetscScalar             hx,hy,Hx,Hy;
>       |                                       ^~
> MsFEM_poisson2D_DMDA.c:58:42: warning: variable ‘Hy’ set but not used [-Wunused-but-set-variable]
>    58 |         PetscScalar             hx,hy,Hx,Hy;
>       |                                          ^~
> MsFEM_poisson2D_DMDA.c:60:58: warning: variable ‘Nondimensionalization’ set but not used [-Wunused-but-set-variable]
>    60 |         PetscInt                Compute_finegridsolution,Nondimensionalization;
>       |                                                          ^~~~~~~~~~~~~~~~~~~~~
> MsFEM_poisson2D_DMDA.c:283:54: warning: ‘%d’ directive writing between 1 and 11 bytes into a region of size between 0 and 99
> 
> 
> Can you guys help me to fix or solve this warning in order to get the code run smoothly. Please help  
> 
> 
> -- 
> Best regards,
> 
> Ivan Luthfi Ihwani

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20240716/f168497b/attachment-0001.html>


More information about the petsc-users mailing list