Skip to content

Commit b031a0f

Browse files
committed
Add write capability directly from Xdr
1 parent ea90b6e commit b031a0f

2 files changed

Lines changed: 35 additions & 6 deletions

File tree

include/systems/equation_systems.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,15 @@ class EquationSystems : public ReferenceCountedObject<EquationSystems>,
514514
const unsigned int write_flags=(WRITE_DATA),
515515
bool partition_agnostic = true) const;
516516

517+
void write (std::ostream name,
518+
const unsigned int write_flags=(WRITE_DATA),
519+
bool partition_agnostic = true) const;
520+
521+
void write (Xdr & io,
522+
const unsigned int write_flags=(WRITE_DATA),
523+
bool partition_agnostic = true,
524+
Xdr * const local_io = nullptr) const;
525+
517526
/**
518527
* \returns \p true when this equation system contains
519528
* identical data, up to the given threshold. Delegates

src/systems/equation_systems_io.C

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,23 @@ void EquationSystems::write(std::string_view name,
381381
const XdrMODE mode,
382382
const unsigned int write_flags,
383383
bool partition_agnostic) const
384+
{
385+
Xdr io((this->processor_id()==0) ? std::string(name) : "", mode);
386+
387+
std::unique_ptr<Xdr> local_io;
388+
// open a parallel buffer if warranted
389+
if (write_flags & EquationSystems::WRITE_PARALLEL_FILES && write_flags & EquationSystems::WRITE_DATA)
390+
local_io = std::make_unique<Xdr>(local_file_name(this->processor_id(),name), mode);
391+
392+
this->write(io, write_flags, partition_agnostic, local_io.get());
393+
}
394+
395+
396+
397+
void EquationSystems::write(Xdr & io,
398+
const unsigned int write_flags,
399+
bool partition_agnostic,
400+
Xdr * const local_io) const
384401
{
385402
/**
386403
* This program implements the output of an
@@ -474,9 +491,10 @@ void EquationSystems::write(std::string_view name,
474491
// !this->get_mesh().is_serial())
475492
;
476493

477-
// New scope so that io will close before we try to zip the file
494+
if (write_parallel_files && write_data)
495+
libmesh_assert(local_io);
496+
478497
{
479-
Xdr io((this->processor_id()==0) ? std::string(name) : "", mode);
480498
libmesh_assert (io.writing());
481499

482500
LOG_SCOPE("write()", "EquationSystems");
@@ -554,21 +572,23 @@ void EquationSystems::write(std::string_view name,
554572
// to write vectors to disk, if wanted
555573
if (write_data)
556574
{
557-
// open a parallel buffer if warranted.
558-
Xdr local_io (write_parallel_files ? local_file_name(this->processor_id(),name) : "", mode);
559-
560575
for (auto & pr : _systems)
561576
{
562577
// Ignore this system if it has been marked as hidden
563578
if (pr.second->hide_output()) continue;
564579

565580
// 10.) + 11.)
566581
if (write_parallel_files)
567-
pr.second->write_parallel_data (local_io,write_additional_data);
582+
pr.second->write_parallel_data (*local_io,write_additional_data);
568583
else
569584
pr.second->write_serialized_data (io,write_additional_data);
570585
}
586+
587+
if (local_io)
588+
local_io->close();
571589
}
590+
591+
io.close();
572592
}
573593

574594
// the EquationSystems::write() method should look constant,

0 commit comments

Comments
 (0)