JAVA

endif

*

if( master.and.(master_rank.eq.iam) ) then

call MPI_SEND(msg,len(msg),MPI_CHARACTER,

+ slave_rank,0,icomm,ierr)

endif

*

if((.not.master).and.(iam.eq.slave_rank)) then

call MPI_RECV(msg,len(msg),MPI_CHARACTER,

+ master_rank,0,icomm,stat,ierr)

write(*,1000),'slave',iam,proc_name, msg

endif

* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

* 󠠠

* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

* 堠

if( (.not.master) .and. (iam.eq.slave_rank)) then

write (msg,2000),'slave', iam

else

msg='---'

endif

*

if((.not.master).and.(iam.eq.slave_rank)) then

call MPI_SEND(msg,len(msg),MPI_CHARACTER,

+ master_rank,0,icomm,ierr)

endif

*

if( master.and.(master_rank.eq.iam) ) then

call MPI_RECV(msg,len(msg),MPI_CHARACTER,

+ slave_rank,0,icomm,stat,ierr)

write(*,1000),'master',iam,proc_name, msg

endif

* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

*

* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

call MPI_COMM_DISCONNECT(icomm, ierr)

100 continue

call MPI_FINALIZE(ierr)

stop

1000 format(a7,i2,' on ',a15,' : ',a30)

3000 format(a7,i2,' on ',a15,' : start')

2000 format('message from', a7, i2)

4000 format('broadcast from', a7, i2)

END

* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

*

* -- .false.

* "--slave"

* master .false. .true.

function cmd_arg_parse(master)

logical cmd_arg_parse

logical master

integer npar

character*100 arg

cmd_arg_parse=.true.

master=.true.

*

npar=iargc()

if(npar.eq.0) then

* -- master

cmd_arg_parse=.false.

return

endif

if(npar .ne. 1) then

*

write (*,*) 'usage: getarg [--slave]'

return

endif

* 1

call getarg(1,arg)

if(arg.ne.'--slave')then

write (*,*) 'unknow option:',arg

write (*,*) 'usage: getarg [--slave]'

return

endif

* slave

master=.false.

cmd_arg_parse=.false.

return

end

:

$ mpiexec -n 1 ./spawn

master 0 on node2.home.net : start

slave 1 on node2.home.net : start

slave 0 on node1.home.net : start

slave 2 on node1.home.net : start

slave 1 on node2.home.net : broadcast from slave 2

slave 0 on node1.home.net : broadcast from slave 2

slave 2 on node1.home.net : broadcast from slave 2

master 0 on node2.home.net : message from slave 2

slave 2 on node1.home.net : message from master 0


<< >>