Jeff,
Thanks.
Here is a simple code from the book "Using MPI" that I want to modify to use
MPI_IN_PLACE.
program main
include "mpif.h"
double precision PI25DT
parameter (PI25DT = 3.141592653589793238462643d0)
double precision mypi, pi, h, sum, x, f, a
double precision starttime, endtime
integer n, myid, numprocs, i, ierr
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)
10 if ( myid .eq. 0 ) then
print *, 'Enter the number of intervals: (0 quits) '
read(*,*) n
endif
starttime = MPI_WTIME()
c broadcast n
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.
endtime = MPI_WTIME()
if (myid .eq. 0) then
print *, 'pi is ', pi, ' Error is', abs(pi - PI25DT)
print *, 'time is ', endtime-starttime, ' seconds'
endif
goto 10
30 call MPI_FINALIZE(ierr)
stop
end
Can I use MPI_IN_PLACE in the MPI_REDUCE call? If I can, how? Thanks for any
help!
David
***** Correspondence *****
> From: Jeff Squyres <jsquyres_at_[hidden]>
> Reply-To: Open MPI Users <users_at_[hidden]>
> Date: Fri, 3 Mar 2006 18:04:28 -0500
> To: Open MPI Users <users_at_[hidden]>
> Subject: Re: [OMPI users] MPI_IN_PLACE
>
> On Mar 3, 2006, at 4:40 PM, Xiaoning (David) Yang wrote:
>
>> Does Open MPI supports MPI_IN_PLACE? Thanks.
>
> Yes.
>
> --
> {+} Jeff Squyres
> {+} The Open MPI Project
> {+} http://www.open-mpi.org/
>
>
> _______________________________________________
> users mailing list
> users_at_[hidden]
> http://www.open-mpi.org/mailman/listinfo.cgi/users
|