You saved a Vec to the file, not a Mat.
> On Dec 3, 2018, at 1:38 PM, Sajid Ali via petsc-users > <petsc-users@mcs.anl.gov> wrote: > > Hi, > > I ran ex10 from /vec/examples/tutorials and saved the matrix in binary format. > > Looking at the matrix in binary using xxd, I see > > [sajid@xrm temp]$ xxd -b vector.dat > 0000000: 00000000 00010010 01111011 01001110 00000000 00000000 ..{N.. > 0000006: 00000000 00010100 00000000 00000000 00000000 00000000 ...... > 000000c: 00000000 00000000 00000000 00000000 00111111 11110000 ....?. > 0000012: 00000000 00000000 00000000 00000000 00000000 00000000 ...... > 0000018: 01000000 00000000 00000000 00000000 00000000 00000000 @..... > 000001e: 00000000 00000000 01000000 00001000 00000000 00000000 ..@... > 0000024: 00000000 00000000 00000000 00000000 01000000 00010000 ....@. > 000002a: 00000000 00000000 00000000 00000000 00000000 00000000 ...... > 0000030: 01000000 00010100 00000000 00000000 00000000 00000000 @..... > 0000036: 00000000 00000000 01000000 00011000 00000000 00000000 ..@... > 000003c: 00000000 00000000 00000000 00000000 01000000 00011100 ....@. > 0000042: 00000000 00000000 00000000 00000000 00000000 00000000 ...... > 0000048: 01000000 00100000 00000000 00000000 00000000 00000000 @ .... > 000004e: 00000000 00000000 01000000 00100010 00000000 00000000 ..@".. > 0000054: 00000000 00000000 00000000 00000000 01000000 00100100 ....@$ > 000005a: 00000000 00000000 00000000 00000000 00000000 00000000 ...... > 0000060: 01000000 00100110 00000000 00000000 00000000 00000000 @&.... > 0000066: 00000000 00000000 01000000 00101000 00000000 00000000 ..@(.. > 000006c: 00000000 00000000 00000000 00000000 01000000 00101010 ....@* > 0000072: 00000000 00000000 00000000 00000000 00000000 00000000 ...... > 0000078: 01000000 00101100 00000000 00000000 00000000 00000000 @,.... > 000007e: 00000000 00000000 01000000 00101110 00000000 00000000 ..@... > 0000084: 00000000 00000000 00000000 00000000 01000000 00110000 ....@0 > 000008a: 00000000 00000000 00000000 00000000 00000000 00000000 ...... > 0000090: 01000000 00110001 00000000 00000000 00000000 00000000 @1.... > 0000096: 00000000 00000000 01000000 00110010 00000000 00000000 ..@2.. > 000009c: 00000000 00000000 00000000 00000000 01000000 00110011 ....@3 > 00000a2: 00000000 00000000 00000000 00000000 00000000 00000000 ...... > > > The format of the binary file is supposed to be > MAT_FILE_CLASSID, num_rows, num_cols, -1 followed by data. > > Converting the first 4 bytes (32 bits) of binary to int, the number > 00000000000100100111101101001110 becomes 1211214, but the value of > MAT_FILE_CLASSID according to the header file petscmat.h is 1211216 > (petsc@3.10.2.1 built without complex support). What causes this discrepancy > ? > > Also, what are the special characters at the end of every line ? Am i not > reading the binary file correctly ? > > > Thank You, > Sajid Ali > Applied Physics > Northwestern University