[petsc-dev] how to print with PescPrintf a PetscScalar value?
Jed Brown
jedbrown at mcs.anl.gov
Wed Jul 4 03:20:28 CDT 2012
On Wed, Jul 4, 2012 at 12:15 AM, Luigia Ambrosio
<ambrosio.luigia at gmail.com>wrote:
> this is the source code (very simple)
> Vec x;
> PetscInt n = 10;
> PetscErrorCode ierr;
> PetscScalar one = 1.0;
>
> ierr = VecCreateMPI(PETSC_COMM_WORLD, PETSC_DECIDE, n, &x);CHKERRQ(ierr);
> ierr = VecSet(x,one);CHKERRQ(ierr);
> PetscScalar sum=0.0;
> ierr = VecSum(x,&sum);CHKERRQ(ierr);
> ierr = PetscPrintf(PETSC_COMM_WORLD,"sum %f\n",(PetscRealPart)sum);
>
Use PetscRealPart(sum), it is a function, not a type.
> CHKERRQ(ierr); puts("");
>
This puts will be issued by every process, leading to messy output,
especially for larger runs. Just add a second \n to the string passed to
PetscPrintf() if you want another newline.
> ...
>
> and this is the error message I get trying make myex
> error: 'PetscRealPart' was not declared in this scope
>
> this is how I compile myex
> myex: myex.o chkopts
> -${CLINKER} -o myex myex.o ${PETSC_VEC_LIB}
> ${RM} -f myex.o
>
> I have petsc 3.3 developer version
>
> Luigia Ambrosio
>
> Se la gente ferisce è perchè tu sei migliore e lo capisce bene! - Tiziano
> Ferro
>
>
>
>
> Il giorno 04/lug/2012, alle ore 09:58, Jed Brown ha scritto:
>
> On Tue, Jul 3, 2012 at 11:53 PM, Luigia Ambrosio <
> ambrosio.luigia at gmail.com> wrote:
>
>> It seems I don't have this function. I checked my configuring options, in
>> particular
>> --with-scalar-type=complex
>>
>
> Which version of PETSc? Can you send the full error message?
>
>
>>
>> so I'm sure that a PetscScalar variable is handled as a complex number. I
>> tried to use the PetscRealPart but it says:
>> error: 'PetscRealPart' was not declared in this scope
>>
>> I included also the header "petscmat.h" but there isn't defined this
>> function.
>> It seems that I don't include the right header, I googled it but I didn't
>> find it. Which header shiuld I include?
>>
>
> That header includes petscmath.h (which you should not include directly).
>
>
>> thanks
>>
>> Luigia Ambrosio
>>
>> Se la gente ferisce è perchè tu sei migliore e lo capisce bene! - Tiziano
>> Ferro
>>
>>
>>
>>
>> Il giorno 04/lug/2012, alle ore 09:28, Jed Brown ha scritto:
>>
>> On Tue, Jul 3, 2012 at 11:26 PM, Luigia Ambrosio <
>> ambrosio.luigia at gmail.com> wrote:
>>
>>> Is there a function already avilable to get the real part of a
>>> petscscalar value?
>>>
>>>
>> PetscRealPart() and PetscImaginaryPart()
>>
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20120704/79f08c74/attachment.html>
More information about the petsc-dev
mailing list