[petsc-users] Inquiry about the PetscScalar in Petsc.

Barry Smith bsmith at petsc.dev
Tue Jul 11 11:41:45 CDT 2023



> On Jul 11, 2023, at 12:16 PM, neil liu <liufield at gmail.com> wrote:
> 
> I think I understood that.
> 
> 1) In order to save memory, use a larger real system

   This will save a little memory, but requires a slight change to your model/code for your problem

> 2) vec will store the real part with imaginary part equal to zero in the context of --scalar =complex. But this will not save memory. 

    This will waste a little memory.

    Usually, coordinates do not take much of the total memory, that is solution vectors, matrices, intermediate work vectors for the solver take most of the memory
so I suggest just using complex and not worrying about the few percent memory lost.


> 
> Right? 
> 
> Thanks, 
> 
> Xiaodong 
> 
> On Tue, Jul 11, 2023 at 12:03 PM neil liu <liufield at gmail.com <mailto:liufield at gmail.com>> wrote:
>> Do you mean that, 
>> 
>> even if I configure with --scalar=complex, when I use vecGetarray to get the coords, the coords array is still stored in a real manner? 
>> 
>> Thanks, 
>> 
>> Xiaodong 
>> 
>> On Tue, Jul 11, 2023 at 11:54 AM Matthew Knepley <knepley at gmail.com <mailto:knepley at gmail.com>> wrote:
>>> On Tue, Jul 11, 2023 at 11:48 AM neil liu <liufield at gmail.com <mailto:liufield at gmail.com>> wrote:
>>>> Thanks for your reply. 
>>>> I am using DMPLEX to read GMSH. And it seems I have to use 
>>>> DMGetCoordinatesLocal();
>>>> VecGetArray(veccords, &coords);//it seems coords has to be defined by complex either.
>>>> 
>>>> 2) Store the coordinates in coords with imaginary part equal to zero. 
>>>> I got the coordinates from above function VecGetArray, therefore will this reduce the memory? 
>>>> 
>>>> 3) is a good way to work around that. 
>>> 
>>> We just store them with real part 0.
>>> 
>>>   Thanks,
>>> 
>>>     Matt
>>>  
>>>> On Tue, Jul 11, 2023 at 11:40 AM Barry Smith <bsmith at petsc.dev <mailto:bsmith at petsc.dev>> wrote:
>>>>> 
>>>>>   Not really. PetscScalar (and entries of vectors etc) are either real or complex, they cannot be mixed. 
>>>>> 
>>>>>   What parts of PETSc are you using, DM? 
>>>>> 
>>>>>   You can 
>>>>> 
>>>>> 1) store the coordinates in arrays and not use Vec for them. (of if you are not using DM)
>>>>> 2) sore them in Vec but with imaginary part 0 
>>>>> 3) rewrite your complex systems as real systems (with twice as many unknowns, but only real ones)
>>>>> 
>>>>>   Barry
>>>>> 
>>>>> 
>>>>> > On Jul 11, 2023, at 11:34 AM, neil liu <liufield at gmail.com <mailto:liufield at gmail.com>> wrote:
>>>>> > 
>>>>> > Dear Petsc developers,
>>>>> > 
>>>>> > My computation involves both real and complex numbers. 
>>>>> > For example, my coordinate is real, but my matrix is complex. 
>>>>> > 
>>>>> > I use VecGetArray to get the coordinates. But it seems coordinates have to be defined in a complex manner to be consistent with complex matrix. 
>>>>> > 
>>>>> > Is there some ways to work around this if I understood correctly ?
>>>>> > 
>>>>> > Thanks, 
>>>>> > 
>>>>> > Xiaodong 
>>>>> > 
>>>>> > 
>>>>> > 
>>>>> 
>>> 
>>> 
>>> -- 
>>> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.
>>> -- Norbert Wiener
>>> 
>>> https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20230711/2c01959c/attachment-0001.html>


More information about the petsc-users mailing list