[petsc-users] Wrapping PetscFPrintf

Jed Brown jedbrown at mcs.anl.gov
Sun Nov 11 09:18:56 CST 2012


On Sun, Nov 11, 2012 at 8:35 AM, Jed Brown <jedbrown at mcs.anl.gov> wrote:

> 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?
>>
>
> PetscSynchronizedVFPrintf is missing, but should be added.
>

There is actually an implementation issue. The current version dynamically
sizes the local buffer by calling PetscVSNPrintf repeatedly, increasing the
buffer size as necessary [1]. We cannot offer a PetscSynchronizedVFPrintf()
without either (a) truncating sufficient long strings or (b) using
vasprintf() which is a GNU extension. You can roll your own loop over
va_start, vsnprintf(), va_end, resize-array-if-necessary and then call
PetscSynchronizedPrintf(), or, if you can use the GNU extension, just use
asprintf().


[1] The implementation is hideous, leaking memory quadratic in the input
size for large data volume.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20121111/92241a0b/attachment.html>


More information about the petsc-users mailing list