# Printing variables for debugging

**URL:** <https://pyfr.discourse.group/t/printing-variables-for-debugging/37>\
**Category:** General\
**Created:** [1 July 2014 15:49 UTC](https://pyfr.discourse.group/t/printing-variables-for-debugging/37 "2014-07-01T15:49:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Castel\_Kevin](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Castel\_Kevin](https://pyfr.discourse.group/u/Castel_Kevin)\
**Post date:** [1 July 2014 15:49 UTC](https://pyfr.discourse.group/t/printing-variables-for-debugging/37/1 "2014-07-01T15:49:45Z")

</div>

Hi all,

I'm currently working with Peter and Antony on implementing enthalpy damping into PyFR to reduce the start up period.

Could anyone tell me how to print the content of a PyFR variable in the console or in an output file for debugging?

Thanks in advance for your help!

Cheers,

Kevin

---

<div class="post-metadata">

**Author:** ![fdw](https://avatars.discourse-cdn.com/v4/letter/f/a587f6/32.png) [@fdw](https://pyfr.discourse.group/u/fdw)\
**Post date:** [1 July 2014 16:29 UTC](https://pyfr.discourse.group/t/printing-variables-for-debugging/37/2 "2014-07-01T16:29:19Z")

</div>

Hi Kevin,

> I'm currently working with Peter and Antony on implementing enthalpy  
> damping into PyFR to reduce the start up period.
> 
> Could anyone tell me how to print the content of a PyFR variable in  
> the console or in an output file for debugging?

It depends what you mean by a "PyFR variable". If this is simply a  
Python variable then you can use a regular Python print statement to  
output it to the console. Alternatively, if you are only running with a  
single MPI rank you can drop into IPython:

&nbsp;&nbsp;import IPython; IPython.embed()

which is often easier and more convenient as you can "look around" and  
see exactly what is going on.

Otherwise, if it is a variable in a kernel things are a little bit more  
difficult. When it comes to debugging "kernels" (and I use the term  
loosely!) I am inclined to agree with Linus Torvalds on the issue [1].  
All of the kernels in PyFR were written without the use of either a  
debugger or print statements. If you're being careful you shouldn't  
need either.

However, although officially not supported, you can on occasion utilise  
`printf(...)` inside of the CUDA and C/OpenMP backends. I must warn you  
that this is not officially supported and is known to break under a wide  
range of circumstances. Caveat emptor...

If outside of the kernel/macro definition you put:

`#include <stdio.h>`

you should be able to---inside of your kernel/macro---do

`printf("%f\n", myvar);`

of course the order in which these printf statements come out to the  
console is effectively random.

Regards, Freddie.

[1] [linus-im-a-bastard-speech](http://linuxmafia.com/faq/Kernel/linus-im-a-bastard-speech.html)

---

<div class="post-metadata">

**Author:** ![Castel\_Kevin](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Castel\_Kevin](https://pyfr.discourse.group/u/Castel_Kevin)\
**Post date:** [1 July 2014 18:00 UTC](https://pyfr.discourse.group/t/printing-variables-for-debugging/37/3 "2014-07-01T18:00:55Z")

</div>

Hi Freddie,

Thank you for you answer, it does work.

I also had a look at the link you shared, which was an interesting reading. Don't worry, I don't plan on printing everything all the time.

Thank you once more for your time.

Best,

Kevin
