<div dir="ltr">Hi Stefano and PETSc dev team,<div> I want to try your suggestion to always load complex version of PETSc but if my input matrix A is real, I want to create shell matrix to matrix-vector and factorization using real only.</div><div> I still need to understand how MatRealPart works. Does it just zero out the image numerical values or does it delete the image memory? If my input matrix A is real, how do I create a shell matrix to matrix -vector multiplication y=A*x where A is real, PestcScalar = complex, x and y are Vec? I notice there is a VecRealPart but it seems it just zeros the image numerical values. It seems I still have to create a PetscReal pointer to copy the real part of PetacScalar pointers like following. Can you comment on it?</div><div><br></div><div>Thanks,</div><div>Sam</div><div><br></div><div>PetscScalar *px = nullptr;</div><div>VecGetArrayRead(x, &px);</div><div>PetscScalar *py = nullptr;</div><div>VecGetArray(y, &py);</div><div>int localSize = 0;</div><div>VecGetLocalSize(x, &localSize);</div><div>std::vector<PetasReal> realX(localSize); // I am using c++ to call PETSc</div><div><br></div><div>//retrieve real part </div><div>for(int i = 0; i < localSize; i++) realX[i] = PetscRealPart(px[i]);</div><div><br></div><div>// do real matrix-vector multiplication </div><div>// realY=A*realX </div><div>// here where realY is std::vector<PetscReal></div><div><br></div><div>//put real part back to py</div><div> for(int i = 0; i < localSize; i++) pv[i] = realY[i]; <br></div><div>VecRestoreArray(y,&py);</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 26, 2020 at 1:49 PM Sam Guo <<a href="mailto:sam.guo@cd-adapco.com">sam.guo@cd-adapco.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Thanks<br><br>On Tuesday, May 26, 2020, Stefano Zampini <<a href="mailto:stefano.zampini@gmail.com" target="_blank">stefano.zampini@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;">All the solvers/matrices/vectors works for PetscScalar types (i.e. in your case complex)<div>If you need to solve for the real part only, you can duplicate the matrix and call MatRealPart to zero out the imaginary part. But the solve will always run in the complex space</div><div>You should not be worried about doubling the memory for a matrix (i.e. real and imaginary part)</div><div><br><div><br><blockquote type="cite"><div>On May 26, 2020, at 11:28 PM, Sam Guo <<a href="mailto:sam.guo@cd-adapco.com" target="_blank">sam.guo@cd-adapco.com</a>> wrote:</div><br><div>complex version is needed since matrix sometimes is real and sometimes is complex. I want to solve real matrix without allocating memory for imaginary part((except eigen pairs).<br><br>On Tuesday, May 26, 2020, Zhang, Hong <<a href="mailto:hzhang@mcs.anl.gov" target="_blank">hzhang@mcs.anl.gov</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt">
You can build PETSc with complex <span style="color:rgb(50,49,48);background-color:rgb(255,255,255);display:inline">
version</span>, and declare some variables as 'PETSC_REAL'.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt">
Hong</div>
<div></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt">
<br>
</div>
<hr style="display:inline-block;width:98%">
<div dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt"><b>From:</b> petsc-users <<a href="mailto:petsc-users-bounces@mcs.anl.gov" target="_blank">petsc-users-bounces@mcs.anl.gov</a>> on behalf of Sam Guo <<a href="mailto:sam.guo@cd-adapco.com" target="_blank">sam.guo@cd-adapco.com</a>><br>
<b>Sent:</b> Tuesday, May 26, 2020 1:00 PM<br>
<b>To:</b> PETSc <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>><br>
<b>Subject:</b> [petsc-users] using real and complex together</font>
<div> </div>
</div>
<div>
<div dir="ltr">Dear PETSc dev team,
<div> Can I use both real and complex versions together?</div>
<div><br>
</div>
<div>Thanks,</div>
<div>Sam</div>
</div>
</div>
</div>
</blockquote>
</div></blockquote></div><br></div></div></blockquote>
</blockquote></div>