Skip to content

Commit

Permalink
Merge branch 'main' into create_rectangle
Browse files Browse the repository at this point in the history
  • Loading branch information
garth-wells authored Sep 11, 2024
2 parents 4d58854 + 442117b commit 9c6c598
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 44 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
name: macOS build

on:
schedule:
# '*' is a special character in YAML, so string must be quoted
- cron: "0 4 * * WED"
pull_request:
branches:
- main
push:
branches:
- "main"
tags:
- "v*"
merge_group:
branches:
- main
workflow_dispatch:

jobs:
Expand Down
17 changes: 5 additions & 12 deletions cpp/dolfinx/common/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,14 @@
#include "Timer.h"
#include "TimeLogManager.h"
#include "TimeLogger.h"
#include <optional>
#include <stdexcept>

using namespace dolfinx;
using namespace dolfinx::common;

//-----------------------------------------------------------------------------
Timer::Timer() : Timer::Timer("")
{
// Do nothing
}
//-----------------------------------------------------------------------------
Timer::Timer(const std::string& task) : _task(task)
{
// Do nothing
}
Timer::Timer(std::optional<std::string> task) : _task(task) {}
//-----------------------------------------------------------------------------
Timer::~Timer()
{
Expand All @@ -33,7 +26,7 @@ void Timer::start() { _timer.start(); }
//-----------------------------------------------------------------------------
void Timer::resume()
{
if (!_task.empty())
if (_task.has_value())
{
throw std::runtime_error(
"Resuming is not well-defined for logging timer. Only "
Expand All @@ -46,8 +39,8 @@ double Timer::stop()
{
_timer.stop();
const auto [wall, user, system] = this->elapsed();
if (!_task.empty())
TimeLogManager::logger().register_timing(_task, wall, user, system);
if (_task.has_value())
TimeLogManager::logger().register_timing(_task.value(), wall, user, system);
return wall;
}
//-----------------------------------------------------------------------------
Expand Down
13 changes: 7 additions & 6 deletions cpp/dolfinx/common/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <array>
#include <boost/timer/timer.hpp>
#include <optional>
#include <string>

namespace dolfinx::common
Expand All @@ -30,11 +31,11 @@ namespace dolfinx::common
class Timer
{
public:
/// Create timer without logging
Timer();

/// Create timer with logging
Timer(const std::string& task);
/// Create timer
///
/// If a task name is provided this enables logging to logger, otherwise (i.e.
/// no task provided) nothing gets logged.
Timer(std::optional<std::string> task = std::nullopt);

/// Destructor
~Timer();
Expand All @@ -54,7 +55,7 @@ class Timer

private:
// Name of task
std::string _task;
std::optional<std::string> _task;

// Implementation of timer
boost::timer::cpu_timer _timer;
Expand Down
39 changes: 26 additions & 13 deletions cpp/dolfinx/fem/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ get_cell_orientation_info(const Function<T, U>& coefficient)
}

/// Pack a single coefficient for a single cell
template <dolfinx::scalar T, int _bs>
template <int _bs, dolfinx::scalar T>
void pack(std::span<T> coeffs, std::int32_t cell, int bs, std::span<const T> v,
std::span<const std::uint32_t> cell_info, const DofMap& dofmap,
auto transform)
Expand All @@ -869,6 +869,7 @@ void pack(std::span<T> coeffs, std::int32_t cell, int bs, std::span<const T> v,
}
else
{
assert(_bs == bs);
const int pos_c = _bs * i;
const int pos_v = _bs * dofs[i];
for (int k = 0; k < _bs; ++k)
Expand Down Expand Up @@ -926,36 +927,47 @@ void pack_coefficient_entity(std::span<T> c, int cstride,
for (std::size_t e = 0; e < entities.size(); e += estride)
{
auto entity = entities.subspan(e, estride);
std::int32_t cell = fetch_cells(entity);
auto cell_coeff = c.subspan((e / estride) * cstride + offset, space_dim);
pack<T, 1>(cell_coeff, cell, bs, v, cell_info, dofmap, transformation);
if (std::int32_t cell = fetch_cells(entity); cell >= 0)
{
auto cell_coeff
= c.subspan((e / estride) * cstride + offset, space_dim);
pack<1>(cell_coeff, cell, bs, v, cell_info, dofmap, transformation);
}
}
break;
case 2:
for (std::size_t e = 0; e < entities.size(); e += estride)
{
auto entity = entities.subspan(e, estride);
std::int32_t cell = fetch_cells(entity);
auto cell_coeff = c.subspan((e / estride) * cstride + offset, space_dim);
pack<T, 2>(cell_coeff, cell, bs, v, cell_info, dofmap, transformation);
if (std::int32_t cell = fetch_cells(entity); cell >= 0)
{
auto cell_coeff
= c.subspan((e / estride) * cstride + offset, space_dim);
pack<2>(cell_coeff, cell, bs, v, cell_info, dofmap, transformation);
}
}
break;
case 3:
for (std::size_t e = 0; e < entities.size(); e += estride)
{
auto entity = entities.subspan(e, estride);
std::int32_t cell = fetch_cells(entity);
auto cell_coeff = c.subspan(e / estride * cstride + offset, space_dim);
pack<T, 3>(cell_coeff, cell, bs, v, cell_info, dofmap, transformation);
if (std::int32_t cell = fetch_cells(entity); cell >= 0)
{
auto cell_coeff = c.subspan(e / estride * cstride + offset, space_dim);
pack<3>(cell_coeff, cell, bs, v, cell_info, dofmap, transformation);
}
}
break;
default:
for (std::size_t e = 0; e < entities.size(); e += estride)
{
auto entity = entities.subspan(e, estride);
std::int32_t cell = fetch_cells(entity);
auto cell_coeff = c.subspan((e / estride) * cstride + offset, space_dim);
pack<T, -1>(cell_coeff, cell, bs, v, cell_info, dofmap, transformation);
if (std::int32_t cell = fetch_cells(entity); cell >= 0)
{
auto cell_coeff
= c.subspan((e / estride) * cstride + offset, space_dim);
pack<-1>(cell_coeff, cell, bs, v, cell_info, dofmap, transformation);
}
}
break;
}
Expand Down Expand Up @@ -1128,6 +1140,7 @@ void pack_coefficients(const Form<T, U>& form, IntegralType integral_type,
auto mesh = coefficients[coeff]->function_space()->mesh();
std::vector<std::int32_t> facets
= form.domain(IntegralType::interior_facet, id, *mesh);

std::span<const std::uint32_t> cell_info
= impl::get_cell_orientation_info(*coefficients[coeff]);

Expand Down
5 changes: 1 addition & 4 deletions python/dolfinx/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ class Timer:
_cpp_object: _cpp.common.Timer

def __init__(self, name: typing.Optional[str] = None):
if name is None:
self._cpp_object = _cpp.common.Timer()
else:
self._cpp_object = _cpp.common.Timer(name)
self._cpp_object = _cpp.common.Timer(name)

def __enter__(self):
self._cpp_object.start()
Expand Down
10 changes: 5 additions & 5 deletions python/dolfinx/wrappers/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@

#include <complex>
#include <memory>
#include <optional>
#include <span>
#include <string>
#include <vector>

#include <nanobind/nanobind.h>
#include <nanobind/ndarray.h>
#include <nanobind/stl/array.h>
#include <nanobind/stl/optional.h>
#include <nanobind/stl/pair.h>
#include <nanobind/stl/string.h>
#include <nanobind/stl/tuple.h>
#include <nanobind/stl/vector.h>

#include <dolfinx/common/defines.h>
#include <dolfinx/common/defines.h>
#include <dolfinx/common/IndexMap.h>
#include <dolfinx/common/log.h>
#include <dolfinx/common/Scatterer.h>
#include <dolfinx/common/Table.h>
#include <dolfinx/common/Timer.h>
#include <dolfinx/common/defines.h>
#include <dolfinx/common/log.h>
#include <dolfinx/common/timing.h>
#include <dolfinx/common/utils.h>

Expand Down Expand Up @@ -152,8 +153,7 @@ void common(nb::module_& m)
nb::arg("global"));
// dolfinx::common::Timer
nb::class_<dolfinx::common::Timer>(m, "Timer", "Timer class")
.def(nb::init<>())
.def(nb::init<std::string>(), nb::arg("task"))
.def(nb::init<std::optional<std::string>>(), nb::arg("task").none())
.def("start", &dolfinx::common::Timer::start, "Start timer")
.def("stop", &dolfinx::common::Timer::stop, "Stop timer")
.def("resume", &dolfinx::common::Timer::resume)
Expand Down
Loading

0 comments on commit 9c6c598

Please sign in to comment.