<div class="gmail_extra">On Mon, Nov 5, 2012 at 7:10 AM,  <span dir="ltr"><<a href="mailto:Gregor.Matura@dlr.de" target="_blank">Gregor.Matura@dlr.de</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Maybe I have not explained my situation well enough: I do already have a matrix on the disk.</span></p>
</blockquote><div><br></div><div>First a warning: 99% of the time, storing large matrices on disk represents a flawed workflow. Putting a matrix on disk is an epic scalability bottleneck that almost no amount of computation can escape. It takes most of today's supercomputers more than half an hour to read or write their contents to disk, assuming that they sustain maximum theoretical bandwidth for the entire operation.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> This makes generating the matrix on-the-fly either
 a burden for the filesystem (because of to many accesses in a short time) or for the memory (because data has to be duplicated).</span></p></blockquote><div><br></div><div>1. File IO APIs read in chunks, not entire files. Just read one chunk at a time, loop through rows in the chunk, and call MatSetValues[Blocked][Local]().</div>
<div><br></div><div>2. Be aware that independent file IO will scale terribly.</div><div><br></div><div>3. Recall that it's _terrible_ for your workflow to partition the matrix entirely up-front for a specific number of processors. This means that you can't store the matrix data in a way that could be used directly anyway.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> I want to avoid both, thus read in my matrix in one go and pass this data conveniently to PETSc. As far as my insights go, there
 are two possibilities with certain drawbacks, maybe you could uncover more details on both (like convenience of data layout, assembly time, solution speed, …).<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">1.)MatCreateBAIJ (includes MatSetBlockSize and MatMPIBAIJSetPreallocation) > MatSetLocalToGlobalMapping > MatSetValuesBlockedLocal<u></u><u></u></span></p>

<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">drawbacks:<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">- data is copied (thus doubles memory needs)</span></p></blockquote><div><br></div><div>
Disk doesn't work like this, see above.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u><u></u></span></p>

<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">- ALL local rows has to be read in to get information for preallocation</span></p></blockquote>
<div><br></div><div>Row lengths are stored explicitly anyway, in a dedicated array if you use a CSR-type format.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">- but: SetValuesBlockedLocal requires "square" layout of data (not suited for sparse matrices). In my case this leads to setting values (block)
 row by (block) row.</span></p></blockquote><div><br></div><div>That is intentional. It inserts a _logically dense_ block. In typical PDE problems, that is a row (for FD schemes) or an element stiffness matrix for FE schemes.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u><u></u></span></p>

<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">- and: value array does not match block structure (cf. documentation example of MatSetValuesBlocked): my values are sorted sequentially by blocks,
 i.e. v[] = [1,2,5,6,3,4,7,8,...]</span></p></blockquote><div><br></div><div>Just unpack row-by-row before calling MatSetValuesBlocked(). It's vanishingly little time.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">2.)MatCreateMPIAIJWithSplitArrays<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">drawbacks:<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">? doesn't match PETSc data layout -> slower?<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">- not blocked (conversion to MPIBAIJ possible?)</span></p></blockquote></div><br></div>
<div class="gmail_extra">This routine exists for rare and peculiar workflows. It's only used by a handful of people and most of them shouldn't be using it. You shouldn't use it either.</div>