[petsc-users] Why PETSc needs PetscScalar datatype?

Youjun Hu youjunhu at gmail.com
Sat Aug 4 15:02:02 CDT 2018


When having lunch at a garden under wonderful autumn sky, I realized that
the tutorial examples are designed to test both the real and complex
versions and thus they must be general enough. My complaint about the
tutourial examples are not justified.
Cheers,
Youjun


On Sat, Aug 4, 2018 at 12:37 PM Dave May <dave.mayhem23 at gmail.com> wrote:

>
>
> On 4 August 2018 at 19:11, Youjun Hu <youjunhu at gmail.com> wrote:
>
>> Thank Barry for the clarification.
>> In summary, application code developers should choose the specific
>> datatypes (PetscReal and PetscComplex) rather than the more general
>> datatype PetscScalar
>> because application codes usually have fixed datatype and the flexibility
>> provided by PetscScalar is for PETSc library developers and usually not for
>> application developers.
>> 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
>> 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.
>>
>> 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.
>> Correct me if anybody finds this conclusion is not justified.
>>
>
> Not justified.
>
> Tutorial examples serve several purposes:
>
> 1/ To illustrate the point Barry made. e.g. they demonstrate how a user
> can write a single application code which works with both complex and real
> configurations.
>
> 2/ The examples are also used in the testing suite which employs a
> multitude of petsc configuration combinations, e.g single precision
> {real,complex|, double precision {real,complex}, __float128.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20180804/c809b2c7/attachment.html>


More information about the petsc-users mailing list