<div dir="ltr">How about the logic of this analysis?<div><br></div><div>1. We are trying to use the same functions (in particular, PetscVFPrintf) for two purposes:</div><div> a. printing error messages (don't want to malloc)</div><div> b. use by public API printing functions (don't want length restrictions)</div><div><br></div><div>2. Right now, PetscVFPrintf works fine for a but not for b. We could make it work for b and not for a by malloc'ing a longer string.</div><div><br></div><div>3. Printing from error handlers happens through PetscErrorPrintf (default : <a href="http://www.mcs.anl.gov/petsc/petsc-dev/src/sys/error/errtrace.c.html#PetscErrorPrintfDefault">http://www.mcs.anl.gov/petsc/petsc-dev/src/sys/error/errtrace.c.html#PetscErrorPrintfDefault</a> ), so if there's a special requirement for printing error messages, we can impose it here.</div><div><br></div><div>A solution could then be something which skips the malloc only when printing an error, e.g.</div><div><br></div><div>1. Add an argument to PetscVFPrintf (say "PetscBool noMalloc") [1]</div><div>2. API (PetscPrintf(), etc.) functions use noMalloc = PETSC_FALSE<br></div><div>3. error functions (PetscErrorPrintf() ) functions use noMalloc = PETSC_TRUE </div><div><br></div><div><br></div><div>[1] And probably do the same thing in PetscVSNPrintf since, as Dr. Zhang pointed out, this could also call malloc while handling an error, if the string was long enough</div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-04-13 15:59 GMT+02:00 Junchao Zhang <span dir="ltr"><<a href="mailto:jczhang@mcs.anl.gov" target="_blank">jczhang@mcs.anl.gov</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="">On Thu, Apr 12, 2018 at 9:48 AM, Smith, Barry F. <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="m_6947870436724932205gmail-"><br>
<br>
> On Apr 12, 2018, at 3:59 AM, Patrick Sanan <<a href="mailto:patrick.sanan@gmail.com" target="_blank">patrick.sanan@gmail.com</a>> wrote:<br>
><br>
> I also happened to stumble across this yesterday. Is the length restriction for the default printer (l assume from the array of 8*1024 chars in PetscVFPrintfDefault() ) intended behavior to be documented, or a bug to be fixed?<br>
<br>
</span> You could call it either. My problems are<br>
<br>
1) that given a format string I don't know in advance how much work space is needed so cannot accurately malloc, for sure, enough space<br>
<br>
2) since this can be called in an error handler I really don't want it calling malloc().<br></blockquote></span><div>PetscVSNPrintf does still contain a malloc "122 ierr = PetscMalloc1(oldLength, &newformat);CHKERRQ(ierr);"</div><div>Also, vsnprintf returns "t<span style="color:rgb(0,0,0);font-family:verdana,arial,helvetica,sans-serif;font-size:12px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">he number of characters that would have been written if<span> </span></span><var style="color:rgb(0,0,0);font-family:verdana,arial,helvetica,sans-serif;font-size:12px;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">n</var><span style="color:rgb(0,0,0);font-family:verdana,arial,helvetica,sans-serif;font-size:12px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span> </span>had been sufficiently large</span>". I don't know why you void'ed it.</div><div>We can not make the 8K chars a requirement since users don't know how many chars they want to print upfront.</div><div>Anyway, crash is better than silent errors. </div><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Hence it lives in this limbo. I don't even know a way to add a good error checking that detects if the buffer is long enough. All in all it is bad ugly code, any suggestions on improvements would be appreciated.<br>
<span class="m_6947870436724932205gmail-HOEnZb"><font color="#888888"><br>
Barry<br>
</font></span><div class="m_6947870436724932205gmail-HOEnZb"><div class="m_6947870436724932205gmail-h5"><br>
><br>
> 2018-04-12 2:16 GMT+02:00 Rongliang Chen <<a href="mailto:rongliang.chan@gmail.com" target="_blank">rongliang.chan@gmail.com</a>>:<br>
> Thanks Barry. I found petsc-3.6 and older versions did not have this restriction.<br>
><br>
> Best,<br>
> Rongliang<br>
><br>
><br>
> On 04/12/2018 07:22 AM, Smith, Barry F. wrote:<br>
> Yes, PetscPrintf() and related functions have a maximum string length of about 8000 characters.<br>
><br>
> Barry<br>
><br>
><br>
> On Apr 11, 2018, at 6:17 PM, Rongliang Chen <<a href="mailto:rongliang.chan@gmail.com" target="_blank">rongliang.chan@gmail.com</a>> wrote:<br>
><br>
> Dear All,<br>
><br>
><br>
> When I tried to print a long string using PetscPrintf() I found that it truncated the string. Attached is a simple example for this (run with single processor). I used PetscPrintf() and printf() to print the same string and the printf() seems OK. I am using petsc-3.8.4.<br>
><br>
><br>
> Best,<br>
><br>
> Rongliang<br>
><br>
> <ex111.c><br>
><br>
><br>
><br>
<br>
</div></div></blockquote></span></div><br></div></div>
</blockquote></div><br></div>