<html><head></head><body><div style="color:#000; background-color:#fff; font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:10px">Hello,<br id="yui_3_16_0_ym19_1_1506627721212_3318"><br id="yui_3_16_0_ym19_1_1506627721212_3319">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.<br id="yui_3_16_0_ym19_1_1506627721212_3320"><br id="yui_3_16_0_ym19_1_1506627721212_3321">This is how far I am and includes my questions:<br id="yui_3_16_0_ym19_1_1506627721212_3322"><br id="yui_3_16_0_ym19_1_1506627721212_3323">...<br id="yui_3_16_0_ym19_1_1506627721212_3324">#include <petscvec.h><br id="yui_3_16_0_ym19_1_1506627721212_3325"><br id="yui_3_16_0_ym19_1_1506627721212_3326"><br id="yui_3_16_0_ym19_1_1506627721212_3327">// vector x, rhs size n; "matrix" is the matrix from the physics application<br id="yui_3_16_0_ym19_1_1506627721212_3328">PetscMPIInt n = matrix.diag().size();<br id="yui_3_16_0_ym19_1_1506627721212_3329"><br id="yui_3_16_0_ym19_1_1506627721212_3330">Vec            rhs; // Question 1: How to set the value type to double?<br id="yui_3_16_0_ym19_1_1506627721212_3331">VecSetSizes(rhs, n, PETSC_DECIDE); // Question 2: What is "global size"?<br id="yui_3_16_0_ym19_1_1506627721212_3332"><br id="yui_3_16_0_ym19_1_1506627721212_3333">Vec            x;<br id="yui_3_16_0_ym19_1_1506627721212_3334">VecSetSizes(x, n, PETSC_DECIDE);<br id="yui_3_16_0_ym19_1_1506627721212_3335"><br id="yui_3_16_0_ym19_1_1506627721212_3336"><br id="yui_3_16_0_ym19_1_1506627721212_3337"><br id="yui_3_16_0_ym19_1_1506627721212_3338"><br id="yui_3_16_0_ym19_1_1506627721212_3339">// Question 3:<br id="yui_3_16_0_ym19_1_1506627721212_3340">// How to load petsc rhs vector with data from vector (= pointer array) named rhs_source?<br id="yui_3_16_0_ym19_1_1506627721212_3341">// Current load/copy syntax is:    fast_copy(rhs_source.begin(), rhs_source.end(), rhs.begin());<br id="yui_3_16_0_ym19_1_1506627721212_3342"><br id="yui_3_16_0_ym19_1_1506627721212_3343"><br id="yui_3_16_0_ym19_1_1506627721212_3344"><br id="yui_3_16_0_ym19_1_1506627721212_3345">// Question 4:<br id="yui_3_16_0_ym19_1_1506627721212_3346">// How to export petsc result vector x i.e. load the result x into array named x_result?<br id="yui_3_16_0_ym19_1_1506627721212_3347">// Current load/copy syntax is:    fast_copy(x.begin(), x.end(), x_result.begin());<br id="yui_3_16_0_ym19_1_1506627721212_3348"><br id="yui_3_16_0_ym19_1_1506627721212_3349"><br id="yui_3_16_0_ym19_1_1506627721212_3350"><br id="yui_3_16_0_ym19_1_1506627721212_3351">// destroy petsc vectors<br id="yui_3_16_0_ym19_1_1506627721212_3352">VecDestroy(&rhs);<br id="yui_3_16_0_ym19_1_1506627721212_3353">VecDestroy(&x);<br id="yui_3_16_0_ym19_1_1506627721212_3354">PetscFinalize();<br id="yui_3_16_0_ym19_1_1506627721212_3355"><br id="yui_3_16_0_ym19_1_1506627721212_3356">// What's the best way to copy rhs to petsc and to copy the result x back to the physics application?<div id="yui_3_16_0_ym19_1_1506627721212_3363"><br></div></div></body></html>