      subroutine matinit( aa, desca, b, descb )
*
*     setup local matrices for a and b
*
*     globally: a(i,j) = i + j + n*delta(i,j)
*               b(i) = 2*i
*
      integer            desca( * ), descb( * )
      double precision   aa( * ), b( * )

      integer            m, n, mb, nb, lda
      integer            ictxt, mycol, myrow, npcol, nprow
      integer            mloc, nloc, bloc
      integer            i,j, iglob, jglob

* get matrix and grid infos
      ictxt = desca(2)
      m     = desca(3)
      n     = desca(4)
      mb    = desca(5)
      nb    = desca(6)
      lda   = desca(9)
      call blacs_gridinfo(ictxt, nprow, npcol, myrow, mycol)
      mloc = numroc(m, mb, myrow, 0, nprow)
      nloc = numroc(n, nb, mycol, 0, npcol)
      bloc = numroc(n, nb, myrow, 0, nprow)

******

* compute array values
      do i=1, mloc
         do j=1, nloc
            iglob = indxl2g(i, mb, myrow, 0, nprow)
            jglob = indxl2g(j, nb, mycol, 0, npcol)
            aa(i + lda*(j-1)) = iglob + jglob 
            if (iglob .eq. jglob) then
               aa(i + lda*(j-1)) = aa(i + lda*(j-1)) + n
            endif
         enddo
      enddo

      do i=1, bloc
         iglob = indxl2g(i, nb, myrow, 0, nprow)
         b(i) = 2*iglob
      enddo

      return
      end
