Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Module use diagnostics

acar
Beginner
1,448 Views
Hi, the application that I am developing has grown over a number of years and my programming has improved with time. I have many modules in my application many of which are simply declarations and contain no routines or functions. In the process of tidying my code I would like to remove USE statements where applicable, i.e. where the declarations in the module are not used in the routine. To do this I could look at each routine, comment out a USE statement and then see if it compiles - removing it if it does and retaining it if it does not compile. As I have some 5000 routines this will take me some considerable time to perform. I wonder whether, like in the Fortran=>Diagnostics of the project properties page, there is an option/switch somewhere to warn the user if a routine is using a module that is not required?
Thanks,
Angus.
0 Kudos
1 Solution
Steven_L_Intel1
Employee
1,448 Views
Sorry, there is not a diagnostic like that.

View solution in original post

0 Kudos
7 Replies
Steven_L_Intel1
Employee
1,449 Views
Sorry, there is not a diagnostic like that.
0 Kudos
anthonyrichards
New Contributor III
1,448 Views
I think if you declare a variable in a module and USE it in a routine where you also declare the variable, you will get a compilation error message that the declaration clashes with one in a USE statement.

On the other hand, if you always declare IMPLICIT NONE in your routines and remove a USE statement for a module from the routine, on compilation you will get warnings about all the variables that are now not declared that were previously declared in the module.
0 Kudos
acar
Beginner
1,448 Views
That's correct, I use IMPLICIT NONE always and then hunt for unused modules by commenting out and recompiling. But it is a time consuming task to perform manually and I was hoping there might be a facility within the compiler to map module usage. However, Steve thinks not so I shall revert to manual.
Thanks,
ACAR.
0 Kudos
anthonyrichards
New Contributor III
1,448 Views
How many modules are you talking about?
What about taking a module, creating a copy, renaming and saving the original under a temporary name then edit the copy to be empty. Delete the original module from your project and add the edited empty copy to the project. Compile and USE this empty module. Then, compile the routines and where you actually need the module, using the empty module will give you (alot of) diagnostics?
0 Kudos
IanH
Honored Contributor III
1,448 Views
One of the free fortran compilers at least (g95) has some capability in this area (I know it can warn at least about symbols from modules that are USE'd but not used, I'm not so sure about the modules themselves). If your codes are f95 only you may be able to use it in parallel with ifort. For some projects I maintain a build system that allows changing the compiler primarily for the opportunity to see different diagnostics and checks.
0 Kudos
acar
Beginner
1,448 Views
A good suggestion but it is all a little manual. I was hoping for an automated approach to module management from Intel. This seems unavailable at this time so I shall probably resort to a method like this or, depending on available time, I shall ignore and assume/hope that USEing modules within a routine from which no variables are actually used does not incur any overhead. Thanks for your suggestion anthonyrichards.
0 Kudos
acar
Beginner
1,448 Views
That is a good idea IanH. My code is f95 and so I might give this a try. Thanks, ACAR.
0 Kudos
Reply