<div dir="ltr"><div>Thank Barry for the clarification.</div><div>In summary, application code developers should choose the specific datatypes (PetscReal and PetscComplex) rather than the more general datatype PetscScalar</div><div>because application codes usually have fixed datatype and the flexibility provided by PetscScalar is for PETSc library developers and usually not for application developers.</div><div>If an application developer uses PetscScalar to declare a variable that is intended by the developer to be complex and is assigned a complex value later in the code and then used in, e.g., MatSetValues, but it happens that petsc is configured with --with-scalar-type=real</div><div>then, it is not possible for this error to be detected at compiling time. If the developer specify PetscComplex, then this inconsistency can be seen by compilers and hopefully an error message can be raised during compiling.</div><div><br></div><div>Conclusion: avoid using PetscScalar in application codes unless it is absolutely needed (which is not common). The example application codes provided in tutor folds of petsc often use PetscScalar, which is a little misleading and should better be revised to use concrete datatypes.<br></div><div>Correct me if anybody finds this conclusion is not justified.<br></div><div><br></div><div>Cheers,</div><div>Youjun<br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Sat, Aug 4, 2018 at 11:03 AM Smith, Barry F. <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
For a particular configuration (./configure --with-scalar-type= real or complex) the PETSc objects, such as vectors and matrices either contain real values or complex values. In the same running code it is not possible to have some vectors with real numbers and some vectors with complex numbers.<br>
<br>
Depending on how you configure PETSc ./configure --with-scalar-type= real or complex the variable name PetscScalar becomes either PetscReal or PetscComplex. PETSc code is written with PetscScalar so we can reconfigure the same source code and have it work with real numbers or complex.<br>
<br>
For users who just work with real numbers you can simply use PetscReal as your variable type. If working with just with complex numbers you can use PetscComplex. If you want to sometimes configure with real numbers and sometimes configure with complex (which is not common) you use PetscScalar. <br>
<br>
Barry<br>
<br>
<br>
> On Aug 4, 2018, at 11:39 AM, Youjun Hu <<a href="mailto:youjunhu@gmail.com" target="_blank">youjunhu@gmail.com</a>> wrote:<br>
> <br>
> Hi all,<br>
> <br>
> I am just wondering why PETSc introduces PetscScalar datatype in addition to the PetscReal and PetscComplex.<br>
> Could someone help clarify the rationale behind this design?<br>
> I am primarily a Fortran guy. The additional datatype PetscScalar seems to only confuse me rather than provide me any flexibility.<br>
> Cheers,<br>
> Youjun Hu<br>
<br>
</blockquote></div>