[petsc-users] Wrapping PetscFPrintf
Dominik Szczerba
dominik at itis.ethz.ch
Sun Nov 11 07:34:16 CST 2012
Thanks for the hint.
Unfortunately, I do not see any related error messages in valgrind and
the whole va_list machinery is a bit obfuscated. What I experimentally
discovered, however, is that the problem goes away if the two
functions are directly provided in the same source file in C-style. As
soon as they go out to a class the problem occurs.
But I found a very promising solution: PetscVFPrintf. It solves my
problem for my own Print function. But I do not seem to find a
corresponding function for synchronized printing (PetscFPrintf). Any
clues how to use PetscVFPrintf for synchronized printing please?
Dominik
On Sun, Nov 11, 2012 at 1:25 AM, Jed Brown <jedbrown at mcs.anl.gov> wrote:
> If you are getting garbage, run in valgrind and/or a debugger. Also make
> sure the int sizes are converted correctly as for a direct call to printf.
>
>
> On Sat, Nov 10, 2012 at 3:38 PM, Dominik Szczerba <dominik at itis.ethz.ch>
> wrote:
>>
>> Hi,
>>
>> I need to have a wrapper to PetscFPrintf and PetscSynchronizedFPrintf.
>> I am aware of the problems and tried following as described here:
>>
>> http://c-faq.com/varargs/handoff.html
>>
>> So I have:
>>
>> virtual bool VPrint(const char* format, va_list argp) = 0;
>> virtual bool Print(const char* format, ...) = 0;
>>
>> implemented as:
>>
>> bool CXCoreReporting::VPrint(const char* format, va_list argp)
>> {
>> vfprintf(stderr, format, argp);
>> return true;
>> }
>>
>> bool CXCoreReporting::Print(const char* format, ...)
>> {
>> va_list argp;
>> va_start(argp, format);
>> VPrint(format, argp);
>> va_end(argp);
>> return true;
>> }
>>
>>
>> Now the problem is that it just does not work... I still get trash
>> when calling e.g. Print("%d", i).
>> Does anyone see a way out?
>>
>> Many thanks
>> Dominik
>
>
More information about the petsc-users
mailing list