0

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 exit

GNU 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~

4
  • Welcome, please take the tour. It is important to use the features of the question editor to format the code in your question properly. I also suggest reading How to Ask and minimal reproducible example. Commented Feb 14, 2023 at 8:41
  • 1
    What do you mean that you tried to compile manually? Which exact command did you execute? Youbeither have to use provided wrapper like mpif90 or you have to link all the necesary libraries and that is complicated. And how exactly did you try to run the program? Using mpirun? Please follow minimal reproducible example and show us some complete code, the exact commands you execute and the details of what happened (does it hang? some error messages?). Commented Feb 14, 2023 at 8:43
  • you would typically uses the wrapper (e.g. mpifort) instead of the Fortran compiler (e.g. gfortran). If you do not use the wrappers, try running mpifort --showme to list the directories and libraries you need to manually include. Commented Feb 14, 2023 at 8:53
  • No, I use gfortran TT and I did no wrapping at all, I only follow some guide in youtube that use MPICH2. I think I dont need to explain anything for now since what I did is complete nonsense. Can anyone please give me a beginner youtube guide link from no setup at all to compile a fortran program? I use windows computer and code::blocks, no experience in linux/C/CMD, with the condition of the easiest to hardest compilers to work with for me are: cygwin, ms-mpi, mpich2, intel fortran (I need to have permission to change C and not allowed to install Visual studio code). Many thanks Commented Feb 14, 2023 at 9:19

2 Answers 2

1

You can do the following with:

  • Windows 10 command line (NOT Cygwin)
  • Intel Fortran compiler (ifort)
  • Microsoft MPI

(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

rem ifort -c %1.f90 /traceback /check:all /Qparallel -I"C:\Program Files (x86)\Microsoft SDKs\MPI\Include\intel
ifort -c %1.f90 /Qparallel /O3 -I"C:\Program Files (x86)\Microsoft SDKs\MPI\Include\intel
ifort %1.obj -o %1.exe "C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64\msmpi.lib" "C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64\msmpifec.lib"

runmpi.bat

set OPT="C:\Program Files\Microsoft MPI\bin"
%OPT%\mpiexec -n %2 %1

test.f90

program main
   use mpi
   implicit none

   integer size, rank, tag
   integer stat(mpi_status_size), ierr
   integer I
   real R

   call mpi_init( ierr )
   call mpi_comm_size( mpi_comm_world, size, ierr )
   call mpi_comm_rank( mpi_comm_world, rank, ierr )
   write( *, * ) "Processor ", rank, " of ", size, " is alive"

   tag = 0
   if ( rank == 0 ) then
      I = 42
      R = 3.14152
      call mpi_send( I, 1, mpi_integer, 1, tag, mpi_comm_world, ierr )
      write( *, * ) "Processor ", rank, " sent integer ", I
      call mpi_send( R, 1, mpi_real   , 1, tag, mpi_comm_world, ierr )
      write( *, * ) "Processor ", rank, " sent real ", R

   else if ( rank == 1 ) then
      call mpi_recv( I, 1, mpi_integer, 0, tag, mpi_comm_world, stat, ierr )
      write( *, * ) "Processor ", rank, " received integer ", I
      call mpi_recv( R, 1, mpi_real, 0, tag, mpi_comm_world, stat, ierr )
      write( *, * ) "Processor ", rank, " received real ", R
   end if

   call mpi_finalize( ierr )

end program main

(5) Using a command window, and in the directory where do_intel.bat, runmpi.bat and test.f90 live, type

do_intel test

which should (hopefully!) compile and link the test file.

(6) If all compiled correctly then type

runmpi test.exe 2

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):

gfortran -c -fallow-invalid-boz -fno-range-check mpi.f90

and the following batch file can compile and link the test file:

rem gfortran -c %1.f90 -Wall -Wextra -I"C:\Program Files (x86)\Microsoft SDKs\MPI\Include\gfortran" -fallow-argument-mismatch -ff2c
gfortran -c %1.f90 -O3 -I"C:\Program Files (x86)\Microsoft SDKs\MPI\Include\gfortran" -fallow-argument-mismatch -ff2c
gfortran -o %1.exe %1.o "C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64\msmpi.lib" "C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64\msmpifec.lib"

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.

Sign up to request clarification or add additional context in comments.

11 Comments

Wow many thanks for your help, it looks pretty clear to me and hopefully also help many other people. But, I first will need to apply for permission to access the C drive. This may take a couple days. I hope there will be no problem. Bless you and many thanks~
Hi~ I have done the procedure that you mentioned. It seems my system does not know option --s I will show the command window response in my question
@DrunkenEngineer, there is no option --s in my batch file. I'm not sure what you are alluding to. At least you seem to have got past the compile stage (which suggests that the mpi module is OK), but maybe your version of ifort is using some other linker in a strange way?
@DrunkenEngineer, are you sure that you can compile and link ANY fortran program from the command line using ifort? Just a simple "Hello, world!" program - no MPI.
yes I can compile it. I often compile with gfortran and also ifort with no problem. It seems it connects itself with GNU, but idk why. Maybe because (1) I put something in the system environment variables (2) I set up many things like in cygwin, mpich, or anything (3) I set up linker setting in code::blocks? But i'm not sure if they are affecting the compilation process or not
|
0

Cygwin has package for OpenMPI

for development you need to install libopenmpi-devel
https://cygwin.com/packages/summary/libopenmpi-devel.html

and the package openmpi
https://cygwin.com/packages/x86_64/openmpi/openmpi-4.1.5-1
provides the interface to most GNU GCC compiler. See extract of the content

usr/bin/mpic++ -> opal_wrapper.exe
usr/bin/mpicc -> opal_wrapper.exe
usr/bin/mpicxx -> opal_wrapper.exe
usr/bin/mpiexec -> orterun.exe
usr/bin/mpif77 -> opal_wrapper.exe
usr/bin/mpif90 -> opal_wrapper.exe
usr/bin/mpifort -> opal_wrapper.exe

Reusing the example reported in the other answer

$ mpif90 test.f90 -o prova

$ mpirun -n 4 ./prova
 Processor            0  of            4  is alive
 Processor            0  sent integer           42
 Processor            0  sent real    3.14152002
 Processor            1  of            4  is alive
 Processor            1  received integer           42
 Processor            1  received real    3.14152002
 Processor            2  of            4  is alive
 Processor            3  of            4  is alive

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.