Back to CFM home             Brown University



dot-product program

      program dot_product

      implicit none

      include 'mpif.h'

      double precision mflops, product, time
      double precision a, b
      double precision dotprod, blas_dotprod
      integer ierror, nprocs, myproc, iter, nglobal, np, n 
      integer i, start
c$$$      double precision pblas_dotprod
c$$$      integer desc(8), ctxt


      include 'dotsizes'

      dimension a(n), b(n)


      call MPI_INIT (ierror)
      call MPI_COMM_SIZE (MPI_COMM_WORLD, nprocs, ierror)
      call MPI_COMM_RANK (MPI_COMM_WORLD, myproc, ierror)

      start = myproc * n
      do i = 1, n
         a(i) = dble(start + i)
         b(i) = dble((nglobal + 1) - (start + i))
      enddo

      call MPI_BARRIER (MPI_COMM_WORLD, ierror)

      if (myproc .eq. 0) time = MPI_WTIME ()

      do i=1, iter
         product = dotprod (n, a, b, MPI_COMM_WORLD)
      enddo

      call MPI_BARRIER (MPI_COMM_WORLD, ierror)

      if (myproc .eq. 0) then
         time = MPI_WTIME () - time
         mflops = 1.0d-6 * (2 * nglobal - 1) * iter / time 
         write (6,*) 'dotprod achieves ', mflops, ' Mflop/s'
         write (6,*) 'the dot product is ', product
      endif

C Initialize Communications 
      product = blas_dotprod (n, a, b, MPI_COMM_WORLD)

      call MPI_BARRIER (MPI_COMM_WORLD, ierror)

      if (myproc .eq. 0) time = MPI_WTIME ()

      do i=1, iter
         product = blas_dotprod (n, a, b, MPI_COMM_WORLD)
      enddo

      call MPI_BARRIER (MPI_COMM_WORLD, ierror)

      if (myproc .eq. 0) then
         time = MPI_WTIME () - time
         mflops = 1.0d-6 * (2 * nglobal - 1) * iter / time
         write (6,*) 'blas_dotprod achieves ', mflops, ' Mflop/s'
         write (6,*) 'the dot product is ', product
      endif

c$$$      call BLACS_GET (0, 0 , ctxt)
c$$$      call BLACS_GRIDINIT (ctxt, 'Row-major', nprocs, 1)
c$$$
c$$$      call descinit (desc, nglobal, 1, n, 1, 0, 0, ctxt, n)
c$$$
c$$$      call MPI_BARRIER (MPI_COMM_WORLD, ierror)
c$$$
c$$$      if (myproc .eq. 0) time = MPI_WTIME ()
c$$$
c$$$      do i=1, iter
c$$$         product = pblas_dotprod (nglobal, a, b, desc)
c$$$      enddo
c$$$
c$$$      call MPI_BARRIER (MPI_COMM_WORLD, ierror)
c$$$
c$$$      if (myproc .eq. 0) then
c$$$         time = MPI_WTIME () - time
c$$$         mflops = 1.0d-6 * (2 * nglobal - 1) * iter / time
c$$$         write (6,*) 'pblas_dotprod achieves ', mflops, ' Mflop/s'
c$$$         write (6,*) 'the dot product is ', product
c$$$      endif
c$$$
c$$$      call BLACS_EXIT (0)
c$$$
      call MPI_FINALIZE (ierror)
      end