[petsc-users] How to copy vectors to/from petsc?

Klaus Burkart k_burkart at yahoo.com
Thu Sep 28 14:43:38 CDT 2017


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?
VecSetSizes(rhs, n, PETSC_DECIDE); // Question 2: What is "global size"?

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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20170928/dcd0a3c5/attachment.html>


More information about the petsc-users mailing list