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

Is there a method to compile just a subroutine?

Animesh_D_
Beginner
1,856 Views

I am using PSE2016 in Windows 10

Is there a method to just compile a subroutine? At present, I have to include a begin program...end program statements for successful compilation as shown below.

program try

end program try
      
SUBROUTINE CREEP(....

I am interested to know if there are any alternatives in VS2015 to simply compile the subroutine without adding the program statements. At present I am selecting a Fortran console project as my option in VS 2015.

The reason, I just need just a subroutine compiled is because it will be linked with another finite element analysis program which will access the compiled subroutine. Per the instructions of the finite element analysis program I need to link the compiled subroutine - I am assuming it means that I need to get the .obj file.

Please pardon my ignorance, as I am new to all this. All your helps and tips will be appreciated.

Regards

Animesh

0 Kudos
1 Solution
mecej4
Honored Contributor III
1,856 Views

Regardless of whether you choose to use the command line or Visual Studio, you need to make it known to the compiler/build system that you wish to stop after the source has been compiled.

In a command line environment, the /c option to the compiler does this. In Visual Studio, right click on the specific source file in the solution explorer, and choose "Compile".

View solution in original post

0 Kudos
8 Replies
Arjen_Markus
Honored Contributor I
1,856 Views

You could use the command-line tools or you could define a library project. If you use a console project, then the compiler will compile the code and then try to make a runnable program out of it (via the linker). You only need the first step, hence you need to instruct Visual Studio to do so - by using the right type of project.

If you open the command tools window, then you could simply do:

ifort /c mysource.f90

(Do remove the program/end program lines)

 

0 Kudos
mecej4
Honored Contributor III
1,857 Views

Regardless of whether you choose to use the command line or Visual Studio, you need to make it known to the compiler/build system that you wish to stop after the source has been compiled.

In a command line environment, the /c option to the compiler does this. In Visual Studio, right click on the specific source file in the solution explorer, and choose "Compile".

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,856 Views

In Visual Studio you will note that you have a Solution .and. you have Project.

What it sounds like you want is a Solution containing two Projects

First Project is a Library Project (either static or DLL) containing the subroutines and functions that you desire to be in your Library.

Second Project is a Console program that uses the library.

In the Solution you then make the Console project as dependent upon the Library Project(s), and you set the Console Project as the startup Project.

You may or may not want more than one library depending on your needs.

You can also have multiple "console" projects, one selected as startup, with each console project performing a different series of tests. Example: Test_Small, Test_Medium, Test_Large, ...

Jim Dempsey

0 Kudos
Animesh_D_
Beginner
1,856 Views

Thank you Arjenmarkus, mecej4 and Jim, for your suggestions and prompt help.

I tried right clicking and choosing compile - by removing the program...end program lines and I had success.

With the command line option I get the following message:

error: can't open file creep.obj for write

My follow on question is, is there a way for me to issue the ifort command from the commnd line window in the folder where my source file is? At present I open the intel 64 command window from the program menu and then have to issue the command.

  Regards

0 Kudos
TimP
Honored Contributor III
1,856 Views
Apparently you don't have privilege to write or replace creep.obj in your current folder. You should compile in a folder where you have full rights.
0 Kudos
mecej4
Honored Contributor III
1,856 Views

The phrase "ifort command from the command line window in the folder" is ambiguous, and I don't understand what the difficulty is related to.

The Ifort command window is opened using a shortcut from the start menu. You can edit the shortcut itself (right click) and change the starting directory, if you wish. Or, after opening the command window, you can change to a different drive/folder using the "chdir" (or "cd") command within the command window.

The "cd" command, by itself without arguments, will display the present device/directory.

If the starting directory happens to be something such as "C:\program files (x86)\intel", you may not have write permissions for that directory, and should change to the directory containing the source file before attempting to compile.

0 Kudos
LRaim
New Contributor I
1,856 Views

About compilation in Visual Studio.

If the source file is included in a fortran project you do not need to have main/program module and build the entire project.

The compile command (ctrl+F7) is available, though a command customization is required to have the command included in the toolbar. So you can compile a single .for, .f90, etc. source file. 

Regards

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,856 Views

When compiling a console program Project you are required to have a source file with PROGRAM in that project either as source or coming in as a dependent .obj or .lib..

You do not need this in a Library Project. But then you cannot run the Library without an accompanying program that uses the library.

One of my Solutions contains 11 Library Projects and 1 Console Project. There are about 750 source files, ~500,000 lies of code. The Libraries are categorized by functionality. Using the multiple libraries cuts down on build time (several can be built at the same time with parallel build). Most of the time I work on a few files and only they get compiled and the Librarian builds only that library, then the Linker links everything together.

Experiment with some simple multi-project solutions. You could start with a Hello World where the write statement is in a subroutine that is in a Library project (only file), and a Console Project containing the PROGRAM and a CALL to the Library. Once you have that working and are comfortable you can start over generating the Console Project and Library Project(s) using meaningful names. Then your remaining "work" is copying the source files (if necessary) to the appropriate folders, then Right-Click on the project of interest in the Solution Explorer | Add | Existing, then locate the file(s) for that project.

Jim Dempsey

0 Kudos
Reply