Newsgroups: comp.parallel.mpi
From: Fokke Dijkstra <f.dijkstra@chem.ruu.nl>
Subject: count-process uses complete CPU
Organization: RUU
Date: Wed, 10 Dec 1997 16:39:03 +0100
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-ID: <348EB797.41C6@chem.ruu.nl>

Hi,

Is there an easy way to create a process in MPI supplying values of
a counter to the other processes without taking a complete CPU or a lot
of CPU-time? 
The problem seems to be that the process is in MPI_RECV in a tight loop
checking for incoming sends.
 
At the moment I'm using the code below for supplying the values. It is
the easiest to have one process only performing this work, but it should
not spend all CPU-cycles for supplying values once in awhile.

What is the best solution for such a problem? 

Regards,

Fokke Dijkstra

      subroutine counter_create()
c
      implicit real*8 (a-h,o-z), integer (i-n)
c
      include 'mpif.h'
c
      common /mpicomm/ismall_comm,icount_comm,iserver
c
      dimension istatus(MPI_STATUS_SIZE),irank(2)
      logical odone
c
      data IREQ /1/
      data IRESET /2/
      data IGOAWAY /3/
      ioldcomm = MPI_COMM_WORLD
      odone = .false.
      icounter = 1
      call MPI_COMM_SIZE(ioldcomm,numprocs,ierr)
      call MPI_COMM_RANK(ioldcomm,myid,ierr)
      iserver = numprocs - 1
      call MPI_COMM_DUP(ioldcomm,icount_comm,ierr)
      call MPI_COMM_GROUP (ioldcomm,ioldgroup,ierr)
      irank(1)=iserver
      call MPI_GROUP_EXCL(ioldgroup,1,irank,ismall_group,ierr)
      call MPI_COMM_CREATE(ioldcomm,ismall_group,ismall_comm,ierr)
      call MPI_GROUP_FREE(ismall_group,ierr)
      if (myid.eq.iserver) then
        print *,'This process can be counted upon'
10      if (.not.odone) then
          call MPI_RECV(incc,1,MPI_INTEGER,MPI_ANY_SOURCE,
     &                  MPI_ANY_TAG,icount_comm,istatus,ierr)
          if (istatus(MPI_TAG).eq.IREQ) then
            call MPI_SEND(icounter,1,MPI_INTEGER,
     &            istatus(MPI_SOURCE),IREQ,icount_comm,ierr)
            icounter=icounter+incc
          else
            if (istatus(MPI_TAG).eq.IGOAWAY) then
              odone=.true.
            else
              if (istatus(MPI_TAG).eq.IRESET) then
                icounter = 1
              else
                  call vberr('bad tag sent to counter')
              endif
            endif
          endif
          if (.not.odone) goto 10
        end if
        call counter_free()
      endif
      return
      end


This has been modelled like an example in:

W. Gropp, E. Lusk, A. Skjellum, Using Mpi, MIT, Cambridge, 1994

-- 
------------------------------------------------------------------------
Fokke Dijkstra                        Theoretical Chemistry group
E-mail: f.dijkstra@chem.ruu.nl        Padualaan 14
Phone : +31-30-2532205                3584 CH  UTRECHT (The Netherlands)
------------------------------------------------------------------------

