Skip to content

Commit

Permalink
Merge branch 'HmAssemblyMixins' into 'master'
Browse files Browse the repository at this point in the history
Parallel assembly in HM

See merge request ogs/ogs!5054
  • Loading branch information
endJunction committed Aug 14, 2024
2 parents fea65d5 + 86f3b6c commit 6f76fcd
Show file tree
Hide file tree
Showing 20 changed files with 422 additions and 278 deletions.
7 changes: 7 additions & 0 deletions BaseLib/ThreadException.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

/// Initial code from
/// https://stackoverflow.com/questions/11828539/elegant-exception-handling-in-openmp
///
/// The implementation does not guarantee, that while the exception is being
/// checked for nullptr in the bool-conversion operator, the capture is not
/// changing the pointer. This might lead to an exception being lost if there
/// are two exceptions thrown simultaneously.
class ThreadException
{
public:
Expand All @@ -31,6 +36,8 @@ class ThreadException
}
}

explicit operator bool() const noexcept { return exception_ != nullptr; }

private:
std::exception_ptr exception_ = nullptr;
std::mutex lock_;
Expand Down
47 changes: 35 additions & 12 deletions ProcessLib/Assembly/MatrixOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,9 @@ GlobalMatrixOutput::GlobalMatrixOutput()
}

void GlobalMatrixOutput::operator()(double const t, int const process_id,
GlobalMatrix const* M,
GlobalMatrix const* K,
GlobalVector const& b,
GlobalMatrix const* const Jac)
GlobalMatrix const& M,
GlobalMatrix const& K,
GlobalVector const& b)
{
if (!do_output_)
{
Expand All @@ -188,22 +187,20 @@ void GlobalMatrixOutput::operator()(double const t, int const process_id,
#ifndef USE_PETSC
++counter_;

if (M)
{
auto fh = openGlobalMatrixOutputFile(filenamePrefix_, counter_, t,
process_id, "M", "mat");

fh << "M ";
outputGlobalMatrix(*M, fh);
outputGlobalMatrix(M, fh);
}

if (K)
{
auto fh = openGlobalMatrixOutputFile(filenamePrefix_, counter_, t,
process_id, "K", "mat");

fh << "K ";
outputGlobalMatrix(*K, fh);
outputGlobalMatrix(K, fh);
}

{
Expand All @@ -213,21 +210,47 @@ void GlobalMatrixOutput::operator()(double const t, int const process_id,
fh << "b ";
outputGlobalVector(b, fh);
}
#else
// do nothing, warning message already printed in the constructor
(void)t;
(void)process_id;
(void)M;
(void)K;
(void)b;
#endif
}

void GlobalMatrixOutput::operator()(double const t, int const process_id,
GlobalVector const& b,
GlobalMatrix const& Jac)
{
if (!do_output_)
{
return;
}

#ifndef USE_PETSC
++counter_;

{
auto fh = openGlobalMatrixOutputFile(filenamePrefix_, counter_, t,
process_id, "b", "vec");

fh << "b ";
outputGlobalVector(b, fh);
}

if (Jac)
{
auto fh = openGlobalMatrixOutputFile(filenamePrefix_, counter_, t,
process_id, "Jac", "mat");

fh << "Jac ";
outputGlobalMatrix(*Jac, fh);
outputGlobalMatrix(Jac, fh);
}
#else
// do nothing, warning message already printed in the constructor
(void)t;
(void)process_id;
(void)M;
(void)K;
(void)b;
(void)Jac;
#endif
Expand Down
8 changes: 5 additions & 3 deletions ProcessLib/Assembly/MatrixOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ struct GlobalMatrixOutput
{
GlobalMatrixOutput();

void operator()(double const t, int const process_id, GlobalMatrix const* M,
GlobalMatrix const* K, GlobalVector const& b,
GlobalMatrix const* const Jac = nullptr);
void operator()(double const t, int const process_id, GlobalMatrix const& M,
GlobalMatrix const& K, GlobalVector const& b);

void operator()(double const t, int const process_id, GlobalVector const& b,
GlobalMatrix const& Jac);

private:
std::string filenamePrefix_;
Expand Down
Loading

0 comments on commit 6f76fcd

Please sign in to comment.