<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Feb 13, 2018 at 10:12 AM, Ali Berk Kahraman <span dir="ltr"><<a href="mailto:aliberkkahraman@yahoo.com" target="_blank">aliberkkahraman@yahoo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">OK, here is the thing. I have a 2D cartesian regular grid. I am working on wavelet method collocation method, which creates an irregular adaptive grid by turning grid points on an off on the previously mentioned cartesian grid. I store the grid and the values as sparse Mat objects, where each entry to the matrix denotes the x and y location of the value (x:row, y:column). However, to feed the values into PETSc's solver contexts, I have to turn them into vectors.<br>
<br>
<br>
By the way, I believe I have solved the problem. For future reference who looks for this, the algorithm is as follows;<br>
<br>
For each processor,<br>
<br>
1.)Get the local number of nonzero entries on the matrix using MatGetInfo<br>
<br>
2.)Call MPI_Allgather so that every process will know exactly how many nonzero entries each other has<br>
<br>
3.)Create the Vector and set its size using the data from MPI_Allgather from step 2 (sum of all local nonzero sizes)<br></blockquote><div><br></div><div>You do not need 2) since you can just give the local size and PETSC_DETERMINE to VecSetSizes().</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
4.)Call MatMPIAIJGetLocalMat to get the local portion of the matrix, then call MatSeqAIJGetArray on the local portion to extract its nonzero values as an array<br>
<br>
5.)Using the info from step 2 and 4, set the according values on the vector (e.g. if process 0 has 4 nonzeros, process 1 will set the values on Vector's row 4 onwards)<br>
<br>
<br>
I am always open to ideas for improvements.<br>
<br>
<br>
Ali<br>
<br>
<br>
On 13-02-2018 16:46, Jed Brown wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Ali Kahraman <<a href="mailto:aliberkkahraman@yahoo.com" target="_blank">aliberkkahraman@yahoo.com</a>> writes:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Dear All,<br>
My problem definition is as follows,<br>
I have an MPI matrix with a random sparsity pattern i.e. I do not know how many nonzeros there are on any row unless I call MatGetRow to learn it. There are possibly unequal numbers of nonzeros on every row. I want to write all the nonzero values of this matrix onto a parallel vector. An example can be as follows.<br>
Imagine I have a 4x4 matrix (; denotes next row, . denotes sparse "zeros") [3 . 2 . ; . 1 . . ; 4 5 3 2; . . . .]. I want to obtain the vector [3 2 1 4 5 3 2]. I could not find any function that does this. Any idea is appreciated.<br>
</blockquote>
This seems like an odd thing to want. What are you trying to do?<br>
</blockquote>
<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.caam.rice.edu/~mk51/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div>
</div></div>