[petsc-users] Vec, Mat and binaryfiles.
Jed Brown
jed at jedbrown.org
Mon Nov 5 10:48:57 CST 2018
Sal Am via petsc-users <petsc-users at mcs.anl.gov> writes:
> Hi,
>
> I am trying to solve a Ax=b complex system. the vector b and "matrix" A are
> both binary and NOT created by PETSc. So I keep getting error messages that
> they are not correct format when I read the files with PetscViewBinaryOpen,
> after some digging it seems that one cannot just read a binary file that
> was created by another software.
Yes, of course the formats would have to match. I would recommend
writing the files in an existing format such as PETSc's binary format.
While the method you describe can be made to work, it will be more work
to make it parallel.
> How would I go on to solve this problem?
>
> More info and trials:
>
> "matrix" A consists of two files, one that contains row column index
> numbers and one that contains the non-zero values. So what I would have to
> do is multiply the last term in a+b with PETSC_i to get a real + imaginary
> vector A.
>
> vector b is in binary, so what I have done so far (not sure if it works) is:
>
> std::ifstream input("Vector_b.bin", std::ios::binary );
> while (input.read(reinterpret_cast<char*>(&v), sizeof(float)))
> ierr = VecSetValues(u,1,&iglobal,&v,INSERT_VALUES);CHKERRQ(ierr);
>
> where v is a PetscScalar.
>
> Once I am able to read both matrices I think I can figure out the solvers
> to solve the system.
>
> All the best,
> S
More information about the petsc-users
mailing list