2.4.3. Vectors

Up: Contents Next: Matrices Previous: The Options Database

One creates a new parallel or sequential vector, x, of global dimension M with the command

   ierr = VecCreate(MPI_Comm comm,int m,int M,Vec *x); 
where comm denotes the MPI communicator. The type of storage for the vector may be set with either calls to VecSetType() or VecSetFromOptions(). Additional vectors of the same type can be formed with
   ierr = VecDuplicate(Vec old,Vec *new); 
The commands
   ierr = VecSet(Scalar *value,Vec x); 
   ierr = VecSetValues(Vec x,int n,int *indices,Scalar *values,INSERT_VALUES); 
respectively set all the components of a vector to a particular scalar value and assign a different value to each component. More detailed information about PETSc vectors, including their basic operations, scattering/gathering, index sets, and distributed arrays, is discussed in Chapter Vectors and Distributing Parallel Data .

Note the use of the PETSc variable type Scalar in this example. The Scalar is simply defined to be double in C/C++ (or correspondingly double precision in Fortran) for versions of PETSc that have not been compiled for use with complex numbers. The Scalar data type enables identical code to be used when the PETSc libraries have been compiled for use with complex numbers. Section Complex Numbers discusses the use of complex numbers in PETSc programs.


Up: Contents Next: Matrices Previous: The Options Database