On Fri, 11 Mar 2011, John Peterson wrote:

> On Fri, Mar 11, 2011 at 1:25 AM, Tim Kroeger
> <[email protected]> wrote:
>> On Thu, 10 Mar 2011, John Peterson wrote:
>>
>>> The attached patch makes PetscMatrix::print_personal() print to file.
>>> Would you try it out and see if that works for you?
>>
>> Your patch makes it even more difficult to write to a file in parallel,
>> because my trick to open the file on one processor and use std::cout on the
>> others confuses your method in that way that you create your custom
>> PetscViewer on the first processor but call
>> MatView(...,PETSC_VIEWER_STDOUT_SELF) on all other processors.  This causes
>> PETSc to crash.
>
> If you have been using a hack (passing a file on one processor and
> std::cout on the others) then you should stop using that hack before
> you try out the new patch...

But what is the correct way to use your method in parallel?

        std::ofstream f("filename");
        matrix.print_personal(f);

can definitely not be correct, no matter what print_personal() does, 
since it opens the same file several times, and the files overwrite 
each other in a non-predictable way.

The more I think about this, the more I come to the conclusion that 
the API of getting a stream on all processors is misleading.  I mean, 
what if the stream is e.g. a std::stringstream?  Then the user might 
want to get the result into the stream on *all* processors, which 
neiter your nor my method correctly performs.

What would be a better API?

Either a similar API as in PETSc, where either a file name is used 
(and the method is responsible for opening this file only once) or 
some special value meaning std::cout.  (This disallows to use a 
std::stringstream, but disallowing something seems better to me than 
allowing it but behaving unexpectedly.)

Or we might want to do

        print(std::ostream*=NULL);

and explicitly allow that the argument differs between processors, 
where the meaning would be that the result is printed on all 
processors that do not use NULL.  However, this requires additional 
communication.

Best Regards,

Tim

-- 
Dr. Tim Kroeger
CeVis -- Center of Complex Systems and Visualization
University of Bremen              [email protected]
Universitaetsallee 29             [email protected]
D-28359 Bremen                            Phone +49-421-218-59246
Germany                                   Fax   +49-421-218-59277

------------------------------------------------------------------------------
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