I am using Codeblock IDE to write and compile my Fortran program. Right now I want to include MPI to my GNU Fortran Compiler. After following some guides on GNU GCC Compiler, it occurs to me that I need to set up the following for MPICH2 (there are two guides about that):
(1) add mpi.lib to the linker setting (2) add include file to the search directory
However, these setting won’t compile due to error on this line below, and saying that it has an unexpected EoF: use mpi
So, then I tried to use Cygwin include file (with mpi.lib from MPICH2), strangely, it compiles fine, even with the:
call mpi_init (ierr)
call mpi_comm_rank (mpi_comm_world,rank,ierr)
call mpi_finalize (ierr)
However, when I tried to run the program. It won’t perform pass the:
call mpi_init (ierr)
Then I tried to manually compile the program, and it shows:
C:\Users\7931\AppData\Local\Temp\cclYnhYq.o:main.f90:(.text+0x18c): undefined reference to mpi_init_' C:\Users\7931\AppData\Local\Temp\cclYnhYq.o:main.f90:(.text+0x1fd): undefined reference to mpi_comm_rank_’
C:\Users\7931\AppData\Local\Temp\cclYnhYq.o:main.f90:(.text+0x276): undefined reference to `mpi_finalize_’
collect2.exe: error: ld returned 1 exit status
Maybe there is a setting that I have not set up yet for the MPI environment, or I need to get the Cygwin mpi.lib, which I can’t found after installing the complete MPI package from the Cygwin.
After trying many other things, I realized that, why there is no "include" folder on Cygwin64
Maybe what I need is a guide how to set up linker/search directories/path for MPI within Cygwin64 environment?
Anyone can please help me here? Many thanks for your help
Edit: I have performed the solution from last chance. It seems there is an error during linking. Below is the command window response:
C:\Windows\system32>cd C:\Batch
C:\Batch>do_intel test
C:\Batch>rem ifort -c test.f90 /traceback /check:all /Qparallel -I"C:\Program Files (x86)\Microsoft SDKs\MPI\Include\intel
C:\Batch>ifort -c test.f90 /Qparallel /O3 -I"C:\Program Files (x86)\Microsoft SDKs\MPI\Include\intel Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on IA-32, Version 2021.6.0 Build 20220226_000000 Copyright (C) 1985-2022 Intel Corporation. All rights reserved.
C:\Batch>ifort test.obj -o test.exe "C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64\msmpi.lib" "C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64\msmpifec.lib" Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on IA-32, Version 2021.6.0 Build 20220226_000000 Copyright (C) 1985-2022 Intel Corporation. All rights reserved.
link: unknown option -- s Try 'link --help' for more information.
C:\Batch>runmpi test.exe 2
C:\Batch>set OPT="C:\Program Files\Microsoft MPI\bin"
C:\Batch>"C:\Program Files\Microsoft MPI\bin"\mpiexec -n 2 test.exe
C:\Batch>link --help Usage: link FILE1 FILE2 or: link OPTION Call the link function to create a link named FILE2 to an existing FILE1.
--help display this help and exit --version output version information and exitGNU coreutils online help: https://www.gnu.org/software/coreutils/ Report any translation bugs to https://translationproject.org/team/ Full documentation https://www.gnu.org/software/coreutils/link or available locally via: info '(coreutils) link invocation'
C:\Batch>
Edit2: Below is the response from CMD when I tried to run the batch file manually one by one (the first line has no response):
C:\Batch>rem ifort -c %1.f90 /traceback /check:all /Qparallel -I"C:\Program Files (x86)\Microsoft SDKs\MPI\Include\intel
C:\Batch>ifort -c %1.f90 /Qparallel /O3 -I"C:\Program Files (x86)\Microsoft SDKs\MPI\Include\intel Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on IA-32, Version 2021.6.0 Build 20220226_000000 Copyright (C) 1985-2022 Intel Corporation. All rights reserved.
fortcom: Severe: No such file or directory
... file is '%1.f90' compilation aborted for %1.f90 (code 1)
Note: I also tried changing all 1.f90 to test.f90, still the same result appear
Many thanks for your help~
You can do the following with:
(1) Install and be able to use the Intel compiler in a Windows command window (your problem).
(2) Install Microsoft MPI by downloading it from https://www.microsoft.com/en-us/download/details.aspx?id=100593 You will need to download - and then install - both msmpisetup.exe and msmpisdk.msi
(3) You will need to compile mpi.f90 with your compiler (ifort) in the MS-MPI include directory (for which you will need administrator rights).
(i) Type "cmd" into the Windows search bar and choose (RHS) "Run as administrator". You will need to ensure that you can still run the ifort compiler in this state: one alternative is to start the command window from the options in the Windows start menu for the compiler, but make sure that you use right-click and run as administrator here.
(ii) In this Administrator command window, navigate to the MS-MPI include directory (e.g. C:\Program Files (x86)\Microsoft SDKs\MPI\Include) and create a new subdirectory "intel".
(iii) Copy the file mpi.f90 from the include directory into the .\intel subdirectory. Also copy the file mpifptr.h from the .\x64 subdirectory into the .\intel subdirectory.
(iv) In this command window, navigate into the .\intel subdirectory and type the command "ifort -c mpi.f90". You should now have the relevant mpi module file available.
(4) Create a normal directory somewhere on your C-drive and put the following batch files and MPI/fortran source file in it:
do_intel.bat
runmpi.bat
test.f90
(5) Using a command window, and in the directory where do_intel.bat, runmpi.bat and test.f90 live, type
which should (hopefully!) compile and link the test file.
(6) If all compiled correctly then type
to run the test program with two processors.
gfortran can also be made to run with Microsoft MPI, although it is harder work to get it going and I have found it "unreliable".
The following command is needed to compile the mpi.f90 file (assumed to be in a .\gfortran subdirector of the MS-MPI include directory):
and the following batch file can compile and link the test file:
For many of my more complex processes, gfortran with MS-MPI works OK for a small number of processors and then either hangs or crashes with more; I have been unable to find out why, as the problem works fine with the intel compiler.