      program solvetri
*
*     example program solving ax=b via scalapack routine pddtsv
*
      integer n, nb, np, lwork
      parameter (n = 10000000, np = 2, nb = 5000000, lwork = 15000048)

      integer            mycol, myrow
      integer            ictxt, info

      integer            desca(7), descb(7)
      double precision   d(nb), du(nb), dl(nb), b(nb)
      double precision   work(lwork)

*     initialize the process grid
      call sl_init( ictxt, 1, np )
      call blacs_gridinfo( ictxt, 1, np, myrow, mycol )

*     initialize the array descriptors for a = du/d/dl and b
      call descinit_col(desca, n, nb, 0, ictxt, 1, info)
      call descinit_row(descb, n, nb, 0, ictxt, nb, info)

*     generate distributed matrices a and b
      call triinit(d, du, dl, desca)
      call rhsinit(b, descb)

*     solve the linear system a * x = b
      call pddtsv(n, 1, dl, d, du, 1, desca, b, 1, descb, work, lwork, info)

*     check: print the last 20 or so entries of the result
      call printlast(b, descb)

      call blacs_gridexit( ictxt )
      call blacs_exit( 0 )
      end

