Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

How to have multiple definitions of a subroutine in Intel Fortran

Ahmed_A_2
Beginner
6,203 Views


How can I use a static library in a Intel Fortran Project and at the same time, include some of the library subroutines in other parts of the project with some changes? In other words, in the case that I have two definitions of the same subroutine, How can I ask the program to use the subroutine that is included in the project rather than the same subroutine in the library?

0 Kudos
36 Replies
Ahmed_A_2
Beginner
2,857 Views
Hi Mr. Lionel and Mr Dempsey many Thanks for your help .Actually, to separate between the subroutine and the its call statement in the library(put them in different sources when we create the library) will be impossible in case of big library that we have . So could you please do that by setting the linking properties of the project , which will be more convenient and easy . Many thanks Ahmed Khalil
0 Kudos
Steven_L_Intel1
Employee
2,857 Views
Sorry, Ahmed, there's no way to do that.
0 Kudos
Liang_W_
Beginner
2,857 Views
Hi, I would appreciate that if you could send us an example of this. Actually, I am still not quite clear about the steps. Thanks.

Why won't this work?
1) Put the subroutine ADD that you really want to invoke in a module.
2) USE the module in the program unit where you really want to invoke it.
3) Give the subroutine a different linker name with !DEC$ ATTRIBUTES ALIAS
Even step 3 above seems unnecessary because a module procedure already has a different linker name.
If the module won't be available at the time the prospective caller is compiled, you could still write out an interface block with a different linker name as specified in 3 above. I don't think you are reduced to LoadLibrary/GetProcAddress/C_F_PROCPOINTER to get this to work.

0 Kudos
Ahmed_A_2
Beginner
2,857 Views
Hi Mr. Dempsey I have tired your method with the simple project we have here and it works fine but with our project that has very big library it does not work it gives me some error, are there any conditions this way will work only or it can work with any project. Many Thanks Ahmed
0 Kudos
Ahmed_A_2
Beginner
2,857 Views
Hi Mr. Lionel But power station was allowing that option( forcing the user subroutines) very easy without the need to separate between the subroutines and its calls(to be in two sources to while creating the library), there no option in Intel Fortran to do the same. Actually this option is very fundamental in our work and we are trying now to convert from power station to Intel Fortran. Could I know please your suggestions. your reply will be appreciated Many thanks
0 Kudos
JVanB
Valued Contributor II
2,857 Views
I compiled the 3 included files as: ifort add.for source1.for sub.for Output was: CALLED HERE ADD NEW 50.0000000000000 2 5 50.0000000000000 THIS IS THE MAIN
0 Kudos
jimdempseyatthecove
Honored Contributor III
2,857 Views

Ahmed A. wrote:

Hi Mr. Dempsey
I have tired your method with the simple project we have here and it works fine but with our project that has very big library it does not work it gives me some error, are there any conditions this way will work only or it can work with any project.
Many Thanks
Ahmed

What is the error message? Is it compiler or linker error message? You have a working simple example, what design changes exist between the simple example and the full library? Jim Dempsey

0 Kudos
Ahmed_A_2
Beginner
2,857 Views
Hi Mr. Dempsey This is the error I just got when I applied to anther project , I made sure that every thing is The same as I did in the simple project the subroutine that I would like to replace is SPLNDT while the errors I got are Error 2 Compilation Aborted (code 1) Error 1 error #6401: The attributes of this name conflict with those made accessible by a USE statement. [SPLNDT] Do I have to include all the arguements and the dimensions and the common blocks associated with each subroutine in the new substitution module Many Thanks Ahmed
0 Kudos
Liang_W_
Beginner
2,857 Views
Hi, thanks very much for your answer. That means I have to create a library that containing the module. How could I leave the 'USE ADDMOD' in the source1.txt and then create the library. So that I could modify other subroutines in the same way.

I compiled the 3 included files as:
ifort add.for source1.for sub.for
Output was:
CALLED HERE ADD NEW 50.0000000000000
2 5 50.0000000000000
THIS IS THE MAIN

0 Kudos
Ahmed_A_2
Beginner
2,857 Views
Hi Mr. Lionel I would like to hear you suggestion about this problem this is essential problem we have , does any upgrading versions for inlet fortran will be helpful to simplify this, and also I'm facing a problem in the size of the debugging that intel fortran created compared to the one i had from power ststion , I'm wondering if there is any configurations that we can change to reduce the size of the library as we can. Your reply will be appreciated Many Thanks Ahmed
0 Kudos
jimdempseyatthecove
Honored Contributor III
2,857 Views
>>Error 1 error #6401: The attributes of this name conflict with those made accessible by a USE statement. [SPLNDT] >>Do I have to include all the arguements and the dimensions and the common blocks associated with each subroutine in the new substitution module Only the calling arguments (and calling conventions if present) must be declared. Your error is likely one of two a) The module with the interface for SPLNDT has an interface that is not the same as the subroutine SPLNDT and SPLNDE is USE-ing this module. (Keep USEing the module but fix your interface) b) You have multiple USE module with declaration of interface for SPLNDT. Assuming one of these is the USE for your general subroutines, e.g. ADD SUB, MUL, DIV and assume you wish to replace ADD USE YourReplacements ! with ADD USE YourLibrary, ONLY : SUB, MUL, DIV Or try USE YourReplacements ! with ADD USE YourLibrary, ADDdontUse = ADD Jim Dempsey
0 Kudos
jimdempseyatthecove
Honored Contributor III
2,857 Views
*** ADDdontUse *EqualSign*GreaterThanSign* ADD
0 Kudos
Steven_L_Intel1
Employee
2,857 Views
Ahmed, I don't know of any reasons why the library should be significantly larger. Please show me the compiler options you are using - in Visual Studio these can be found under the project property Fortran > Command Line.
0 Kudos
Ahmed_A_2
Beginner
2,857 Views
Hi Mr. Lionel I would like to hear your suggestion about the linking problem ,this is essential problem we have , and actually the two suggested ways can not be applied in general case, where to separate between the subroutine and its calls is impossible for us otherwise we have to put each subroutine in a source file when we create the library, and the second method that Mr. Dempsey suggested , is also not practical for us as the user will not be able to change the module we have in the library , so we have to repeat that for each subroutine and this not convenient. does any upgrading versions for inlet fortran will be helpful to simplify this, or what do you recommend us to do in this case. As I told you we are converting from power station to Intel fortran. Many Thanks Ahmed
0 Kudos
Ahmed_A_2
Beginner
2,857 Views
Hi "One possible difference is that the Intel compiler does automatic inlining of procedures in the same source file - this would probably explain the difference." As this problem come from the Intel fortran automatic inlining , there is any way to disable or enable this automatic inlining or any other options that we can control the inlining. Many Thanks Ahmed Khalil
0 Kudos
Liang_W_
Beginner
2,857 Views
Hi, I think we could solve another problem instead to implement the same function. For example, we have a 'A.lib' file and this file contains "subroutine ADD", as we could not get access to the library or it is not easy to modify this library. Shall we build another static library with this "A.lib" file and "Source2.for" in which there is a subroutine called subroutine ADD. How can we replace the one in the library using the new one through some specific settings? Thanks,Liang
0 Kudos
Reply