Skip to content

Commit

Permalink
Flush timers
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisrichardson committed Dec 9, 2024
1 parent b264f2f commit 8d946f1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cgpoisson_problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ cgpoisson::problem(std::shared_ptr<mesh::Mesh<double>> mesh, int order,
fem::create_functionspace(mesh, dolfinx_element));

t0.stop();
t0.flush();

common::Timer t1("ZZZ Assemble");

Expand Down Expand Up @@ -94,6 +95,7 @@ cgpoisson::problem(std::shared_ptr<mesh::Mesh<double>> mesh, int order,

auto bc = std::make_shared<fem::DirichletBC<T>>(u0, bdofs);
t2.stop();
t2.flush();

// Define coefficients
common::Timer t3("ZZZ Create RHS function");
Expand Down Expand Up @@ -122,6 +124,7 @@ cgpoisson::problem(std::shared_ptr<mesh::Mesh<double>> mesh, int order,
return {f, {f.size()}};
});
t3.stop();
t3.flush();

std::vector form_poisson_L
= {form_Poisson_L1, form_Poisson_L2, form_Poisson_L3};
Expand Down
7 changes: 7 additions & 0 deletions src/elasticity_problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ elastic::problem(std::shared_ptr<mesh::Mesh<double>> mesh, int order)
fem::create_functionspace(mesh, dolfinx_element));

t0.stop();
t0.flush();

common::Timer t0a("ZZZ Create boundary conditions");

Expand Down Expand Up @@ -144,6 +145,7 @@ elastic::problem(std::shared_ptr<mesh::Mesh<double>> mesh, int order)
auto bc = std::make_shared<const fem::DirichletBC<T>>(u0, bdofs);

t0a.stop();
t0a.flush();

common::Timer t0b("ZZZ Create RHS function");

Expand Down Expand Up @@ -174,6 +176,7 @@ elastic::problem(std::shared_ptr<mesh::Mesh<double>> mesh, int order)
});

t0b.stop();
t0b.flush();

common::Timer t0c("ZZZ Create forms");

Expand All @@ -187,6 +190,7 @@ elastic::problem(std::shared_ptr<mesh::Mesh<double>> mesh, int order)
auto a = std::make_shared<const fem::Form<T, double>>(fem::create_form<T>(
*form_elasticity_a.at(order - 1), {V, V}, {}, {}, {}, {}));
t0c.stop();
t0c.flush();

// Create matrices and vector, and assemble system
std::shared_ptr<la::petsc::Matrix> A = std::make_shared<la::petsc::Matrix>(
Expand All @@ -206,6 +210,7 @@ elastic::problem(std::shared_ptr<mesh::Mesh<double>> mesh, int order)
MatAssemblyBegin(A->mat(), MAT_FINAL_ASSEMBLY);
MatAssemblyEnd(A->mat(), MAT_FINAL_ASSEMBLY);
t2.stop();
t2.flush();

// Wrap la::Vector with Petsc Vec
la::Vector<T> b(L->function_spaces()[0]->dofmap()->index_map,
Expand All @@ -223,6 +228,7 @@ elastic::problem(std::shared_ptr<mesh::Mesh<double>> mesh, int order)
b.scatter_rev(std::plus<>());
bc->set(b.mutable_array(), std::nullopt);
t3.stop();
t3.flush();

common::Timer t4("ZZZ Create near-nullspace");

Expand All @@ -235,6 +241,7 @@ elastic::problem(std::shared_ptr<mesh::Mesh<double>> mesh, int order)
MatNullSpaceDestroy(&ns);

t4.stop();
t4.flush();

std::function<int(fem::Function<T>&, const la::Vector<T>&)> solver_function
= [A](fem::Function<T>& u, const la::Vector<T>& b)
Expand Down
7 changes: 7 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,14 @@ void solve(int argc, char* argv[])
ndofs_per_node);
}
t0.stop();
t0.flush();

dolfinx::common::Timer t_ent(
"ZZZ Create facets and facet->cell connectivity");
mesh->topology_mutable()->create_entities(2);
mesh->topology_mutable()->create_connectivity(2, 3);
t_ent.stop();
t_ent.flush();

if (problem_type == "poisson")
{
Expand Down Expand Up @@ -206,6 +208,7 @@ void solve(int argc, char* argv[])
dolfinx::common::Timer t5("ZZZ Solve");
int num_iter = solver_function(*u, *b);
t5.stop();
t5.flush();

if (output)
{
Expand All @@ -216,6 +219,7 @@ void solve(int argc, char* argv[])
file.write_mesh(*mesh);
file.write_function(*u, 0.0);
t6.stop();
t6.flush();
}

// Display timings
Expand All @@ -241,14 +245,17 @@ int main(int argc, char* argv[])
dolfinx::common::Timer t0("Init MPI");
MPI_Init(&argc, &argv);
t0.stop();
t0.flush();

dolfinx::common::Timer t1("Init logging");
dolfinx::init_logging(argc, argv);
t1.stop();
t1.flush();

dolfinx::common::Timer t2("Init PETSc");
PetscInitialize(&argc, &argv, nullptr, nullptr);
t2.stop();
t2.flush();

// Set the logging thread name to show the process rank and enable on
// rank 0 (add more here if desired)
Expand Down
6 changes: 6 additions & 0 deletions src/poisson_problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ poisson::problem(std::shared_ptr<mesh::Mesh<double>> mesh, int order)
fem::create_functionspace(mesh, dolfinx_element));

t0.stop();
t0.flush();

common::Timer t1("ZZZ Assemble");

Expand Down Expand Up @@ -75,6 +76,7 @@ poisson::problem(std::shared_ptr<mesh::Mesh<double>> mesh, int order)

auto bc = std::make_shared<fem::DirichletBC<T>>(u0, bdofs);
t2.stop();
t2.flush();

// Define coefficients
common::Timer t3("ZZZ Create RHS function");
Expand Down Expand Up @@ -103,6 +105,7 @@ poisson::problem(std::shared_ptr<mesh::Mesh<double>> mesh, int order)
return {f, {f.size()}};
});
t3.stop();
t3.flush();

std::vector form_poisson_L
= {form_Poisson_L1, form_Poisson_L2, form_Poisson_L3};
Expand Down Expand Up @@ -133,6 +136,7 @@ poisson::problem(std::shared_ptr<mesh::Mesh<double>> mesh, int order)
MatAssemblyBegin(A->mat(), MAT_FINAL_ASSEMBLY);
MatAssemblyEnd(A->mat(), MAT_FINAL_ASSEMBLY);
t4.stop();
t4.flush();

// Create la::Vector
la::Vector<T> b(L->function_spaces()[0]->dofmap()->index_map,
Expand All @@ -150,8 +154,10 @@ poisson::problem(std::shared_ptr<mesh::Mesh<double>> mesh, int order)
b.scatter_rev(std::plus<>());
bc->set(b.mutable_array(), std::nullopt);
t5.stop();
t5.flush();

t1.stop();
t1.flush();

// Create Function to hold solution
auto u = std::make_shared<fem::Function<T>>(V);
Expand Down

0 comments on commit 8d946f1

Please sign in to comment.