<div dir="ltr"><div dir="ltr">On Mon, Oct 4, 2021 at 11:27 AM Peder Jørgensgaard Olesen via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">



<div style="overflow-wrap: break-word;">

<div id="gmail-m_-1010849019896937523divtagdefaultwrapper" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif" dir="ltr">
<p>In theory it should be relatively simple to write up a routine to skip a given number of objects. I'm not getting PetscBinarySeek() to work even on a header-less array of integers, however. I suppose that </p>
<p>> PetscBinarySeek(fd, PETSC_BINARY_INT_SIZE*array_size, PETSC_BINARY_SEEK_CUR, NULL);</p>
<p></p></div></div></blockquote><div>The VecView code is here:</div><div><br></div><div>  <a href="https://gitlab.com/petsc/petsc/-/blob/main/src/vec/vec/utils/vecio.c#L32">https://gitlab.com/petsc/petsc/-/blob/main/src/vec/vec/utils/vecio.c#L32</a></div><div><br></div><div>you can see that it writes 2 integers and then the scalar data. So, first you skip the 2 integers, and then you skip the array_size scalars (so you want PETSC_BINARY_SCALAR_SIZE).</div><div><br></div><div>  Thanks,</div><div><br></div><div>     Matt </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;"><div id="gmail-m_-1010849019896937523divtagdefaultwrapper" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif" dir="ltr"><p>ought to do the trick, but that does not seem to be the case.</p>
<p><br>
</p>
<p>Am I somehow using this routine incorrectly?</p>
<p><br>
</p>
<p>Peder</p>
</div>
<hr style="display:inline-block;width:98%">
<div id="gmail-m_-1010849019896937523divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>Fra:</b> Barry Smith <<a href="mailto:bsmith@petsc.dev" target="_blank">bsmith@petsc.dev</a>><br>
<b>Sendt:</b> 4. oktober 2021 16:38:10<br>
<b>Til:</b> Peder Jørgensgaard Olesen<br>
<b>Cc:</b> <a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a><br>
<b>Emne:</b> Re: [petsc-users] Skipping data when reading from binary file</font>
<div> </div>
</div>
<div>
<div><br>
</div>
  To minimize code changes you could add a PETSc viewer format that caused skipping reading in an object. Then each object load would need a skip-read method that mimicked the reading but actually just skipped over the parts of the data of the object (using
 the correct sizes). For vectors this is trivial since you just skip the single known array. For sparse matrices it is not difficult but you will need to read in the number of nonzeros so you know how much to skip etc.
<div><br>
</div>
<div>  Barry</div>
<div><br>
<div><br>
<blockquote type="cite">
<div>On Oct 4, 2021, at 9:58 AM, Peder Jørgensgaard Olesen via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>> wrote:</div>
<br>
<div>
<div>
<div id="gmail-m_-1010849019896937523divtagdefaultwrapper" style="font-size:12pt;font-family:Calibri,Helvetica,sans-serif" dir="ltr">
<p>Thank you for your quick reply.</p>
<p><br>
</p>
<p>I've had to change away from HDF5 to Binary format at an earlier stage in my work due to the former not working well with what I needed, so I would prefer to stick with the binary format.</p>
<p><span style="font-size:12pt">I had a quick view at the code for some of the Viewer-routines, but </span><span style="font-size:12pt">I'm not well versed in
</span><span style="font-size:12pt">gleaning </span><span style="font-size:12pt">information about header sizes
</span><span style="font-size:12pt">from that. H</span><span style="font-size:12pt">ints about what I'm looking for there would be appreciated.</span><span style="font-size:12pt"> </span><br>
</p>
<p><br>
</p>
<p>Best regards</p>
<p>Peder</p>
</div>
<hr style="display:inline-block;width:98%">
<div id="gmail-m_-1010849019896937523divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt"><b>Fra:</b> Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>><br>
<b>Sendt:</b> 4. oktober 2021 15:37:08<br>
<b>Til:</b> Peder Jørgensgaard Olesen<br>
<b>Cc:</b> <a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a><br>
<b>Emne:</b> Re: [petsc-users] Skipping data when reading from binary file</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div dir="ltr">On Mon, Oct 4, 2021 at 9:26 AM Peder Jørgensgaard Olesen via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>> wrote:<br>
</div>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div id="gmail-m_-1010849019896937523gmail-m_9165503901133771575divtagdefaultwrapper" dir="ltr" style="font-size:12pt;font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<p>Hello</p>
<p>I have a binary file in which a mix of different objects is stored (Vecs, Mats, PetscInts). I can read each element just fine using VecLoad, MatLoad, and PetscIntView, provided they're read in the order in which they were put in the binary. What
 I would like to do is to skip the reading of any unneeded element, instead proceeding directly to the next one. I tried using PetscBinarySeek() for this, as shown in the attached code. This produces segmentation faults, suggesting that the file pointer isn't
 going where I want it to.</p>
</div>
</div>
</blockquote>
<div>There is header information you also have to skip for each object.</div>
<div><br>
</div>
<div>We can go over the sizes  for that (it is best just to look at the code), but that is fragile. A more robust way to achieve this random</div>
<div>access is to use HDF5 and name the objects.</div>
<div><br>
</div>
<div>  Thanks,</div>
<div><br>
</div>
<div>     Matt</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div id="gmail-m_-1010849019896937523gmail-m_9165503901133771575divtagdefaultwrapper" dir="ltr" style="font-size:12pt;font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<p>Any suggestions as to what I'm doing wrong here?</p>
<p><br>
</p>
<p>Best regards,</p>
<p>Peder</p>
<div id="gmail-m_-1010849019896937523gmail-m_9165503901133771575Signature">
<div id="gmail-m_-1010849019896937523gmail-m_9165503901133771575divtagdefaultwrapper" dir="ltr" style="font-size:12pt;font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<p><br>
</p>
<div><br>
</div>
<table style="font-family:"Times New Roman";padding:0px;width:400px" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td style="width:400px">
<table style="width:400px;font-family:Arial;font-size:11.5px;border-collapse:collapse" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td style="width:50px;vertical-align:top" valign="top">
<table style="width:50px;padding-top:4px" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="width:50px;vertical-align:top" align="left"><img width="36" height="53" src="http://www.dtu.dk/-/media/DTU_Generelt/Andet/mail-signature-logo.png"></td>
</tr>
</tbody>
</table>
</td>
<td style="width:350px;vertical-align:top" valign="top">
<table style="width:350px;border-collapse:collapse" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td style="width:350px;font-size:16px;margin:0px;font-weight:bold;line-height:19.2px">
Peder Jørgensgaard Olesen</td>
</tr>
<tr>
<td style="width:350px;margin:0px;line-height:17px">PhD student<br>
Department of Mechanical Engineering</td>
</tr>
<tr>
<td style="width:350px;margin:0px;line-height:17px"> </td>
</tr>
<tr>
<td style="width:350px;line-height:17px"><a href="mailto:pjool@mek.dtu.dk" id="gmail-m_-1010849019896937523gmail-m_9165503901133771575LPNoLP" style="margin:0px;line-height:17px" target="_blank">pjool@mek.dtu.dk</a></td>
</tr>
<tr>
<td style="width:350px;margin:0px;line-height:17px">Koppels Allé</td>
</tr>
<tr>
<td style="width:350px;margin:0px;line-height:17px">Building 403, room 105</td>
</tr>
<tr>
<td style="width:350px;margin:0px;line-height:17px">2800 Kgs. Lyngby</td>
</tr>
<tr>
<td style="width:350px;line-height:17px"><a href="https://www.dtu.dk/english" id="gmail-m_-1010849019896937523gmail-m_9165503901133771575LPNoLP" style="margin:0px;line-height:17px" target="_blank">www.dtu.dk/english</a></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<div><span style="font-size:10pt;color:rgb(117,123,128)"></span><br>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr">
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div dir="ltr">
<div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener</div>
<div><br>
</div>
<div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</div>

</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>