LAM/MPI logo

LAM/MPI General User's Mailing List Archives

  |   Home   |   Download   |   Documentation   |   FAQ   |   all just in this list

From: ew fgff (sah_8_at_[hidden])
Date: 2006-02-18 11:46:26


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