Newsgroups: comp.parallel.mpi
From: eddemain@neumann.uwaterloo.ca (Erik Demaine)
Subject: Re: Short MPI example of global sums neded (and a manual would be nice, too)
Organization: University of Waterloo
Date: Thu, 19 Oct 1995 13:56:17 GMT
Message-ID: <DGp81t.74J@undergrad.math.uwaterloo.ca>

Fedor G. Pikus (pikus@sbphy.physics.ucsb.edu) wrote:
: Single-Program-Multiple-Data code:
: 1) Node number 0 recognizes that it is 0, and reads data.
: 2) Node 0 sends data to all other nodes.
: 3) All nodes except 0 receive data
: 4) All nodes including 0 compute
: 5) All nodes execute global sum of few real and integer numbers

      program spmd_code

      integer err, p, np
      real x(500), y(5), ysum(5)
      integer z(3), zsum(5)

      call mpi_init (err)
      call mpi_comm_rank (MPI_COMM_WORLD, p, err)
      call mpi_comm_size (MPI_COMM_WORLD, np, err)
      if (p .eq. 0) then
	 open (10, 'data')
	 read (10,*) x
      end if
c The 0 after MPI_REAL is the root (who has the data to broadcast).
      call mpi_bcast (x, 500, MPI_REAL, 0, MPI_COMM_WORLD, err)
c ...compute y and z...
      call mpi_allreduce (y, ysum, 5, MPI_REAL, MPI_SUM, MPI_COMM_WORLD,
     &   err)
      call mpi_allreduce (z, zsum, 3, MPI_INTEGER, MPI_SUM,
     &   MPI_COMM_WORLD, err)
c ...save ysum and zsum in seperate files...
      call mpi_finalize (err)

      stop
      end

After every MPI call that has err passed, there should be something like

      if (err .ne. 0) then
	 print *,'Error in MPI call!  Aborting...'
	 stop
      end if
: I would also appreciate a pointer to a nice MPI manual: not a
: quick-start cheat-shit, but preferably a reference guide which lisks all
: calls, with all their parameters and what they do, and short example of
: how to call it.

The best thing that I know of is the MPI 1.1 standard itself.  It includes
a few examples.  See

	http://www.mcs.anl.gov/mpi

Hope this helps,
Erik
--
Erik Demaine                 \/  Masters student in Computer Science
Dept. of Computer Science    /\  e-mail: eddemain@neumann.uwaterloo.ca
University of Waterloo       \/  URL   : http://barrow.uwaterloo.ca/~eddemain/
Waterloo, ON Canada N2L 3G1  /\  DO NOT READ THIS SENTENCE--it is false.

