On Thu, Mar 10, 2011 at 9:09 AM, Tim Kroeger
<[email protected]> wrote:
> On Thu, 10 Mar 2011, John Peterson wrote:
>
>> On Thu, Mar 10, 2011 at 8:39 AM, Tim Kroeger
>> <[email protected]> wrote:
>>
>>> PetscMatrix::print_personal() can only print to stdout, which makes it
>>> difficult for me to cut out the correct part of the output, in
>>> particular if I'm writing more than one matrix.
>>
>> I think we should try to fix/update the PetscMatrix implementation of
>> print_personal.  I don't think there's any limitation of MatView which
>> prevents its contents from being written to file instead of stdout.
>
> I don't know either.  But as far as I understand, print_personal() does
> different things for different solver packages, and I think it would be a
> nice thing to have a method that supplies a uniform output format for all
> packages, and takes the sparsity pattern into account.

Well, print_personal() already takes an ostream& so I don't think we'd
be stepping outside the current bounds of its responsibilities to
provide it a reasonable execution path for when os != std::cout.  For
PETSc, I think PETSC_VIEWER_ASCII_COMMON, which uses "a sparse format
common among all matrix types" would be the way to go in
print_personal to avoid printing the zeros.

>>> I would like to implement a method, e.g. called
>>> SparseMatrix::print_sparse(), which works the same way as
>>> SparseMatrix::print() does, but does not print all the 0 entries.  It
>>> would e.g. rather print one entry per line in the format
>>>
>>>        row column value
>>>
>>> Any objections or thoughts?
>>
>> I'd prefer not adding yet another print* function to SparseMatrix if
>> possible.  If it turns out that print_personal() can't be fixed up the
>> way you want, I think it'd be easier to pass an additional flag (with
>> default value) to print() to make it do what you want.  You'd have to
>> duplicate a lot of code from print() to implement print_sparse()
>> anyway, wouldn't you?
>
> That's a good point.  What about this:
>
>        SparseMatrix::print(std::ostream& os, const bool sparse=false);

Yeah, that's pretty much what I had in mind.


> By the way, there is another issue with that method, I've just ran into.  I
> did:
>
>        std::ofstream sMatrix("matrix");
>        matrix->print(sMatrix);
>
> But that opens libMesh::processor_id() instances of the same file at once
> and writes the matrix to only one of them.  Since these files keep
> overwriting each other, the result is rubbish.  This can of course be
> avoided on user side by

Are you using a complex-enabled build of LibMesh?  The complex version
of SparseMatrix::print(), which is defined in the header file, looks
like it incorrectly writes on all processors in a parallel run, but
the version of SparseMatrix::print() in the C file looks like it
should do the right thing in parallel.  The Complex version should be
wrapped in if (libMesh::processor_id()==0), or, more ideally,
rewritten in the style of the C file implementation.

-- 
John

------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
Libmesh-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libmesh-devel

Reply via email to