0

I have a Fortran project comprising around 100 files. All of them are compiled but not all of them are needed for a run. Also some files contain a mix of used / unused subroutines.

Is there a way to know the minimum set of files / subroutines / functions needed for a run?

Manfredo
  • 1,760
  • 4
  • 25
  • 53
  • 1
    Why are you interested in doing this? Your code will likely not run faster if unused subroutines are eliminated from the program. – Ross Mar 29 '17 at 16:32
  • I am evaluating how much time I will need to translate the code from fortran to c/c++. I want to start with the minimum set of files that I need and only after add the rest. – Manfredo Mar 29 '17 at 16:35

1 Answers1

1

Yes. Start with just the top-level main program.

Compile/Link it and get the list of unsatisfied references.

For each of the unsatisfied references, add the file containing it.

Repeat these two steps until there are no more unsatisfied references.

This removes all files not needed for a clean build. Yes, it is a lot of work. Things are not always easy.

If you want to know what's not needed for a run with particular input, for that you need a coverage tool such as gcov. Routines that are not used will show a coverage count of 0. Then if you really want to get rid of them, extract them into separate source files so you can exclude them, and make sure they are not called.

Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135
  • 1
    Do you know of an alternative that works for code compiled with the intel compilers. Unfortunately I am getting some errors with gfortran that prevent compilation. – Manfredo Mar 29 '17 at 16:36
  • Intel compiler code coverage tool is described at https://software.intel.com/sites/default/files/article/401105/code-coverage.pdf note that they don't mention to what extent it was tested with ifort. – tim18 Mar 29 '17 at 17:51
  • If your starting project is in such bad shape that you don't have it working in gfortran, converting to c++ may be premature. – tim18 Mar 29 '17 at 17:53
  • Moving it to c means more people could work on it. If it worked, then there would be no reason to move it. Unless you are great in c, then I believe you would be enter off concentrating on making it work as is, or using Python. – Holmz Mar 29 '17 at 21:42
  • @Manfredo: Can you compile/link it at all, with Intel or gfortran? If so, can you run it? You have to get to first base. – Mike Dunlavey Mar 30 '17 at 13:01
  • Yes I am able to compile and run properly with intel. I remember that for the very same source code gfortran was throwing me some errors about explicit interfaces but now I don't recall what exactly. If I am to recompile I would need to recompile before the `hdf5` which is really annoying. The only thing I can find for intel is [Vtune](https://software.intel.com/en-us/intel-vtune-amplifier-xe) which does not have the student free version... – Manfredo Mar 30 '17 at 15:07
  • @Manfredo, Vtube is profiling tool, not coverage tool (and Mike always says you need not a profiler to profile programs, but only his random-stop-in-gdb stack sampling from his highest voted answer). There is **`codecov`** for coverage with intel compilers (fortran is supported): https://software.intel.com/en-us/node/522743 https://software.intel.com/sites/products/collateral/hpc/compilers/code_coverage_tool.pdf - "*To determine which code is used, the code coverage tool uses Profile-guided Optimization (PGO) options and optimizations*" – osgx May 03 '17 at 14:12