10.1.6. Duplicating Multiple Vectors

Up: Contents Next: Matrix and Vector Indices Previous: Passing Null Pointers

The Fortran interface to VecDuplicateVecs() differs slightly from the C/C++ variant because Fortran does not allow arrays to be returned in routine arguments. To create n vectors of the same format as an existing vector, the user must declare a vector array, v_new of size n. Then, after VecDuplicateVecs() has been called, v_new will contain (pointers to) the new PETSc vector objects. When finished with the vectors, the user should destroy them by calling VecDestroyVectors(). For example, the following code fragment duplicates v_old to form two new vectors, v_new(1) and v_new(2).

   Vec     v_old, v_new(2) 
   integer ierr 
   Scalar  alpha 
   .... 
   call VecDuplicateVecs(v_old,2,v_new,ierr) 
   alpha = 4.3 
   call VecSet(alpha,v_new(1),ierr) 
   alpha = 6.0 
   call VecSet(alpha,v_new(2),ierr) 
   .... 
   call VecDestroyVecs(v_new,2,ierr) 


Up: Contents Next: Matrix and Vector Indices Previous: Passing Null Pointers