<div dir="ltr"><div dir="ltr">On Mon, Sep 28, 2020 at 8:15 PM Randall Mackie <<a href="mailto:rlmackie862@gmail.com">rlmackie862@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><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;">Sam, you can solve a complex matrix using a real version of PETSc by doubling the size of your matrix and spitting out real/imaginary parts.<div><br><div>See this paper:</div><div><br></div><div><a href="https://epubs.siam.org/doi/abs/10.1137/S1064827500372262?mobileUi=0" target="_blank">https://epubs.siam.org/doi/abs/10.1137/S1064827500372262?mobileUi=0</a></div></div></div></blockquote><div><br></div><div>Thanks Randy. Yes, I meant that one.</div><div><br></div><div> Matt</div><div> </div><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;"><div><div>Randy M.</div><div><br><div><br><blockquote type="cite"><div>On Sep 28, 2020, at 5:12 PM, Sam Guo <<a href="mailto:sam.guo@cd-adapco.com" target="_blank">sam.guo@cd-adapco.com</a>> wrote:</div><br><div>All I want is to solve both real and complex matrix using either real or complex version of PETSc. If I load complex version of PETSc, I waste memory solving real matrix. If I can solve complex matrix using real version of PETSc, I will accept it.<br><br>On Monday, September 28, 2020, Sam Guo <<a href="mailto:sam.guo@cd-adapco.com" target="_blank">sam.guo@cd-adapco.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">If I load complex version of PETSc, how can Vec be real?<br><br>On Monday, September 28, 2020, Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@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 dir="ltr"><div dir="ltr">On Mon, Sep 28, 2020 at 7:44 PM Sam Guo <<a href="mailto:sam.guo@cd-adapco.com" target="_blank">sam.guo@cd-adapco.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I want to make sure I understand you. I load real version of PETSc. If my input matrix is complex, </blockquote><div><br></div><div>You said that your matrix was real.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">just get real and imagine parts of PETSc Vec</blockquote><div><br></div><div>No, the PETSc Vec would be real. You would have two vectors.</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> and do the matrix vector multiplication. Right?<br><br>On Monday, September 28, 2020, Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@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 dir="ltr"><div dir="ltr">On Mon, Sep 28, 2020 at 6:29 PM Sam Guo <<a href="mailto:sam.guo@cd-adapco.com" target="_blank">sam.guo@cd-adapco.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">“<span style="color:rgb(34,34,34);font-size:14px"> I think it would be much easier to just decompose your complex work into real and imaginary parts and use PETSc with real scalars to compute them separately.</span><div style="color:rgb(34,34,34);font-size:14px">Since you know your matrices have 0 imaginary part, this becomes very straightforward.”</div><div style="color:rgb(34,34,34);font-size:14px"><br></div><div style="color:rgb(34,34,34);font-size:14px">I think this is what I am trying to do. But since I have to provide matrix-vector operator(since I am using shell matrix), the Vec I receive is complex. I need to convert complex vec to real one and then convert it back(that’s the code I shown before).</div></blockquote><div><br></div><div>No, this is not what I am advocating. Keep your vectors real, just keep one for the real part and one for the imaginary part. Then you can just call MatMult() twice with your matrix.</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Monday, September 28, 2020, Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@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 dir="ltr"><div dir="ltr">On Mon, Sep 28, 2020 at 5:01 PM Sam Guo <<a href="mailto:sam.guo@cd-adapco.com" target="_blank">sam.guo@cd-adapco.com</a>> wrote:<br></div><div class="gmail_quote"><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">Hi Matt,<div> Since I use MUMPS as preconditioner, complex uses too much memory if my input matrix is real. Ideally if I can compile real and complex into different symbols (like MUMPS) , I can load both version without conflict. </div></div></blockquote><div><br></div><div>What I mean to say is that it would be great if it were as simple as using two different symbols, but unfortunately the problem is more difficult. I was trying to use</div><div>the example of templates. This would be a very intrusive change no matter what technology you are using.</div><div><br></div><div>So your main memory usage is from the MUMPS factorization, and you cannot afford to double that usage?</div><div><br></div><div>You could consider writing a version of AIJ that stores real entries, but allows complex vector values. It would promote to complex for the row dot product.</div><div>However, you would also have to do the same work for all the solves you do with MUMPS.</div><div><br></div><div>I think it would be much easier to just decompose your complex work into real and imaginary parts and use PETSc with real scalars to compute them separately.</div><div>Since you know your matrices have 0 imaginary part, this becomes very straightforward.</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div><div> </div><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>Thanks,</div><div>Sam</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 28, 2020 at 12:52 PM Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.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"><div dir="ltr"><div dir="ltr">On Mon, Sep 28, 2020 at 3:43 PM Sam Guo <<a href="mailto:sam.guo@cd-adapco.com" target="_blank">sam.guo@cd-adapco.com</a>> wrote:<br></div><div class="gmail_quote"><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">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></blockquote><div><br></div><div>I do not think that will work as you expect. I will try to explain below.</div><div> </div><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> I still need to understand how MatRealPart works. Does it just zero out the image numerical values or does it delete the image memory?</div></div></blockquote><div><br></div><div>When we have complex values, we use the "complex" type to allocate and store them. Thus you cannot talk about just the memory to store imaginary parts.</div><div>MatRealPart sets the imaginary parts of all the matrix elements to zero.</div><div> </div><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> 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></blockquote><div><br></div><div>What you suggest would mean rewriting the matrix multiplication algorithm by hand after extracting the values. I am not sure if this</div><div>is really what you want to do. Is the matrix memory really your limiting factor? Even if you tried to do this with templates, the memory</div><div>from temporaries would be very hard to control.</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div><div> </div><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>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" target="_blank">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>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>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div><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.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>
</blockquote></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div><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.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>
</blockquote>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div><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.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>
</blockquote>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div><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.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>
</blockquote>
</blockquote>
</div></blockquote></div><br></div></div></div></blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><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.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>