<div dir="ltr"><div dir="ltr">On Wed, May 12, 2021 at 2:17 AM Pierre Jolivet <<a href="mailto:pierre@joliv.et">pierre@joliv.et</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;"><br><div><br><blockquote type="cite"><div>On 11 May 2021, at 6:26 PM, Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>> wrote:</div><br><div><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div dir="ltr">On Tue, May 11, 2021 at 12:03 PM Pierre Jolivet <<a href="mailto:pierre@joliv.et" target="_blank">pierre@joliv.et</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>Hello Frederico,<div>I’m not sure that’s possible.</div><div>Here is what I do, it makes me sick, but mixing precisions/scalar types with PETSc is difficult (crossing my fingers this will be better with future).</div><div>In MATLAB (after putting petsc/share/petsc/matlab in the path):</div><div>A = PetscBinaryRead('your_binary_mat_with_re+im.dat','complex',true); % scalar-type=complex</div><div>PetscBinaryWrite('re.dat',real(A)); % scalar-type=real</div><div>PetscBinaryWrite('im.dat',imag(A)); % scalar-type=real</div></div></blockquote><div><br></div><div>So what you want to happen is that MatLoad() looks at the datatype, sees that it is complex and PetscScalar is real, and returns two matrices with the real and imaginary parts?</div><div><br></div><div>The hard part is that the MatLoad interface returns a single matrix.</div></div></div></div></blockquote><div><br></div><div>There is Mat[Real,Imaginary]Part(), maybe there could be Mat[Real,Imaginary]PartLoad()?</div><div>It will be inefficient (complex Mat read twice in a very naive implementation), but functional and would not require tinkering with the options (but maybe you had something clear in mind).</div><div>Also, just for reference, <a href="https://gitlab.com/petsc/petsc/-/issues/901" target="_blank">https://gitlab.com/petsc/petsc/-/issues/901</a>.</div><div><br></div><div>Frederico, as Barry wrote, it will work with Octave or Python. In fact, it will work in any code that does not include petsc.h or link to libpetsc.</div><div>If you want to stick to C, I think you could simply copy/paste the MatLoad_SeqAIJ_Binary() implementation <a href="https://www.mcs.anl.gov/petsc/petsc-current/src/mat/impls/aij/seq/aij.c.html#line4811" target="_blank">https://www.mcs.anl.gov/petsc/petsc-3.15.0/src/mat/impls/aij/seq/aij.c.html#line4811</a> and replace <span>PETSC_SCALAR line 4861 by PETSC_COMPLEX.</span></div><div><span>Then, as Matt wrote, instead of assembling a single Mat, assemble two Mats by splitting a->a in two PetscScalar arrays (remember that this is for your scalar-type=real configuration).</span></div></div></div></blockquote><div><br></div><div>Should this make two matrices, or the equivalent real matrix?</div><div><br></div><div>  / R Q \</div><div> \ -Q R /</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 style="overflow-wrap: break-word;"><div><div>Thanks,</div><div>Pierre</div><br><blockquote type="cite"><div><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div class="gmail_quote"><div>I guess we could have a flag that says what to do with complex numbers (read real, read imaginary, read norm, etc.)</div><div>and you could read it twice. Would that work?</div><div><br></div><div> <span> </span>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><div>Thanks,</div><div>Pierre</div><div><br><div><blockquote type="cite"><div>On 11 May 2021, at 3:30 PM, Frederico Teixeira <<a href="mailto:teixeira@zmt.swiss" target="_blank">teixeira@zmt.swiss</a>> wrote:</div><br><div><div><div style="font-family:arial,helvetica,sans-serif;font-size:12pt"><div><div><div><div>Dear fellows,<br></div></div></div></div><div><div style="font-family:arial,helvetica,sans-serif;font-size:16px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255)"><div><br></div><div>I hope this message finds you safe and well.</div><div><br></div><div>I have<span style="font-family:arial,helvetica,sans-serif;font-size:16px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);float:none;display:inline"> </span><span style="font-size:12pt">a complex-valued matrix and its real/imaginary components<span> </span><span style="font-family:arial,helvetica,sans-serif;font-size:16px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);float:none;display:inline">in </span><span style="font-family:arial,helvetica,sans-serif;font-size:16px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);float:none;display:inline">binary format</span></span><span style="font-size:12pt">. They were extracted from a solver that only works with "scalar-type=complex" configuration.</span></div><div>I am getting weird results when I load them into a small test program that's configured with "scalar-type=real", but I believe this is expected.</div><div>At the end of the day, I would like to have both real and imaginary components as real-valued matrices.</div><div>Is it possible to do it? I want to<span style="font-family:arial,helvetica,sans-serif;font-size:16px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);float:none;display:inline"> test preconditioners that are tailored for this sort of problem.</span></div><div><br></div><div>Regards,</div><div> Frederico.</div></div><span style="font-family:arial,helvetica,sans-serif;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;font-size:11pt;background-color:rgb(255,255,255)"></span><div style="clear:both"><br></div></div></div></div></div></blockquote></div><br></div></div></blockquote></div><br clear="all"><div><br></div>--<span> </span><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></div></div></div></div></div></div></div></div></div></blockquote></div><br></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>