Hi, I am a new LAM-MPI user, I think my problem is common but I browsed the mailing list without finding any satisfying answer. Here is my problem. I want to wrap that FORTRAN program called "pi.f" :
c**********************************************************************
c pi.f - compute pi by integrating f(x) = 4/(1 + x**2) c
c c
c Each node: c
c 1) receives the number of rectangles used in the approximation. c
c 2) calculates the areas of it's rectangles. c
c 3) Synchronizes for a global summation. c
c Node 0 prints the result. c
c c
c Variables: c
c c
c pi the calculated result c
c n number of points of integration. c
c x midpoint of each rectangle's interval c
c f function to integrate c
c sum,pi area of rectangles c
c tmp temporary scratch space for global summation c
c i do loop index c
c**********************************************************************
program main
include 'mpif.h'
real PI25DT
parameter (PI25DT = 3.141592653589793238462643)
real mypi, pi, h, sum, x, f, a
integer n, myid, numprocs, i, ierr
c Function to integrate
f(a) = 4.0 / (1.0 + a*a)
c*****************************************************c
c Initialize MPI environment c
c*****************************************************c
call MPI_INIT( ierr )
c Get the process number and assign it to the variable myid
call MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
c Determine how many processes the program will run on and
c assign that number to numprocs
call MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )
c Each process will print its id number and the total number of processes
print *, 'Process ', myid, ' of ', numprocs, ' is alive'
sizetype = 1
sumtype = 2
c Test to see if this is the program running on process 0,
c and run this section of the code for input.
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
c The argument 0 in the 4th place indicates that process 0 will send
c then single integer n to every other process in processor group MPI_COMM_WORLD.
call MPI_BCAST(n,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
c If the user puts in a negative number for n we leave the
c program by branching to MPI_FINALIZE
if ( n .le. 0 ) goto 30
c Now this part of the code is running on every node and each one
c shares the same value of n. But all other variables are local
c to each individual process. So each process then calculates the
c each interval size.
c*****************************************************c
c Main Body : Runs on all processors c
c*****************************************************c
h = 1.0/n ! even step size h as a function of partions
sum = 0.0
do 20 i = myid+1, n, numprocs
x = h * (dble(i) - 0.5)
sum = sum + f(x)
20 continue
mypi = h * sum ! this is the total area in this process, (a partial sum.)
c After each partition of the integral is calculated we collect all the
c partial sums. The MPI_SUM argument is the operation that adds all the
c values of mypi into pi of process 0 indicated by the 6th argument.
call MPI_REDUCE(mypi,pi,1,MPI_DOUBLE_PRECISION,MPI_SUM,0,
$ MPI_COMM_WORLD,ierr)
c*****************************************************c
c Print results from Process 0 c
c*****************************************************c
c Finally the program tests if myid is node 0
c so process 0 can print 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
c Run the program again.
c
goto 10
c Branch for the end of program. MPI_FINALIZE will close all the processes
c in the active group.
30 call MPI_FINALIZE(rc)
stop
end
So, I enter the following command : [ ]$ mpif77 pi.f
and lam gives me that error message :
FORTRAN 77 Compiler 7.5a, Copyright (c) 1987-2002, Absoft Corp.
pi.o: In function `main':
pi.o(.text+0x59): undefined reference to `MPI_INIT'
pi.o(.text+0x8a): undefined reference to `MPI_COMM_RANK'
pi.o(.text+0xb6): undefined reference to `MPI_COMM_SIZE'
pi.o(.text+0x325): undefined reference to `MPI_BCAST'
pi.o(.text+0x4b9): undefined reference to `MPI_REDUCE'
pi.o(.text+0x5ba): undefined reference to `MPI_FINALIZE'
collect2: ld returned 1 exit status
Can somebody help me with that ? Please be very precise in your explanation, don't forget you are talking to a dummie !
Thank you very much.
Olivier Paradis Béland
|