On Thu, 28 Sep 2017, Karl Rupp wrote: > Hi Klaus, > > there are several options, e.g.: > * > http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecCreateSeqWithArray.html > (sequential)
For parallel http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecCreateMPIWithArray.html > * > http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecSetValues.html > (use with multiple MPI ranks if you cannot easily determine the local parts) > * > http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGetArray.html > (get a pointer to the data and assign values yourself) > > Best regards, > Karli > > > On 09/28/2017 02:43 PM, Klaus Burkart wrote: > > Hello, > > > > I want to solve a physics problem with support of petsc i.e. solve the > > linear system using petsc. So far I have been using another linear algebra > > library. I am using c++. Now I am struggling to load the rhs vector/array > > from the physics application to petsc and copying the result x back to the > > physics application. I found information about how to load data from > > binaries or from files but both is not the case here. The computation will > > take place on a multi core CPU using MPI. > > > > This is how far I am and includes my questions: > > > > ... > > #include <petscvec.h> > > > > > > // vector x, rhs size n; "matrix" is the matrix from the physics application > > PetscMPIInt n = matrix.diag().size(); > > > > Vec rhs; // Question 1: How to set the value type to double? PETSc provides configure options --with-precision=single,double,.. --with-scalar-type=real,complex We default to double precision real values. The corresponding datatype is PetscScalar > > VecSetSizes(rhs, n, PETSC_DECIDE); // Question 2: What is "global size"? Sum of local sizes - when running parallely. Satish > > > > Vec x; > > VecSetSizes(x, n, PETSC_DECIDE); > > > > > > > > > > // Question 3: > > // How to load petsc rhs vector with data from vector (= pointer array) > > named rhs_source? > > // Current load/copy syntax is: fast_copy(rhs_source.begin(), > > rhs_source.end(), rhs.begin()); > > > > > > > > // Question 4: > > // How to export petsc result vector x i.e. load the result x into array > > named x_result? > > // Current load/copy syntax is: fast_copy(x.begin(), x.end(), > > x_result.begin()); > > > > > > > > // destroy petsc vectors > > VecDestroy(&rhs); > > VecDestroy(&x); > > PetscFinalize(); > > > > // What's the best way to copy rhs to petsc and to copy the result x back to > > the physics application? > > >