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

Problem compiling the simplest MPI program

elfmade
Beginner
1,054 Views
I've installed Visual Studio 2005 and Intel Fortran Compiler 10 in Windows XP...No problems with the instalations...

I've tryed to run the first program i've found in the book USING MPI (http://www-unix.mcs.anl.gov/mpi/usingmpi/usingmpi-1st/index.html) but it give me an error "Error 1 error LNK2019: unresolved external symbol _MPI_INIT referenced in function _MAIN__ pi.obj
"
...The program is:

program main

include 'mpif.h'

double precision PI25DT
parameter (PI25DT = 3.141592653589793238462643d0)

double precision mypi, pi, h, sum, x, f, a
integer n, myid, numprocs, i, rc
c function to integrate
f(a) = 4.d0 / (1.d0 + a*a)

call MPI_INIT( ierr )
call MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
call MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )
print *, "Process ", myid, " of ", numprocs, " is alive"

sizetype = 1
sumtype = 2

10 if ( myid .eq. 0 ) then
write(6,98)
98 format('Enter the number of intervals: (0 quits)')
read(5,99) n
99 format(i10)
endif

call MPI_BCAST(n,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)

c check for quit signal
if ( n .le. 0 ) goto 30

c calculate the interval size
h = 1.0d0/n

sum = 0.0d0
do 20 i = myid+1, n, numprocs
x = h * (dble(i) - 0.5d0)
sum = sum + f(x)
20 continue
mypi = h * sum

c collect all the partial sums
call MPI_REDUCE(mypi,pi,1,MPI_DOUBLE_PRECISION,MPI_SUM,0,
$ MPI_COMM_WORLD,ierr)

c node 0 prints the answer.
if (myid .eq. 0) then
write(6, 97) pi, abs(pi - PI25DT)
97 format(' pi is approximately: ', F18.16,
+ ' Error is: ', F18.16)
endif

goto 10

30 call MPI_FINALIZE(rc)
stop
end

...I found the mpif.h and i put it in project directory...but it seems that this is not enough...Looks like it needs more linked files...Any help would be appreciated...Thank you
0 Kudos
8 Replies
TimP
Honored Contributor III
1,054 Views
As this is a link error, not a compile error, and you did not show the link command, the first suspicion is that you didn't include the MPI libraries in the link. The usual way of building an MPI application is to replace the ifort command with the MPI wrapper, usually mpif77 or mpif90, which provides all the MPI include and library paths. Your book should have recommendations on how this is done. Adding all the necessary paths to your project also would accomplish it.
0 Kudos
elfmade
Beginner
1,054 Views
In Visual Studio 2005 i've just created an EMPTY PROJECT from Intel Fortran->Console Application and then i've add to this project just the file pi.f which contain the above code and the file mpif.h . How to link the libraries? Where should i replace that command ifort? This book is kind of old and it doesn't have to many instructions...Thank you for your time. I hope you can help me
0 Kudos
TimP
Honored Contributor III
1,054 Views
I'm guessing, from the reference you made, that you may be using Argonne MPICH, but it would be good to know which one. It will be several days before I could ask a colleague who is familiar with these. I do know that he uses VS2003 with the old 32-bit MPICH, as he has not got the VS2005 linking sorted out. I believe he uses command line to link the 64-bit MPICH2 directly with Microsoft 64-bit SDK. Still, it may be possible to add all the MPICH libraries as dependencies in your project, and link that way.
As there are developer's guides and test case setups for several versions of Argonne MPICH, including the test case you mentioned, it would take more detail from you to understand which of those should be relevant. In principle, the Clusters and HPC Technology forum would be a more promising place to ask questions. Intel MPI for Windows is a work-alike for Argonne MPICH2, so there should be some expertise available on that.
0 Kudos
elfmade
Beginner
1,054 Views
Thank you again Tim for your time...It is important to me to resolve this i need it for a project... I've installed olso the MPICH found at http://www-unix.mcs.anl.gov/mpi/mpich1/mpich-nt/ ...But still i don't know how to link it to Visual Studio...Maybe i should set something in Intel Compiler....There must be someone that did this before..Any information is good.
0 Kudos
Steven_L_Intel1
Employee
1,054 Views
Two things you need to do. In the project properties, Linker > General, Additional Library Directories, add the path to the folder containing the MPI .lib files. Just the folder, not the file names. Now under Linker > Input, list the .lib filenames under "Additional Dependencies".

See if that gets you further.
0 Kudos
elfmade
Beginner
1,054 Views
Thanks for both of you guys...Now i have another small problem i hope.. When i'm trying to run de exe file after the program was finally succesfull compiled it give me this error "MPI_COMM_RANK : Null communicator"...I found out this may because the older version of the file mpif.h that come with the program above ( pi.f and mpif.h could be found at this addres ftp://info.mcs.anl.gov/pub/mpi/usingmpi-1st/examples/simplempi/ ) is incompatible with the librarie that comes with the program MPICH ( http://www-unix.mcs.anl.gov/mpi/mpich1/mpich-nt/ )...If i take the new version of mpif.h file that come MPIH program, it give the following error during the compilation "Error: This symbol has multiply declared DEC$ ATTRIBUTES DLLIMPORT attribute. [MPIPRIV] mpif.h"...What should i do next!!1..Thank you
0 Kudos
Steven_L_Intel1
Employee
1,054 Views
The compilation diagnostic is unrelated to your run-time error. It just means that the compiler saw two separate DLLIMPORT directives for the same name. Perhaps one of them is in your source - if so, remove it.

I am not very familiar with MPI coding, but the run-time error you got suggests to me a coding error in your application. Have you tried a sample program that is "known" to work?
0 Kudos
elfmade
Beginner
1,054 Views
This program work for sure...It's from the book and in the book's errata nothing that say that program is wrong..Plus this program is put as example on many page from the internet...But it seems that my compilation tools are different..I don't know what's wrong with this program maybe my lack of knowledge for sure... But thanks anyway guys...Thank for your time
0 Kudos
Reply