Skip to content

Commit

Permalink
Merge branch 'main' into dokken/ignore-none-sd
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgensd authored Dec 2, 2024
2 parents e5194c3 + 97a802f commit 1d96193
Show file tree
Hide file tree
Showing 31 changed files with 235 additions and 197 deletions.
4 changes: 2 additions & 2 deletions cpp/doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -2268,7 +2268,7 @@ PERLMOD_MAKEVAR_PREFIX =
# C-preprocessor directives found in the sources and include files.
# The default value is: YES.

ENABLE_PREPROCESSING = NO
ENABLE_PREPROCESSING = YES

# If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names
# in the source code. If set to NO, only conditional compilation will be
Expand All @@ -2285,7 +2285,7 @@ MACRO_EXPANSION = YES
# The default value is: NO.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

EXPAND_ONLY_PREDEF = YES
EXPAND_ONLY_PREDEF = NO

# If the SEARCH_INCLUDES tag is set to YES, the include files in the
# INCLUDE_PATH will be searched if a #include is found.
Expand Down
2 changes: 0 additions & 2 deletions cpp/dolfinx/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ set(HEADERS_common
${CMAKE_CURRENT_SOURCE_DIR}/Table.h
${CMAKE_CURRENT_SOURCE_DIR}/Timer.h
${CMAKE_CURRENT_SOURCE_DIR}/TimeLogger.h
${CMAKE_CURRENT_SOURCE_DIR}/TimeLogManager.h
${CMAKE_CURRENT_SOURCE_DIR}/timing.h
${CMAKE_CURRENT_SOURCE_DIR}/utils.h
PARENT_SCOPE
Expand All @@ -26,6 +25,5 @@ target_sources(
${CMAKE_CURRENT_SOURCE_DIR}/MPI.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Table.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TimeLogger.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TimeLogManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/timing.cpp
)
77 changes: 40 additions & 37 deletions cpp/dolfinx/common/MPI.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2007-2023 Magnus Vikstrøm and Garth N. Wells
// Copyright (C) 2007-2023 Magnus Vikstrøm, Garth N. Wells and Paul T. Kühner
//
// This file is part of DOLFINx (https://www.fenicsproject.org)
//
Expand Down Expand Up @@ -271,39 +271,42 @@ struct dependent_false : std::false_type
};

/// MPI Type

/// @brief Type trait for MPI type conversions.
template <typename T>
constexpr MPI_Datatype mpi_type()
{
if constexpr (std::is_same_v<T, float>)
return MPI_FLOAT;
else if constexpr (std::is_same_v<T, double>)
return MPI_DOUBLE;
else if constexpr (std::is_same_v<T, std::complex<double>>)
return MPI_C_DOUBLE_COMPLEX;
else if constexpr (std::is_same_v<T, std::complex<float>>)
return MPI_C_FLOAT_COMPLEX;
else if constexpr (std::is_same_v<T, short int>)
return MPI_SHORT;
else if constexpr (std::is_same_v<T, int>)
return MPI_INT;
else if constexpr (std::is_same_v<T, unsigned int>)
return MPI_UNSIGNED;
else if constexpr (std::is_same_v<T, long int>)
return MPI_LONG;
else if constexpr (std::is_same_v<T, unsigned long>)
return MPI_UNSIGNED_LONG;
else if constexpr (std::is_same_v<T, long long>)
return MPI_LONG_LONG;
else if constexpr (std::is_same_v<T, unsigned long long>)
return MPI_UNSIGNED_LONG_LONG;
else if constexpr (std::is_same_v<T, bool>)
return MPI_C_BOOL;
else if constexpr (std::is_same_v<T, std::int8_t>)
return MPI_INT8_T;
else
// Issue compile time error
static_assert(!std::is_same_v<T, T>);
}
struct mpi_type_mapping;

/// @brief Retrieves the MPI data type associated to the provided type.
/// @tparam T cpp type to map
template <typename T>
MPI_Datatype mpi_t = mpi_type_mapping<T>::type;

/// @brief Registers for cpp_t the corresponding mpi_t which can then be
/// retrieved with mpi_t<cpp_t> from here on.
#define MAP_TO_MPI_TYPE(cpp_t, mpi_t) \
template <> \
struct mpi_type_mapping<cpp_t> \
{ \
static inline MPI_Datatype type = mpi_t; \
};

/// @defgroup MPI type mappings
/// @{
/// @cond
MAP_TO_MPI_TYPE(float, MPI_FLOAT)
MAP_TO_MPI_TYPE(double, MPI_DOUBLE)
MAP_TO_MPI_TYPE(std::complex<float>, MPI_C_FLOAT_COMPLEX)
MAP_TO_MPI_TYPE(std::complex<double>, MPI_C_DOUBLE_COMPLEX)
MAP_TO_MPI_TYPE(std::int8_t, MPI_INT8_T)
MAP_TO_MPI_TYPE(std::int16_t, MPI_INT16_T)
MAP_TO_MPI_TYPE(std::int32_t, MPI_INT32_T)
MAP_TO_MPI_TYPE(std::int64_t, MPI_INT64_T)
MAP_TO_MPI_TYPE(std::uint8_t, MPI_UINT8_T)
MAP_TO_MPI_TYPE(std::uint16_t, MPI_UINT16_T)
MAP_TO_MPI_TYPE(std::uint32_t, MPI_UINT32_T)
MAP_TO_MPI_TYPE(std::uint64_t, MPI_UINT64_T)
/// @endcond
/// @}

//---------------------------------------------------------------------------
template <typename U>
Expand Down Expand Up @@ -434,7 +437,7 @@ distribute_to_postoffice(MPI_Comm comm, const U& x,

// Send/receive data (x)
MPI_Datatype compound_type;
MPI_Type_contiguous(shape[1], dolfinx::MPI::mpi_type<T>(), &compound_type);
MPI_Type_contiguous(shape[1], dolfinx::MPI::mpi_t<T>, &compound_type);
MPI_Type_commit(&compound_type);
std::vector<T> recv_buffer_data(shape[1] * recv_disp.back());
err = MPI_Neighbor_alltoallv(
Expand Down Expand Up @@ -616,7 +619,7 @@ distribute_from_postoffice(MPI_Comm comm, std::span<const std::int64_t> indices,
dolfinx::MPI::check_error(comm, err);

MPI_Datatype compound_type0;
MPI_Type_contiguous(shape[1], dolfinx::MPI::mpi_type<T>(), &compound_type0);
MPI_Type_contiguous(shape[1], dolfinx::MPI::mpi_t<T>, &compound_type0);
MPI_Type_commit(&compound_type0);

std::vector<T> recv_buffer_data(shape[1] * send_disp.back());
Expand Down Expand Up @@ -691,8 +694,8 @@ distribute_data(MPI_Comm comm0, std::span<const std::int64_t> indices,
if (comm1 != MPI_COMM_NULL)
{
rank_offset = 0;
err = MPI_Exscan(&shape0_local, &rank_offset, 1, MPI_INT64_T, MPI_SUM,
comm1);
err = MPI_Exscan(&shape0_local, &rank_offset, 1,
dolfinx::MPI::mpi_t<std::int64_t>, MPI_SUM, comm1);
dolfinx::MPI::check_error(comm1, err);
}
else
Expand Down
34 changes: 16 additions & 18 deletions cpp/dolfinx/common/Scatterer.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ class Scatterer

// Scale sizes and displacements by block size
{
auto rescale = [](auto& x, int bs)
{
auto rescale = [](auto& x, int bs) {
std::ranges::transform(x, x.begin(), [bs](auto e) { return e *= bs; });
};
rescale(_sizes_local, bs);
Expand Down Expand Up @@ -207,11 +206,11 @@ class Scatterer
case type::neighbor:
{
assert(requests.size() == std::size_t(1));
MPI_Ineighbor_alltoallv(
send_buffer.data(), _sizes_local.data(), _displs_local.data(),
dolfinx::MPI::mpi_type<T>(), recv_buffer.data(), _sizes_remote.data(),
_displs_remote.data(), dolfinx::MPI::mpi_type<T>(), _comm0.comm(),
requests.data());
MPI_Ineighbor_alltoallv(send_buffer.data(), _sizes_local.data(),
_displs_local.data(), dolfinx::MPI::mpi_t<T>,
recv_buffer.data(), _sizes_remote.data(),
_displs_remote.data(), dolfinx::MPI::mpi_t<T>,
_comm0.comm(), requests.data());
break;
}
case type::p2p:
Expand All @@ -220,14 +219,14 @@ class Scatterer
for (std::size_t i = 0; i < _src.size(); i++)
{
MPI_Irecv(recv_buffer.data() + _displs_remote[i], _sizes_remote[i],
dolfinx::MPI::mpi_type<T>(), _src[i], MPI_ANY_TAG,
_comm0.comm(), &requests[i]);
dolfinx::MPI::mpi_t<T>, _src[i], MPI_ANY_TAG, _comm0.comm(),
&requests[i]);
}

for (std::size_t i = 0; i < _dest.size(); i++)
{
MPI_Isend(send_buffer.data() + _displs_local[i], _sizes_local[i],
dolfinx::MPI::mpi_type<T>(), _dest[i], 0, _comm0.comm(),
dolfinx::MPI::mpi_t<T>, _dest[i], 0, _comm0.comm(),
&requests[i + _src.size()]);
}
break;
Expand Down Expand Up @@ -404,11 +403,10 @@ class Scatterer
case type::neighbor:
{
assert(requests.size() == 1);
MPI_Ineighbor_alltoallv(send_buffer.data(), _sizes_remote.data(),
_displs_remote.data(), MPI::mpi_type<T>(),
recv_buffer.data(), _sizes_local.data(),
_displs_local.data(), MPI::mpi_type<T>(),
_comm1.comm(), &requests[0]);
MPI_Ineighbor_alltoallv(
send_buffer.data(), _sizes_remote.data(), _displs_remote.data(),
MPI::mpi_t<T>, recv_buffer.data(), _sizes_local.data(),
_displs_local.data(), MPI::mpi_t<T>, _comm1.comm(), &requests[0]);
break;
}
case type::p2p:
Expand All @@ -418,16 +416,16 @@ class Scatterer
for (std::size_t i = 0; i < _dest.size(); i++)
{
MPI_Irecv(recv_buffer.data() + _displs_local[i], _sizes_local[i],
dolfinx::MPI::mpi_type<T>(), _dest[i], MPI_ANY_TAG,
_comm0.comm(), &requests[i]);
dolfinx::MPI::mpi_t<T>, _dest[i], MPI_ANY_TAG, _comm0.comm(),
&requests[i]);
}

// Start non-blocking receive from neighbor process for which an owned
// index is a ghost.
for (std::size_t i = 0; i < _src.size(); i++)
{
MPI_Isend(send_buffer.data() + _displs_remote[i], _sizes_remote[i],
dolfinx::MPI::mpi_type<T>(), _src[i], 0, _comm0.comm(),
dolfinx::MPI::mpi_t<T>, _src[i], 0, _comm0.comm(),
&requests[i + _dest.size()]);
}
break;
Expand Down
5 changes: 3 additions & 2 deletions cpp/dolfinx/common/Table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ Table Table::reduce(MPI_Comm comm, Table::Reduction reduction) const
std::partial_sum(pcounts.begin(), pcounts.end(), offsets.begin() + 1);

std::vector<double> values_all(offsets.back());
err = MPI_Gatherv(values.data(), values.size(), MPI_DOUBLE, values_all.data(),
pcounts.data(), offsets.data(), MPI_DOUBLE, 0, comm);
err = MPI_Gatherv(values.data(), values.size(), dolfinx::MPI::mpi_t<double>,
values_all.data(), pcounts.data(), offsets.data(),
dolfinx::MPI::mpi_t<double>, 0, comm);
dolfinx::MPI::check_error(comm, err);

// Return empty table on rank > 0
Expand Down
18 changes: 0 additions & 18 deletions cpp/dolfinx/common/TimeLogManager.cpp

This file was deleted.

23 changes: 0 additions & 23 deletions cpp/dolfinx/common/TimeLogManager.h

This file was deleted.

7 changes: 7 additions & 0 deletions cpp/dolfinx/common/TimeLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
using namespace dolfinx;
using namespace dolfinx::common;

//-----------------------------------------------------------------------------
TimeLogger& TimeLogger::instance()
{
static TimeLogger _instance{};
return _instance;
}

//-----------------------------------------------------------------------------
void TimeLogger::register_timing(
std::string task, std::chrono::duration<double, std::ratio<1>> time)
Expand Down
31 changes: 19 additions & 12 deletions cpp/dolfinx/common/TimeLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,16 @@

namespace dolfinx::common
{
/// Timer logging
/// @brief Time logger maintaining data collected by Timer, if registered.
///
/// @note This is a monotstate, i.e. the data members are static and thus
/// timings are aggregated into a single map.
class TimeLogger
{
public:
/// Constructor
TimeLogger() = default;

// This class is used as a singleton and thus should not allow copies.
TimeLogger(const TimeLogger&) = delete;

// This class is used as a singleton and thus should not allow copies.
TimeLogger& operator=(const TimeLogger&) = delete;

/// Destructor
~TimeLogger() = default;
/// @brief Singleton access.
/// @return Unique time logger object.
static TimeLogger& instance();

/// Register timing (for later summary)
void register_timing(std::string task,
Expand Down Expand Up @@ -58,6 +53,18 @@ class TimeLogger
timings() const;

private:
/// Constructor
TimeLogger() = default;

// This class is used as a singleton and thus should not allow copies.
TimeLogger(const TimeLogger&) = delete;

// This class is used as a singleton and thus should not allow copies.
TimeLogger& operator=(const TimeLogger&) = delete;

/// Destructor
~TimeLogger() = default;

// List of timings for tasks, map from string to (num_timings,
// total_wall_time)
std::map<std::string,
Expand Down
7 changes: 4 additions & 3 deletions cpp/dolfinx/common/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

#pragma once

#include "TimeLogManager.h"
#include <chrono>
#include <optional>
#include <stdexcept>
#include <string>

#include "TimeLogger.h"

namespace dolfinx::common
{
/// @brief Timer for measuring and logging elapsed time durations.
Expand Down Expand Up @@ -56,7 +57,7 @@ class Timer
if (_start_time.has_value() and _task.has_value())
{
_acc += T::now() - *_start_time;
TimeLogManager::logger().register_timing(*_task, _acc);
TimeLogger::instance().register_timing(*_task, _acc);
}
}

Expand Down Expand Up @@ -121,7 +122,7 @@ class Timer

if (_task.has_value())
{
TimeLogManager::logger().register_timing(*_task, _acc);
TimeLogger::instance().register_timing(*_task, _acc);
_task = std::nullopt;
}
}
Expand Down
Loading

0 comments on commit 1d96193

Please sign in to comment.