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

Fortran modules

rfvujm
Principiante
801 Visualizações
Hi All,

First of all, sorry for a newbie quiestion on this forum.

1st case, I have two simple fortran modules, A_MOD and B_MOD:

[bash]MODULE A_MOD
USE B_MOD
INTEGER PAR_1
...
IF (PAR_2 .GT. 0) CYCLE
...[/bash]
[bash]MODULE B_MOD
USE A_MOD
INTEGER PAR_2
...
IF (PAR_1 .GT. 0) CYCLE
...[/bash]

2nd case, similar three modules, A_MOD, B_MOD and C_MOD:
- A uses B
- B uses C
- C uses A

In any of such combinations, how do I compile the program? To compile A, I need B to be compiled, which needs A. Heard about some vague solution, where:
- in A you comment lines 2 and 5
- compile A
- compile B
- uncomment A
- delete all/some .obj and/or .mod files (???)
- recompile (what?)

Tried, no success, as I do not understand it.

Any hint would be very appreciated. :)

Regards,
Mario
0 Kudos
3 Respostas
Steven_L_Intel1
Funcionário
801 Visualizações
Well, this is interesting - a post written by no username. Hmm.

The short answer is "don't do that" - a circular module dependency is not legal Fortran and will, as you note, cause problems when you try to build. If A and B are really that related, put them in the same module. Otherwise, perhaps moving some common items to a third module C will break the mutual dependency.
jimdempseyatthecove
Colaborador honorário III
801 Visualizações
Mario,

As Steve recommends seperate the data such that you have no circular dependencies.

MODULE A_MOD_DATA
INTEGER PAR_1
...
------------------------
MODULE B_MOD_DATA
INTEGER PAR_2
...
----------------------
MODULE A_MOD_CODE
USE B_MOD_DATA
...
IF(PAR_1 .GT. 0) CYCLE
...
------------------------
MODULE B_MOD_CODE
USE A_MOD_DATA
...
IF(PAR_2 .GT. 0) CYCLE
...


This doesn't fix situations were you are co-dependent on subroutines and/or functions, but this can be fix using INTERFACE blocks.

Jim Dempsey
rfvujm
Principiante
801 Visualizações
Steve, Jim,

Thanks for very quick replies. I'm recompiling large, someone elses program and to be honest - have no time to refactor too much of it. My predecessor used to compile it by this 'illegal' operation of commenting and deleting. I was curious maybe someone else knows this hack. Anyway, thanks again for your repies.

P.S. Don't know why my username did not appear, I was logged in...
Responder