Skip to content

Remove unused variables, fix compiler warnings, and standardize constants for -pedantic builds#626

Merged
johanneshofmann87 merged 17 commits into
masterfrom
625-pedantic-compiler-warnings
Jun 3, 2026
Merged

Remove unused variables, fix compiler warnings, and standardize constants for -pedantic builds#626
johanneshofmann87 merged 17 commits into
masterfrom
625-pedantic-compiler-warnings

Conversation

@johanneshofmann87

@johanneshofmann87 johanneshofmann87 commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Using the -pedantic and -Wunused-variable flags, various compiler warnings were cleaned up across the codebase.

Unused variables and imports:

  • Removed unused local variables across 30+ Fortran modules and programs.
  • Moved MPI/HDF5-only locals (e.g., ierr, loop indices) behind #ifdef _MPI / #ifdef _HDF5 preprocessor guards to avoid warnings in non-MPI/HDF5 builds.
  • Removed unused imports of pi from Natural_Constants in files where only twopi is actually referenced.

Standardized mathematical and numerical constants:

  • Extended the Natural_Constants module with pi = acos(-1.d0), twopi, Eps_machine = 1.D-12, Eps_small = 1.D-10, and Eps_convergence = 1.D-6 as a single source of truth.
  • Replaced all local hardcoded definitions of pi and small tolerance values (e.g., 1.D-10, 1.D-8) across the codebase with imports from Natural_Constants.

Other fixes:

  • Changed INTENT(IN), target to INTENT(INOUT), target for dummy arguments whose addresses are stored in pointers in observables_mod and DynamicMatrixArray_mod, as required by flang. Added inline comments and updated Doxygen @param tags explaining the rationale.
  • Fixed spelling in udv_state_mod.F90 warning message: "smalles" → "smallest representable value".

The libqrref files with non-standard complex*16 declarations were intentionally left unchanged.

@johanneshofmann87 johanneshofmann87 linked an issue Apr 1, 2026 that may be closed by this pull request

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses compiler warnings (notably when building with -pedantic) by cleaning up unused/conditionally-used locals and tightening some constant declarations.

Changes:

  • Removes unused local variables across multiple Fortran modules/programs.
  • Moves MPI/HDF5-only locals (e.g., ierr, loop indices) behind preprocessor guards to avoid unused-variable warnings in non-MPI/HDF5 builds.
  • Converts some literal “constants” to parameter and standardizes a few numeric literals (e.g., 0.011.d-2), plus minor formatting tweaks.

Reviewed changes

Copilot reviewed 30 out of 30 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Prog/Wrapgr_mod.F90 Removes unused locals in update/sort routines.
Prog/WaveFunction_mod.F90 Drops unused overlap routine locals.
Prog/upgrade_mod.F90 Removes unused tmp_r local.
Prog/udv_state_mod.F90 Eliminates unused dummy variable; adjusts huge/tiny kind usage; warning message touched region.
Prog/tau_p_mod.F90 Removes unused locals from projector tau routine.
Prog/tau_m_mod.F90 Removes unused locals from finite-T tau routine.
Prog/Set_random_mod.F90 Makes loop index MPI-only to avoid unused warnings without MPI.
Prog/Predefined_Trial_mod.F90 Removes unused locals; standardizes small numeric literals; makes Test a parameter.
Prog/Predefined_Obs_mod.F90 Cleans up unused locals; makes small constant a parameter.
Prog/Predefined_Hop_mod.F90 Cleans up unused locals; converts Zero/Test to parameters in several routines.
Prog/Operator_mod.F90 Makes Zero a parameter; guards ierr declaration with #ifdef MPI.
Prog/observables_mod.F90 Cleans up unused locals; changes lattice/unit-cell dummy intents; removes unused locals in print routines.
Prog/main.F90 Guards HDF5/MPI-only locals (file_dat, Ierr) to avoid unused warnings.
Prog/Langevin_HMC_mod.F90 Removes unused locals from force routine.
Prog/Hamiltonians/LRC_mod.F90 Removes unused locals; makes a test flag a parameter.
Prog/Hamiltonian_main_mod.F90 Removes unused locals from Get_Delta_S0_global_base.
Prog/Global_mod.F90 Removes unused locals in global update/ratio routines.
Prog/Fields_mod.F90 Guards MPI-only locals; removes unused filename variable(s).
Prog/DynamicMatrixArray_mod.F90 Changes dummy intent for stored target object in pushback.
Prog/cgr1_mod.F90 Guards DLJ declaration behind stabilization macros.
Libraries/Modules/mpi_shared_mem_mod_v2.F90 Moves MPI-only locals under #ifdef MPI in deallocation routine.
Libraries/Modules/maxent_stoch_mod.F90 Standardizes small numeric literals; makes Test a parameter; removes unused locals.
Libraries/Modules/entanglement_mod.F90 Reorganizes First_call and MPI-guarded declarations to reduce warnings.
Libraries/Modules/alf_hdf5_mod.F90 Adds a non-HDF5 stub module under #else and fixes module end formatting.
configure.sh Adds an example dev-flag line using -pedantic (commented).
Analysis/maxent_wrapper_mod.F90 Replaces low-precision pi literal; makes Test a parameter; makes Zero a parameter; minor cleanup.
Analysis/Max_SAC.F90 Removes unused locals; makes Test a parameter.
Analysis/cov_tau.F90 Removes unused local; makes Zero a parameter.
Analysis/cov_eq.F90 Removes unused locals and allocations; updates related declarations.
Analysis/ana_mod.F90 Removes unused locals in analysis routines.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Prog/observables_mod.F90
Comment thread Prog/DynamicMatrixArray_mod.F90
Comment thread Prog/udv_state_mod.F90 Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 30 out of 30 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Prog/observables_mod.F90
…les_mod and DynamicMatrixArray_mod

Agent-Logs-Url: https://github.com/ALF-QMC/ALF/sessions/299b5004-ab69-41e9-8c94-0780b75987db

Co-authored-by: johanneshofmann87 <129625831+johanneshofmann87@users.noreply.github.com>
Comment thread Analysis/maxent_wrapper_mod.F90 Outdated
jonasschwab and others added 4 commits April 3, 2026 15:48
… Libraries/Modules/mpi_shared_mem_mod_v2.F90
- Replaced hardcoded small values (e.g., 1.D-10, 1.D-8) with Eps_small for better numerical stability across multiple modules including alf_hdf5_mod, fourier_mod, lattices_v3_mod, maxent_mod, and Hamiltonian modules.
- Updated calculations involving pi to use twopi for consistency and clarity.
- Removed redundant definitions of pi in various modules, ensuring a single source of truth for mathematical constants.
- Enhanced convergence checks in maxent_mod to utilize Eps_convergence for improved iterative processes.
- Ensured all modules that require these constants now import them from the Natural_Constants module.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 49 out of 49 changed files in this pull request and generated 8 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Libraries/Modules/random_wrap_mod.F90 Outdated
Comment thread Libraries/Modules/lattices_v3_mod.F90 Outdated
Comment thread Prog/Predefined_Hop_mod.F90 Outdated
Comment thread Libraries/Modules/maxent_stoch_mod.F90 Outdated
Comment thread Analysis/cov_eq.F90 Outdated
Comment thread Prog/Hamiltonians/Not_supported/Hamiltonian_KN_Kondo_chain.F90 Outdated
Comment thread Prog/Hamiltonians/Not_supported/Hamiltonian_Hub_Canonical_mod.F90 Outdated
Comment thread Libraries/Modules/natural_constants_mod.F90
@johanneshofmann87

Copy link
Copy Markdown
Contributor Author

@copilot apply changes based on the comments in this thread

Agent-Logs-Url: https://github.com/ALF-QMC/ALF/sessions/215b5272-2f97-4b91-8bb8-3a19478fd5bf

Co-authored-by: johanneshofmann87 <129625831+johanneshofmann87@users.noreply.github.com>

Copilot AI commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

@copilot apply changes based on the comments in this thread

Done in commit 81e7e68. Removed unused pi imports from all 7 files flagged in the review:

  • random_wrap_mod.F90: pi removed, kept twopi
  • lattices_v3_mod.F90: pi removed, kept twopi, Eps_small
  • Predefined_Hop_mod.F90: pi removed, kept twopi, Eps_small
  • maxent_stoch_mod.F90: entire Use Natural_Constants, only: pi removed (pi only in commented-out code)
  • cov_eq.F90: entire Use Natural_Constants, only: pi removed (pi only in commented-out code)
  • Hamiltonian_KN_Kondo_chain.F90: pi removed, kept twopi
  • Hamiltonian_Hub_Canonical_mod.F90: pi removed, kept twopi

@johanneshofmann87

Copy link
Copy Markdown
Contributor Author

@copilot update the description of this PR to reflect the actual changes implemented here.

Copilot AI commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

@copilot update the description of this PR to reflect the actual changes implemented here.

Updated the PR description to reflect all the changes implemented in this PR, including: unused variable removals, preprocessor-guarded MPI/HDF5 locals, the Natural_Constants module extensions, replacement of hardcoded pi/tolerance values, removal of unused pi imports, and the INTENT(INOUT) changes with rationale comments.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh gh pr list --repo ALF-QMC/ALF 20&#39; --output-dircredential.helper (http block)
  • https://api.github.com/repos/ALF-QMC/ALF/pulls/626
    • Triggering command: /usr/bin/gh gh api repos/ALF-QMC/ALF/pulls/626 --method PATCH --field body=This PR addresses compiler warnings triggered by the -pedantic` flag across the codebase. The following changes were made:

Removed unused variables and cleaned up declarations:

  • Removed unused local variables across 30+ Fortran modules and pro` (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title removing unused variables and take care of other warnings triggered b… Remove unused variables, fix compiler warnings, and standardize constants for -pedantic builds Apr 7, 2026

@fassaad fassaad left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many changes here, so it would be nice to run as extensive tests as possible.

fassaad
fassaad previously approved these changes Apr 29, 2026
@jonasschwab

Copy link
Copy Markdown
Member

I updated the GNU DEVEL config to compile with -pedantic and -Werror (except for libqrref and entanglement_mod) to avoid regressions from the cleanup.

jonasschwab
jonasschwab previously approved these changes May 5, 2026
@johanneshofmann87

Copy link
Copy Markdown
Contributor Author

@jonasschwab looks like the pgi illegal instructions are back. I only merged with the master to be up-to-date with the base branch...

@jonasschwab

Copy link
Copy Markdown
Member

@jonasschwab looks like the pgi illegal instructions are back. I only merged with the master to be up-to-date with the base branch...

Hm, it's very hard to debug if you can't control on which hardware it runs.

@jonasschwab

Copy link
Copy Markdown
Member

@jonasschwab looks like the pgi illegal instructions are back. I only merged with the master to be up-to-date with the base branch...

The temporary "fix" that works is to re-build the container images (https://github.com/ALF-QMC/alf-container/actions/workflows/docker-build.yml) and hope that the jobs are picked up by runners wit less "capable" CPUs. I did that now and it worked.

@jonasschwab

Copy link
Copy Markdown
Member

Another issue I discovered with test branch: The merge seems to cause significant deviations in the HMC test between master and 625-pedantic-compiler-warnings. We should probably understand these before merging.

Diff on the info files:

$ diff info ../HMC_2/info
34,35c34,35
<  This executable represents commit 3cf85744 of branch 625-pedantic-compiler-warnings.
<   Precision Green  Mean, Max :    2.1781835104644534E-012   2.1878281936116295E-008
---
>  This executable represents commit 3af8e24d of branch master.
>   Precision Green  Mean, Max :    2.0961688165950195E-012   2.8268690221988635E-008
37c37
<   Precision tau    Mean, Max :    4.6370733801731285E-013   1.4929013789077850E-009
---
>   Precision tau    Mean, Max :    5.5154004554221879E-013   2.3485319522453807E-009

Diff on scalar analysis results:

➜  for i in *_scalJ; echo "====== $i =====" && diff $i ../HMC_2/$i
====== Ener_scalJ =====
3c3
<           1 -0.29046023016509910E+001  0.44922555695566906E-001
---
>           1 -0.29132328451038401E+001  0.49448850613298366E-001
====== Kin_scalJ =====
3c3
<           1 -0.50216793578962484E+001  0.83763417025652598E-001
---
>           1 -0.50262407683416050E+001  0.88586516612627550E-001
====== Part_scalJ =====
====== Pot_scalJ =====
3c3
<           1  0.21170770562452557E+001  0.65919629684849157E-001
---
>           1  0.21130079232377659E+001  0.61468578186389795E-001

Parameter file:

&VAR_ham_name
ham_name = "Hubbard"  ! Name of Hamiltonian
/

&VAR_lattice
Model = "Hubbard"  ! Value not relevant
Lattice_type = "N_leg_ladder"  ! 
L1 = 1  ! Length in direction a_1
L2 = 6  ! Length in direction a_2
/

&VAR_Model_Generic
N_SUN = 2  ! Number of colors
N_FL = 1  ! Number of flavors
Phi_X = 0.0d0  ! Twist along the L_1 direction, in units of the flux quanta
Phi_Y = 0.0d0  ! Twist along the L_2 direction, in units of the flux quanta
Bulk = .T.  ! Twist as a vector potential (.T.), or at the boundary (.F.)
N_Phi = 0  ! Total number of flux quanta traversing the lattice
Dtau = 0.1d0  ! Thereby Ltrot=Beta/dtau
Beta = 4.0d0  ! Inverse temperature
Checkerboard = .T.  ! Whether checkerboard decomposition is used
Symm = .T.  ! Whether symmetrization takes place
Projector = .F.  ! Whether the projective algorithm is used
Theta = 10.0d0  ! Projection parameter
/

&VAR_Hubbard
ham_T = 1.0d0  ! Hopping parameter
Ham_chem = 0.0d0  ! Chemical potential
Ham_U = 4.0d0  ! Hubbard interaction
ham_T2 = 1.0d0  ! For bilayer systems
Ham_U2 = 4.0d0  ! For bilayer systems
ham_Tperp = 1.0d0  ! For bilayer systems
ham_h0 = 0.0d0  ! Pinning field strength. Local magnetic field on site i=0, orbital=1
Mz = .T.  ! When true, sets the M_z-Hubbard model: Nf=2, demands that N_sun is even, HS field couples to the z-component of magnetization; otherwise, HS field couples to the density
Continuous = .T.  ! Uses (T: continuous; F: discrete) HS transformation
/

&VAR_QMC
CPU_MAX = 0.0d0  ! Code stops after CPU_MAX hours, if 0 or not specified, the code stops after Nbin bins
Delta_t_Langevin_HMC = 0.1d0  ! Time step for Langevin or HMC
Global_moves = .F.  ! Allows for global moves in space and time.
Global_tau_moves = .F.  ! Allows for global moves on a single time slice.
HMC = .T.  ! HMC update
LOBS_EN = 0  ! End measurements at time slice LOBS_EN
LOBS_ST = 0  ! Start measurements at time slice LOBS_ST
sequential = .F.  ! Conventional updating scheme
Langevin = .F.  ! Langevin update
Leapfrog_steps = 50  ! Number of leapfrog iterations
N_HMC_sweeps = 1  ! Number of HMC sweeps
Amplitude = 1.0d0  ! Width of the box distribution for update of type t=3,4 fields.  Defaults  to 1.0.
Ltau = 1  ! 1 to calculate time-displaced Green functions; 0 otherwise.
Max_Force = 5.0d0  ! Max Force for Langevin
N_global = 1  ! Number of global moves per sweep.
N_global_tau = 1  ! Number of global moves that will be carried out on a single time slice.
Nbin = 5  ! Number of bins.
Nsweep = 20  ! Number of sweeps per bin.
Nt_sequential_end = -1  ! 
Nt_sequential_start = 0  ! 
Nwrap = 10  ! Stabilization. Green functions will be computed from scratch after each time interval Nwrap*Dtau.
Propose_S0 = .F.  ! Proposes single spin flip moves with probability exp(-S0).
/

@johanneshofmann87

Copy link
Copy Markdown
Contributor Author

Another issue I discovered with test branch: The merge seems to cause significant deviations in the HMC test between master and 625-pedantic-compiler-warnings. We should probably understand these before merging.

Diff on the info files:

$ diff info ../HMC_2/info
34,35c34,35
<  This executable represents commit 3cf85744 of branch 625-pedantic-compiler-warnings.
<   Precision Green  Mean, Max :    2.1781835104644534E-012   2.1878281936116295E-008
---
>  This executable represents commit 3af8e24d of branch master.
>   Precision Green  Mean, Max :    2.0961688165950195E-012   2.8268690221988635E-008
37c37
<   Precision tau    Mean, Max :    4.6370733801731285E-013   1.4929013789077850E-009
---
>   Precision tau    Mean, Max :    5.5154004554221879E-013   2.3485319522453807E-009

Diff on scalar analysis results:

➜  for i in *_scalJ; echo "====== $i =====" && diff $i ../HMC_2/$i
====== Ener_scalJ =====
3c3
<           1 -0.29046023016509910E+001  0.44922555695566906E-001
---
>           1 -0.29132328451038401E+001  0.49448850613298366E-001
====== Kin_scalJ =====
3c3
<           1 -0.50216793578962484E+001  0.83763417025652598E-001
---
>           1 -0.50262407683416050E+001  0.88586516612627550E-001
====== Part_scalJ =====
====== Pot_scalJ =====
3c3
<           1  0.21170770562452557E+001  0.65919629684849157E-001
---
>           1  0.21130079232377659E+001  0.61468578186389795E-001

Parameter file:

&VAR_ham_name
ham_name = "Hubbard"  ! Name of Hamiltonian
/

&VAR_lattice
Model = "Hubbard"  ! Value not relevant
Lattice_type = "N_leg_ladder"  ! 
L1 = 1  ! Length in direction a_1
L2 = 6  ! Length in direction a_2
/

&VAR_Model_Generic
N_SUN = 2  ! Number of colors
N_FL = 1  ! Number of flavors
Phi_X = 0.0d0  ! Twist along the L_1 direction, in units of the flux quanta
Phi_Y = 0.0d0  ! Twist along the L_2 direction, in units of the flux quanta
Bulk = .T.  ! Twist as a vector potential (.T.), or at the boundary (.F.)
N_Phi = 0  ! Total number of flux quanta traversing the lattice
Dtau = 0.1d0  ! Thereby Ltrot=Beta/dtau
Beta = 4.0d0  ! Inverse temperature
Checkerboard = .T.  ! Whether checkerboard decomposition is used
Symm = .T.  ! Whether symmetrization takes place
Projector = .F.  ! Whether the projective algorithm is used
Theta = 10.0d0  ! Projection parameter
/

&VAR_Hubbard
ham_T = 1.0d0  ! Hopping parameter
Ham_chem = 0.0d0  ! Chemical potential
Ham_U = 4.0d0  ! Hubbard interaction
ham_T2 = 1.0d0  ! For bilayer systems
Ham_U2 = 4.0d0  ! For bilayer systems
ham_Tperp = 1.0d0  ! For bilayer systems
ham_h0 = 0.0d0  ! Pinning field strength. Local magnetic field on site i=0, orbital=1
Mz = .T.  ! When true, sets the M_z-Hubbard model: Nf=2, demands that N_sun is even, HS field couples to the z-component of magnetization; otherwise, HS field couples to the density
Continuous = .T.  ! Uses (T: continuous; F: discrete) HS transformation
/

&VAR_QMC
CPU_MAX = 0.0d0  ! Code stops after CPU_MAX hours, if 0 or not specified, the code stops after Nbin bins
Delta_t_Langevin_HMC = 0.1d0  ! Time step for Langevin or HMC
Global_moves = .F.  ! Allows for global moves in space and time.
Global_tau_moves = .F.  ! Allows for global moves on a single time slice.
HMC = .T.  ! HMC update
LOBS_EN = 0  ! End measurements at time slice LOBS_EN
LOBS_ST = 0  ! Start measurements at time slice LOBS_ST
sequential = .F.  ! Conventional updating scheme
Langevin = .F.  ! Langevin update
Leapfrog_steps = 50  ! Number of leapfrog iterations
N_HMC_sweeps = 1  ! Number of HMC sweeps
Amplitude = 1.0d0  ! Width of the box distribution for update of type t=3,4 fields.  Defaults  to 1.0.
Ltau = 1  ! 1 to calculate time-displaced Green functions; 0 otherwise.
Max_Force = 5.0d0  ! Max Force for Langevin
N_global = 1  ! Number of global moves per sweep.
N_global_tau = 1  ! Number of global moves that will be carried out on a single time slice.
Nbin = 5  ! Number of bins.
Nsweep = 20  ! Number of sweeps per bin.
Nt_sequential_end = -1  ! 
Nt_sequential_start = 0  ! 
Nwrap = 10  ! Stabilization. Green functions will be computed from scratch after each time interval Nwrap*Dtau.
Propose_S0 = .F.  ! Proposes single spin flip moves with probability exp(-S0).
/

I noticed that as well and agree that we should identify where this is coming from. @jonasschwab

Comment thread Libraries/Modules/random_wrap_mod.F90
@johanneshofmann87 johanneshofmann87 requested a review from fassaad May 20, 2026 15:43
fassaad
fassaad previously approved these changes Jun 3, 2026

@fassaad fassaad left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot go through all the changes. As far as I recall Jonas or Johannes did some extensive automatic checks, and all seemed to work out. There was one exception, but the issue was the art coding of pi=3.1415927 instead of pi = acos(-1.d0) when drawing normal distributed random numbers. Is my recollection correct? If so we can merge.

@johanneshofmann87

Copy link
Copy Markdown
Contributor Author

@fassaad @jonasschwab I fixed the merge conflicts, the pipeline is running but should pass now, and auto-merge is enabled. Can one of you quickly approve the merge, please?

@johanneshofmann87 johanneshofmann87 merged commit fd52897 into master Jun 3, 2026
25 checks passed
@johanneshofmann87 johanneshofmann87 deleted the 625-pedantic-compiler-warnings branch June 3, 2026 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pedantic compiler warnings

5 participants