<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 11 May 2021, at 6:26 PM, Matthew Knepley <<a href="mailto:knepley@gmail.com" class="">knepley@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta charset="UTF-8" class=""><div dir="ltr" style="caret-color: rgb(0, 0, 0); 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; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><div dir="ltr" class="">On Tue, May 11, 2021 at 12:03 PM Pierre Jolivet <<a href="mailto:pierre@joliv.et" class="">pierre@joliv.et</a>> wrote:<br class=""></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div style="overflow-wrap: break-word;" class="">Hello Frederico,<div class="">I’m not sure that’s possible.</div><div class="">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 class="">In MATLAB (after putting petsc/share/petsc/matlab in the path):</div><div class="">A = PetscBinaryRead('your_binary_mat_with_re+im.dat','complex',true); % scalar-type=complex</div><div class="">PetscBinaryWrite('re.dat',real(A)); % scalar-type=real</div><div class="">PetscBinaryWrite('im.dat',imag(A)); % scalar-type=real</div></div></blockquote><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">The hard part is that the MatLoad interface returns a single matrix.</div></div></div></div></blockquote><div><br class=""></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" class="">https://gitlab.com/petsc/petsc/-/issues/901</a>.</div><div><br class=""></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" class="">https://www.mcs.anl.gov/petsc/petsc-3.15.0/src/mat/impls/aij/seq/aij.c.html#line4811</a> and replace <span style="orphans: 2; widows: 2;" class="">PETSC_SCALAR line 4861 by PETSC_COMPLEX.</span></div><div><span style="orphans: 2; widows: 2;" class="">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><br class=""></div><div>Thanks,</div><div>Pierre</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="caret-color: rgb(0, 0, 0); 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; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><div class="gmail_quote"><div class="">I guess we could have a flag that says what to do with complex numbers (read real, read imaginary, read norm, etc.)</div><div class="">and you could read it twice. Would that work?</div><div class=""><br class=""></div><div class=""> <span class="Apple-converted-space"> </span>Thanks,</div><div class=""><br class=""></div><div class=""> Matt</div><div class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div style="overflow-wrap: break-word;" class=""><div class="">Thanks,</div><div class="">Pierre</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 11 May 2021, at 3:30 PM, Frederico Teixeira <<a href="mailto:teixeira@zmt.swiss" target="_blank" class="">teixeira@zmt.swiss</a>> wrote:</div><br class=""><div class=""><div class=""><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt;" class=""><div class=""><div class=""><div class=""><div class="">Dear fellows,<br class=""></div></div></div></div><div class=""><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);" class=""><div class=""><br class=""></div><div class="">I hope this message finds you safe and well.</div><div class=""><br class=""></div><div class="">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;" class=""> </span><span style="font-size: 12pt;" class="">a complex-valued matrix and its real/imaginary components<span class=""> </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;" class="">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;" class="">binary format</span></span><span style="font-size: 12pt;" class="">. They were extracted from a solver that only works with "scalar-type=complex" configuration.</span></div><div class="">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 class="">At the end of the day, I would like to have both real and imaginary components as real-valued matrices.</div><div class="">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;" class=""> test preconditioners that are tailored for this sort of problem.</span></div><div class=""><br class=""></div><div class="">Regards,</div><div class=""> 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);" class=""></span><div style="clear: both;" class=""><br class=""></div></div></div></div></div></blockquote></div><br class=""></div></div></blockquote></div><br clear="all" class=""><div class=""><br class=""></div>--<span class="Apple-converted-space"> </span><br class=""><div dir="ltr" class="gmail_signature"><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class="">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br class="">-- Norbert Wiener</div><div class=""><br class=""></div><div class=""><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank" class="">https://www.cse.buffalo.edu/~knepley/</a></div></div></div></div></div></div></div></div></div></blockquote></div><br class=""></body></html>