Intel® Inspector XE correctness and security checking support analysis of programs written in the C/C++, C#, and Fortran languages. This is the first article in a three part series covering how to use Intel Inspector XE on Fortran applications. This article will cover using Intel Inspector XE memory analysis on a sample Fortran application. Part 2 and part 3 will cover how to use threading analysis and static security analysis on Fortran.
Once you have a debug configuration (optimization off and debug information included) successfully compiled, the next step is to create an Intel Inspector XE project as seen in the figure below. If you are using Microsoft* Visual Studio, this step is omitted because Intel Inspector XE will use the current Visual Studio project.
When creating a new project, modify the project properties in Intel Inspector XE to record the location of the application to launch (in this case "nqueens_memory_debug"), the application parameters, and working directory.
The two figures above are screenshots from the Linux GUI to demonstrate the additional steps required if not using Visual Studio. From here on, this article will use screenshots from the Visual Studio integration of Intel Inspector XE, but the standalone GUI looks very similar. To run a memory analysis on your application, create a "New Analysis", select an Analysis Type and click "Start", as shown in the following figure. There the "Detect Memory Problems" Analysis Type is selected. Intel Inspector XE also has the predefined Analysis Types "Detect Leaks" and "Locate Memory Problems." Each of these has trade-offs with respect to overhead, problems detected, and level of detail. The Details region of the Analysis Type window gives in-depth information about each analysis type. New analysis types can also be created and configured. All of the analysis type details are documented in the Intel Inspector XE help.
Intel Inspector XE will launch the application and monitor it to detect memory issues. Once the application completes, the detected issues are presented in the analysis summary.
In this example, Intel Inspector XE detected one "Uninitialized memory access" and one "Memory leak" problem in this application. The Code Locations pane shows source code snippets related to the selected problem. In the figure above the allocation site of the memory leak is highlighted. Double-clicking on any of these problems will open the Sources view with complete source code information and call stack data shown in the figure below.
From this view, double click on any source line to open the code editor and modify the source file. To fix this particular problem, the following matching deallocation needs to be added.
The second problem reported in the analysis summary is an uninitialized memory access. This means that a variable is being read before it is written for the first time. The Sources view for this issue shows the allocation of the variable "queens" and the first read.
In order to fix this issue, the variable should be initialized before any reads. Adding an initialization line will fix this issue.
Once you have made corrections to fix the issues, rebuild your application and run the analysis again. If all of the issues are fixed, you should see a result similar to the figure below.
Using Intel Inspector XE on Fortran applications is straightforward and increases your confidence in the correctness and security of an application.