Showing results for 
Search instead for 
Did you mean: 

Migrate Fortran code from Linux to Visual Studio

I have a parallel Fortran code I would like to run on the Windows system right now. The codes have a bunch of conditional compilation such as


#ifdef LOOSE


The following is the Makefile I got.

main_lc: modules.o ...(all the object files) \ 
mpif90 -o main.exe \
modules.o ...(all the object files)


modules.o: modules.f
mpif90 -DLOOSE -DPARALLEL -c   modules.f

...(all other object files )
After I got main.exe
then type following command to run the program
mpiexec -np 4 ./main.exe <input.inp> output
I was wondering if there is any way that I can make it compiler and run in Visual Studio?



0 Kudos
2 Replies
New Contributor III

In general, I'd say that you

In general, I'd say that you would open Visual Studio, create a new project and add the Fortran source files to the solution.  After creating the new solution from VS, there will be a new folder where you can copy your Fortran source files.  In the VS Solution Explorer form (usually on the right side of VS), under Source Files, right-click, then select Add, then "Existing item".   For a "hello world" test program to get started, I would recommend  a console application and just one source file for the program.  You will need to confirm that you have installed Intel Fortran so that it is integrated into Visual Studio.  Then in the VS -> Build menu, select "Build Solution".  If that is successful, in the Debug menu select "Start debugging" which should run the executable and open the console window..

Is this the direction you want to go to get started?

Regards, Greg

0 Kudos
Black Belt

For the preprocessor stuff,

For the preprocessor stuff, once you have created the project and added your source file, right click on the project (not the Solution, it will have an icon of a purple box with "Fo" in it), select Properties. Then go to Fortran > Preprocessor. Change "Preprocess Source File" from No to Yes. Then in "Preprocessor Definitions", type in:


This does what the -D switches do in the makefile.

You have a non-Fortran problem, though, in that the program wants to use MPI. That will take more effort, so maybe you want to start by NOT defining PARALLEL under Preprocessor (just put in LOOSE). Once you have the program working that way, then you can start to look at MPI.

Steve (aka "Doctor Fortran") -
0 Kudos