<div>$ ls -l</div><div>-rw-r--r-- 1 John None 192208072 Jul 13 03:31 binaryoutput<br></div>-rw-r--r-- 1 John None 0 Jul 13 03:31 <a href="http://binaryoutput.info">binaryoutput.info</a><br>-rw-r--r-- 1 John None 128128032 Jul 13 01:43 DOF4002_k_double.bin<br>
<div>-rw-r--r-- 1 John None 128128032 Jul 13 01:43 DOF4002_m_double.bin<br></div><div><br></div><div>where DOF4002_k_double.bin and DOF4002_m_double.bin are the file to be converted.</div><div><br></div><div>What is <a href="http://binaryoutput.info">binaryoutput.info</a> (size=0)? </div>
<div>And why is binaryoutput so much fatter than either DOF4002_k_double.bin or DOF4002_m_double.bin?</div><div><br></div><div>---John</div><br><div class="gmail_quote">On Wed, Jul 13, 2011 at 3:24 AM, John Chludzinski <span dir="ltr"><<a href="mailto:jchludzinski@gmail.com">jchludzinski@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div>Is this what you had in mind (more or less)? ---John</div><div><br></div><div>//-----------------------------------CONVERTER---------------------------------------------------------------------------------------------------------</div>
<div><br></div><div>static char help[] = "Reads matrix: \n -f <input_file> : file to load \n\n";<br></div><br>#define SIZE 4002<br><br>#include <stdio.h><br>#include <stdlib.h><br>#include "petscmat.h"<br>
<br>int main(int argc,char **args)<br>{<br> Mat A;<br> char file[PETSC_MAX_PATH_LEN];<br> PetscErrorCode ierr;<br> PetscScalar *a;<br> PetscTruth flg;<br>
PetscInt n=SIZE;<br> int i, j;<br><br> PetscInitialize(&argc,&args,(char *)0,help);<br><br> ierr = PetscOptionsGetString(PETSC_NULL,"-f",file,PETSC_MAX_PATH_LEN-1,&flg);CHKERRQ(ierr);<br>
if (!flg) SETERRQ(1,"Must indicate binary file with the -f option");<br><br> ierr = PetscMalloc(SIZE*SIZE*sizeof(PetscScalar),&a);CHKERRQ(ierr);<br><br> FILE *fpK;<br><br> double *K = (double *)calloc( sizeof(double), SIZE*SIZE );<br>
<br> if((fpK = fopen(file, "rb")) == NULL) <br> {<br> printf("Cannot open joe_DOF4002_k_double.bin\n");<br> exit(1);<br> }<br><br> fprintf(stderr, "Doubles read for K = %d\n", fread( (void *)K, sizeof(double), SIZE*SIZE, fpK ));<br>
<br> for ( i = 0; i < SIZE; i++ )<br> for ( j = i; j < SIZE; j++ ) a[i+j*SIZE]= *(K+i*SIZE+j);<br><br> MatCreateSeqDense(PETSC_COMM_SELF, n, n, a, &A); <div class="im"><br> MatView(A,PETSC_VIEWER_BINARY_(PETSC_COMM_WORLD));<br>
<br></div> ierr = PetscFinalize();CHKERRQ(ierr);<br> return 0;<br>}<br><br><br><br><div class="gmail_quote"><div class="im">On Wed, Jul 13, 2011 at 1:02 AM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br>
</div><div><div class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
If it is truly a dense matrix then it isn't clear that you want to store it as a PETSc binary matrix but you can using the following code<br>
<br>
PetscInt n;<br>
PetscScalar *values;<br>
<br>
allocate values the correct size; read the entries into values then call MatCreateSeqDense(PETSC_COMM_SELF,n,n,values,&A); the call MatView(A,PETSC_VIEWER_BINARY_(PETSC_COMM_WORLD));<br>
<font color="#888888"><br>
Barry<br>
</font><div><div><br>
On Jul 12, 2011, at 11:41 PM, John Chludzinski wrote:<br>
<br>
> I have a matrix stored as a sequential list of binary values (not PETSc binary form) that I read in with a single block read:<br>
><br>
> read( (void *)K, sizeof(double), SIZE*SIZE, fpK ).<br>
><br>
> How do I convert this simple binary file of (sequentially stored) doubles into a "PETSc binary matrix file"?<br>
><br>
> ---John<br>
<br>
</div></div></blockquote></div></div></div><br>
</blockquote></div><br>