create parallel vectors (allocatable type question)

Barry Smith bsmith at mcs.anl.gov
Wed Apr 18 14:23:04 CDT 2007



On Wed, 18 Apr 2007, Randall Mackie wrote:

> I want to create a doubly-indexed MPI global vector in my Fortran code,
> but I won't know the number to create until I start the program (it is
> model dependent). In Fortran, I would use allocatable type statements,
> and just allocate the number once known. (This is different from allocating
> the length of the vector).
> 
> If I knew I wanted 5 of these, I could say:
> 
> 	Vec	X(5)
> 
> And then create them later with calls to VecCreateMPI, and VecDuplicate, for
> example.
> 
> In my case, I want to do something like:
> 
> 	Vec 	X(:)
> 
> And then determine the number later in my code.

  You can use fortran allocation, I think something like

   Vec, pointer :: X(:)
   n = 22
   allocate(X(n))

   VecCreate(....,x(2),ierr)

   Barry

> 
> Is there a way to do this that I'm just overlooking? Do I just need to
> use a larger number than expected, and then create only the number
> of vectors actually needed later on with VecCreateMPI and VecDuplicate?
> 
> Thanks, Randy
> 
> 




More information about the petsc-users mailing list