This looks like more of a general fortran programming question than a
LAM or MPI question.
I don't quite understand exactly what you are trying to do in this
application, but it looks like your logic is not right yet -- you're
only allowing MPI_COMM_WORLD rank 0 to call rout() (which calls func
()), but then you have statements in func() where you clearly are
expecting MPI_COMM_WORLD ranks 1 and 2 to be there.
A few suggestions:
1. Buy a good fortran programming / reference book. :-)
2. If you're trying to do a master/slave model, then split up your
master functionality into one subroutine/function and your slave
functionality into another. This will help keep it clear in your
mind (and in the code) what the master is doing and what the slave is
doing. Perhaps something like:
implicit double precision(a-z)
include 'mpif.h'
integer myid, numprocs, ierr
external func
call MPI_INIT( ierr )
call MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
call MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )
if(myid .eq. 0)then
call master(func, 20, final)
else
call slave(func, 20, final)
endif
call MPI_FINALIZE(ierr)
end
There are frequently many different solutions to programming
problems; I only suggest a few of them above. Many others would work
as well.
On Feb 18, 2006, at 11:46 AM, ew fgff wrote:
> Hi Jeff,
>
> I am really sorry for the attached massage. I did not
> want to send that massage. When I clicked the "send",
> I realized that I forgot to remove the old massage.
>
> I think I understand the problem in my code. In the
> main program rout() is called for rank0 with "if"
> filter. rout() calls func(). Inside the func(), data
> is sent to rank1 with "if" filter. This is the problem
> because I have already used "if" filter for rank0 in
> the main program. So, it can't send to rank1.
>
> I want to call rout() in rank0 from the main program
> only. So, I have to use "if" filter. In the func(), I
> have to call other subroutines.
> To avoid "if" filter in main program, if I initialize
> MPI inside func() then there will be error because
> function is called many times and MPI can't be
> initialized more than 1. I could not find the
> solution. Could you give me some idea. I appreciate
> it. Below is my new code which is similar to my real
> code.
> ######################################
>
> implicit double precision(a-z)
> include 'mpif.h'
> integer myid, numprocs, ierr
> external func
>
> call MPI_INIT( ierr )
> call MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
> call MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )
>
> if(myid .eq. 0)then
> call rout(func,20,final)
> endif
>
> call MPI_FINALIZE(ierr)
> end
>
> c-----------------------------------------
>
> double precision function func()
> implicit double precision(a-z)
> include 'mpif.h'
> integer myid, numprocs, ierr
>
>
> call MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
> call MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )
>
> x = 20.0d0*rand()
>
> call MPI_SEND(x, 1, MPI_DOUBLE_PRECISION, 1, 1,
> & MPI_COMM_WORLD,ierr)
> call MPI_SEND(x, 1, MPI_DOUBLE_PRECISION, 2, 2,
> & MPI_COMM_WORLD,ierr)
>
> if(myid .eq. 1)then
> call MPI_RECV(x, 1, MPI_DOUBLE_PRECISION, 0, 1,
> & MPI_COMM_WORLD, status, ierr)
> call inte(x,reslt)
> call MPI_SEND(reslt, 1, MPI_DOUBLE_PRECISION, 0,
> 11,
> & MPI_COMM_WORLD,ierr)
> elseif(myid .eq. 2)then
> call MPI_RECV(x, 1, MPI_DOUBLE_PRECISION, 0, 2,
> & MPI_COMM_WORLD, status, ierr)
> call cal(x,prob)
> call MPI_SEND(prob, 1, MPI_DOUBLE_PRECISION, 0, 22,
> & MPI_COMM_WORLD,ierr)
> endif
>
> call MPI_RECV(reslt, 1, MPI_DOUBLE_PRECISION, 1, 11,
> & MPI_COMM_WORLD, status, ierr)
> call MPI_RECV(prod, 1, MPI_DOUBLE_PRECISION, 2, 22,
> & MPI_COMM_WORLD, status, ierr)
>
> func = reslt*prod
> return
> end
> c--------------------------------------------------
>
> subroutine rout(func,n,final)
> implicit double precision(a-z)
> integer n
> do 10 i = 1, n
> y = y + func()
> 10 continue
> final = y/n
> end
> #########################################
>
> Thanks a lot.
> Manoj
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> _______________________________________________
> This list is archived at http://www.lam-mpi.org/MailArchives/lam/
--
{+} Jeff Squyres
{+} The Open MPI Project
{+} http://www.open-mpi.org/
|