Comment 7 for bug 1072694

Revision history for this message
corrado maurini (corrado-maurini) wrote : Re: [Bug 1072694] list_timings() cannot be redirected to a file or a variable in python

Johan, I started adding Table output, but this stopped me very soon:

As soon I add
#include "Table.h"
in the log.h I have the following error at compilation:

May you give a quick explanation/solution?

Corrado
-----------------------
majorana:dorsal_build_dir maurini$ make all
[ 0%] Building CXX object dolfin/CMakeFiles/dolfin.dir/adaptivity/adapt.cpp.o
In file included from /opt/HPC/FEniCS/src/dolfin/dolfin/common/Variable.h:27,
                 from /opt/HPC/FEniCS/src/dolfin/dolfin/log/Table.h:28,
                 from /opt/HPC/FEniCS/src/dolfin/dolfin/log/log.h:32,
                 from /opt/HPC/FEniCS/src/dolfin/dolfin/log/dolfin_log.h:6,
                 from /opt/HPC/FEniCS/src/dolfin/dolfin/common/MPI.h:32,
                 from /opt/HPC/FEniCS/src/dolfin/dolfin/fem/UFCCell.h:29,
                 from /opt/HPC/FEniCS/src/dolfin/dolfin/fem/FiniteElement.h:27,
                 from /opt/HPC/FEniCS/src/dolfin/dolfin/adaptivity/adapt.cpp:25:
/opt/HPC/FEniCS/src/dolfin/dolfin/parameter/Parameters.h: In member function 'void dolfin::Parameters::add(std::string)':
/opt/HPC/FEniCS/src/dolfin/dolfin/parameter/Parameters.h:117: error: there are no arguments to 'dolfin_error' that depend on a template parameter, so a declaration of 'dolfin_error' must be available
/opt/HPC/FEniCS/src/dolfin/dolfin/parameter/Parameters.h:117: error: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
/opt/HPC/FEniCS/src/dolfin/dolfin/parameter/Parameters.h: In member function 'void dolfin::Parameters::add(std::string, T, T)':
/opt/HPC/FEniCS/src/dolfin/dolfin/parameter/Parameters.h:128: error: there are no arguments to 'dolfin_error' that depend on a template parameter, so a declaration of 'dolfin_error' must be available
/opt/HPC/FEniCS/src/dolfin/dolfin/parameter/Parameters.h: In member function 'void dolfin::Parameters::add(std::string, std::set<T, std::less<_Key>, std::allocator<_CharT> >)':
/opt/HPC/FEniCS/src/dolfin/dolfin/parameter/Parameters.h:139: error: there are no arguments to 'dolfin_error' that depend on a template parameter, so a declaration of 'dolfin_error' must be available
make[2]: *** [dolfin/CMakeFiles/dolfin.dir/adaptivity/adapt.cpp.o] Error 1
make[1]: *** [dolfin/CMakeFiles/dolfin.dir/all] Error 2
make: *** [all] Error 2

Le 30 oct. 2012 à 21:40, Johan Hake a écrit :

> On 10/30/2012 11:53 AM, corrado maurini wrote:
>> Johan,
>>
>> Thanks a lot for taking care of this.
>
> Well, we see how far it goes :)
>
>> If redirecting ostream through python is too difficult, for the specific
>> case a possible alternative can be to have a function similar to
>> list_timings(), but giving a dolfin Table as output.
>
> Sure that would be pretty trivial to implement, and we have them same
> analogy for list_linear_algebra_backends and linear_algebra_backends,
> where the later return a list of strings instead of printing them to the
> screen.
>
> So adding a free function called timings would fit fine here.
>
>> Then the Table is a python object and one can use the associated methods
>> to access data or print it out (event in latex format!).
>
> Good point!
>
>> I have not done this directly because I do not if this may conflict with
>> your general design principles for the logger.
>
> Should work just fine.
>
> Johan
>
>> Corrado
>>
>> Le 30 oct. 2012 à 11:02, Marco Morandini a écrit :
>>
>>> On 10/30/2012 08:00 AM, Johan Hake wrote:
>>>> Marco, what would the syntax be for adding a file as the log output. Is
>>>> it possible to add an already existing file pointer or just the file
>>>> name as a string? This would be the ultimate solution as we then can
>>>> merge the two log streams from dolfin and logging dependent python
>>>> modules such as UFL.
>>>>
>>>> My boost python skills are really limited so following the inner
>>>> workings of this small file is hard for me...
>>>>
>>>
>>> In my old code (where everything is wrapped with boost)
>>>
>>> after
>>>
>>> fileout = ostream(cout_buf())
>>>
>>> fileout will point to std::cout,
>>>
>>> and after
>>>
>>> fileout = ostream('new_file_name.txt')
>>>
>>> fileout will point to a newly opened ofstream.
>>>
>>> Then, fileout can be passed to any wrapped c++ function that
>>> has an std::ostream & argument.
>>>
>>> I.e., if I have this c++ function
>>>
>>> void DxOutput(std::ostream & out, const MyFloat t);
>>>
>>> and I wrap it as
>>>
>>> BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(ofstream_open_overloads,
>>> std::ofstream::open, 1, 2);
>>> BOOST_PYTHON_MODULE_INIT(_python_util)
>>> {
>>> ....
>>>
>>> the wrapping code I've attached
>>>
>>> ....
>>>
>>> python::def("DxOutput", DxOutput);
>>> }
>>>
>>> in python I can do
>>>
>>> t=0.01
>>> fileout = ostream('new_file_name.txt')
>>> DxOutput(fileout, t)
>>>
>>> if I want to write with DxOutput into new_file_name.txt,
>>>
>>> or
>>>
>>> fileout = ostream(cout_buf())
>>> DxOutput(fileout, t)
>>>
>>> If I want DxOuptut's output on the screen.
>>>
>>> Note however that I can't write directly from python into fileout
>>> (and I fear that this is what you are looking for :( .
>>> At least, I've not even tried to do it (perhaps one should start
>>> extractig the file descriptor, as explained here:
>>>
>>> http://www.ginac.de/~kreckel/fileno/
>>>
>>> )
>>>
>>> Or
>>> http://stackoverflow.com/questions/2378005/c-iostreams-and-python
>>>
>>>
>>> Hope this helps.
>>>
>>> --
>>> You received this bug notification because you are a member of DOLFIN
>>> Team, which is subscribed to DOLFIN.
>>> https://bugs.launchpad.net/bugs/1072694
>>>
>>> Title:
>>> list_timings() cannot be redirected to a file or a variable in python
>>>
>>> Status in DOLFIN:
>>> Confirmed
>>>
>>> Bug description:
>>> In python it is not possible to redirect the output of list_timings()
>>> to a file.
>>>
>>> set_output_stream(std::ostream& out) in log.ccp is not working in
>>> python because of problems in wrapping cpp ostream
>>>
>>> see also https://answers.launchpad.net/dolfin/+question/211271
>>>
>>> To manage notifications about this bug go to:
>>> https://bugs.launchpad.net/dolfin/+bug/1072694/+subscriptions
>>
>
> --
> You received this bug notification because you are a member of DOLFIN
> Team, which is subscribed to DOLFIN.
> https://bugs.launchpad.net/bugs/1072694
>
> Title:
> list_timings() cannot be redirected to a file or a variable in python
>
> Status in DOLFIN:
> Confirmed
>
> Bug description:
> In python it is not possible to redirect the output of list_timings()
> to a file.
>
> set_output_stream(std::ostream& out) in log.ccp is not working in
> python because of problems in wrapping cpp ostream
>
> see also https://answers.launchpad.net/dolfin/+question/211271
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/dolfin/+bug/1072694/+subscriptions