Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
c552fb4
first step to compile
Yushan-Wang Feb 12, 2026
b39862f
Merge branch 'main' into add-a-timer-report
Yushan-Wang Mar 9, 2026
d0f3540
add a timer class
Yushan-Wang Mar 12, 2026
925f489
add timer for pdi init and finalize
Yushan-Wang Mar 12, 2026
f64e41f
add timer option in cmake
Yushan-Wang Mar 12, 2026
2771711
add timer for hdf5
Yushan-Wang Mar 12, 2026
01c5e3f
add timer for netcdf
Yushan-Wang Mar 12, 2026
b532a08
add timer for json
Yushan-Wang Mar 12, 2026
e6be2ed
add timer for serialize
Yushan-Wang Mar 12, 2026
a72d07d
add timer for user_code
Yushan-Wang Mar 12, 2026
a4eda90
Merge branch 'main' into add-a-timer-report
Yushan-Wang Mar 12, 2026
fdbfc18
revert non-relevant change
Yushan-Wang Mar 12, 2026
bef38f9
revert non-relevant change
Yushan-Wang Mar 12, 2026
b7f00e2
revert non-relevant change
Yushan-Wang Mar 12, 2026
194aeec
revert non-relevant change
Yushan-Wang Mar 12, 2026
0e08740
fix indent
Yushan-Wang Mar 12, 2026
9d19822
output cleanup
Yushan-Wang Mar 13, 2026
5f843fe
add example yaml for timing multiple plugins.
Yushan-Wang Mar 13, 2026
cfc462d
add timer for pycall
Yushan-Wang Mar 13, 2026
e851c0c
indent
Yushan-Wang Mar 13, 2026
141647e
fix copyright date
Yushan-Wang Mar 13, 2026
a7fc397
update changelog
Yushan-Wang Mar 13, 2026
ee0508b
make timer inside the context
Yushan-Wang Mar 20, 2026
28e3bbc
update mock
Yushan-Wang Mar 20, 2026
261c89e
fix indent
Yushan-Wang Mar 20, 2026
f69fc66
indent
Yushan-Wang Mar 20, 2026
89f658c
remove old calls
Yushan-Wang Mar 20, 2026
e2c23d1
reactive unit tests
Yushan-Wang Mar 20, 2026
b82a3fb
Remove Apple-specific link options from CMakeLists
Yushan-Wang Mar 31, 2026
a543aa5
Remove Apple-specific link options from CMakeLists
Yushan-Wang Mar 31, 2026
12ac8da
update changelog
Yushan-Wang Mar 31, 2026
f0f13dd
update copyright end date
Yushan-Wang Mar 31, 2026
b89a412
Merge branch 'add-a-timer-report' of https://github.com/Yushan-Wang/p…
Yushan-Wang Mar 31, 2026
8875860
Add optional yaml config member to enable timer, and add an integrati…
JAuriac Apr 1, 2026
04d73e3
rename example.yml to timer.yml
Yushan-Wang Apr 2, 2026
f3b62fa
code cleanup based on review notes
Yushan-Wang Apr 2, 2026
a6d2617
code cleanup [skip ci]
Yushan-Wang Apr 3, 2026
6b8b829
Modify HDF5 configuration in CMakeLists.txt
Yushan-Wang Apr 3, 2026
1717266
variable rename
Yushan-Wang Apr 3, 2026
fe20d6d
Merge branch 'add-a-timer-report' of https://github.com/Yushan-Wang/p…
Yushan-Wang Apr 3, 2026
11da4ee
better check for calling timer
Yushan-Wang Apr 3, 2026
5fe23ae
Merge branch 'main' into add-a-timer-report
Yushan-Wang Apr 17, 2026
63f0ca7
implement timer as plugin
Yushan-Wang Apr 21, 2026
50918db
Merge branch 'main' into add-a-timer-report
Yushan-Wang Apr 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to
### For users

#### Added
* A timer is added to reflect the time consumed by plugins.

#### Changed

Expand Down
14 changes: 10 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ option(BUILD_SHARED_LIBS "Build shared libraries rather than static ones"
option(BUILD_TRACE_PLUGIN "Build Trace plugin" ON)
option(BUILD_USER_CODE_PLUGIN "Build User-code plugin" ON)
option(BUILD_JSON_PLUGIN "Build JSON plugin" OFF)
option(BUILD_TIMER_PLUGIN "Build Timer plugin" ON)
option(ENABLE_BENCHMARKING "Activate benchmarks in the test suite" OFF)



### Default build type

if(NOT DEFINED CMAKE_BUILD_TYPE)
Expand Down Expand Up @@ -295,9 +294,9 @@ endif()
## HDF5

if("${BUILD_DECL_HDF5_PLUGIN}" OR "${BUILD_DECL_NETCDF_PLUGIN}")

set(HDF5_CMAKE_CACHE_ARGS)

if("${BUILD_HDF5_PARALLEL}")
set(HDF5_PREFER_PARALLEL ON)
list(APPEND HDF5_CMAKE_CACHE_ARGS "-DHDF5_ENABLE_PARALLEL:BOOL=ON")
Expand Down Expand Up @@ -536,3 +535,10 @@ sbuild_add_module(PDI_API_TESTS
INSTALL_COMMAND ""
SUBSTEPS test
)

sbuild_add_module(TIMER_PLUGIN
ENABLE_BUILD_FLAG BUILD_TIMER_PLUGIN
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/plugins/timer"
DEPENDS PDI
# SUBSTEPS indent test
)
57 changes: 57 additions & 0 deletions example/timer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# duration in seconds
duration: 0.75
# global [height, width] (excluding boundary conditions or ghosts)
datasize: [60, 12]
# degree of parallelism
parallelism: { height: 3, width: 1 }

# only the following config is passed to PDI
pdi:
metadata: # type of small values for which PDI keeps a copy
iter: int # current iteration id
dsize: { size: 2, type: array, subtype: int } # local data size including ghosts/boundary
psize: { size: 2, type: array, subtype: int } # number of processes in each dimension
pcoord: { size: 2, type: array, subtype: int } # coordinate of the process
data: # type of values for which PDI does not keep a copy
main_field: { size: [ '$dsize[0]', '$dsize[1]' ], type: array, subtype: double }
timer: true
plugins:
mpi:
decl_hdf5:
file: data.h5
communicator: $MPI_COMM_WORLD # the MPI communicator used for HDF5 parallel synchronized write
datasets: # type of the datasets to create in file
data:
type: array
subtype: double
size: [10, '$psize[0]*($dsize[0]-2)', '$psize[1]*($dsize[1]-2)']
write:
main_field: # the name of the data to write
dataset: data
mpio: COLLECTIVE # or INDEPENDENT
when: '$iter<10' # do only write the first 10 iterations (0...9)
memory_selection: # exclude ghosts from the data in memory
size: ['$dsize[0]-2', '$dsize[1]-2']
start: [1, 1]
dataset_selection: # only write into a single slice in time
size: [1, '$dsize[0]-2', '$dsize[1]-2']
start: [$iter, '($dsize[0]-2)*$pcoord[0]', '($dsize[1]-2)*$pcoord[1]']
decl_netcdf:
file: data.nc
communicator: $MPI_COMM_WORLD # the MPI communicator used for HDF5 parallel synchronized write
variables: # type of the datasets to create in file
v_data:
type: array
subtype: double
size: [10, '$psize[0]*$dsize[0]', '$psize[1]*$dsize[1]']
write:
main_field: # the name of the data to write
variable: v_data
when: '$iter<10' # do only write the first 10 iterations (0...9)
variable_selection: # only write into a single slice in time
subsize: [1, '$dsize[0]', '$dsize[1]']
start: [$iter, '$dsize[0]*$pcoord[0]', '$dsize[1]*$pcoord[1]']
json:
file: data_${pcoord[0]}_${pcoord[1]}.json
when: '$iter<10'
write: [main_field]
1 change: 1 addition & 0 deletions pdi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ set(PDI_C_SRC
src/ref_any.cxx
src/scalar_datatype.cxx
src/string_tools.cxx
src/timer.cxx
src/tuple_datatype.cxx
)
add_library(PDI_C ${PDI_C_SRC})
Expand Down
8 changes: 7 additions & 1 deletion pdi/include/pdi/context.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (C) 2015-2024 Commissariat a l'energie atomique et aux energies alternatives (CEA)
* Copyright (C) 2015-2026 Commissariat a l'energie atomique et aux energies alternatives (CEA)
* Copyright (C) 2021 Institute of Bioorganic Chemistry Polish Academy of Science (PSNC)
* All rights reserved.
*
Expand Down Expand Up @@ -37,6 +37,7 @@
#include <pdi/datatype_template.h>
#include <pdi/logger.h>
#include <pdi/ref_any.h>
#include <pdi/timer.h>

namespace PDI {

Expand Down Expand Up @@ -114,6 +115,11 @@ class PDI_EXPORT Context
*/
virtual Logger& logger() = 0;

/** Timer getter
* \return timer
*/
virtual Timer& timer() = 0;

/** Callbacks of the context
* \return context callbacks
*/
Expand Down
11 changes: 10 additions & 1 deletion pdi/include/pdi/context_proxy.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (C) 2021-2024 Commissariat a l'energie atomique et aux energies alternatives (CEA)
* Copyright (C) 2021-2026 Commissariat a l'energie atomique et aux energies alternatives (CEA)
* Copyright (C) 2019-2021 Institute of Bioorganic Chemistry Polish Academy of Science (PSNC)
* All rights reserved.
*
Expand Down Expand Up @@ -30,6 +30,7 @@
#include <pdi/callbacks.h>
#include <pdi/context.h>
#include <pdi/logger.h>
#include <pdi/timer.h>

#include <functional>
#include <string>
Expand All @@ -44,6 +45,8 @@ class PDI_EXPORT Context_proxy: public Context
/// Logger of the plugin
Logger m_plugin_logger;

Timer* m_timer;

public:
/** Creates Context proxy without plugin logger
* \param[in] ctx context to make a proxy
Expand Down Expand Up @@ -101,6 +104,12 @@ class PDI_EXPORT Context_proxy: public Context
*/
Logger& logger() override;

/** Returns plugin timer
*
* \return plugin timer
*/
Timer& timer() override;

/** Returns pdi core logger
*
* \return pdi core logger
Expand Down
60 changes: 60 additions & 0 deletions pdi/include/pdi/timer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*******************************************************************************
* Copyright (C) 2026 Commissariat a l'energie atomique et aux energies alternatives (CEA)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of CEA nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific
* prior written permission.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/

#ifndef PDI_TIMER_H_
#define PDI_TIMER_H_

#include <chrono>
#include <iostream>
#include <map>
#include <string>
#include <utility>

#include <pdi/pdi_fwd.h>

namespace PDI {

class PDI_EXPORT Timer
{
public:
Timer(const Timer&) = delete;

Timer() {}

void operator= (const Timer&) = delete;

void startTimer(const std::string& name);
void stopTimer(const std::string& name);
void printReport() const;
void printReport(const std::string& name) const;

void enable_timer(const bool choice) { timer_enabled = choice; }

private:
std::map<std::string, std::chrono::high_resolution_clock::time_point> start_times;
std::map<std::string, double> accumulated_times;
bool timer_enabled = false;
};
} // namespace PDI
#endif // PDI_TIMER_H_
8 changes: 8 additions & 0 deletions pdi/src/context_proxy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "pdi/context.h"
#include "pdi/context_proxy.h"
#include "pdi/logger.h"
#include "pdi/timer.h"

using std::string;

Expand All @@ -34,10 +35,12 @@ namespace PDI {

Context_proxy::Context_proxy(Context& ctx)
: m_real_context{ctx}
, m_timer{&(ctx.timer())}
{}

Context_proxy::Context_proxy(Context& ctx, const string& logger_name, PC_tree_t logging_tree)
: m_real_context{ctx}
, m_timer{&(ctx.timer())}
, m_plugin_logger{m_real_context.logger(), logger_name, logging_tree}
{}

Expand Down Expand Up @@ -91,6 +94,11 @@ Logger& Context_proxy::logger()
return m_plugin_logger;
}

Timer& Context_proxy::timer()
{
return *m_timer;
}

Logger& Context_proxy::pdi_core_logger()
{
return m_real_context.logger();
Expand Down
10 changes: 10 additions & 0 deletions pdi/src/global_context.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ Global_context::Global_context(PC_tree_t conf)
, m_plugins{*this, conf}
, m_callbacks{*this}
{
PC_tree_t timer_node = PC_get(conf, ".timer");
if (!PC_status(timer_node)) {
m_timer.enable_timer(to_bool(timer_node));
}

// load basic datatypes
Datatype_template::load_basic_datatypes(*this);
// load user datatypes
Expand Down Expand Up @@ -183,6 +188,11 @@ Logger& Global_context::logger()
return m_logger;
}

Timer& Global_context::timer()
{
return m_timer;
}

Datatype_template_sptr Global_context::datatype(PC_tree_t node)
{
string type;
Expand Down
8 changes: 7 additions & 1 deletion pdi/src/global_context.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (C) 2015-2025 Commissariat a l'energie atomique et aux energies alternatives (CEA)
* Copyright (C) 2015-2026 Commissariat a l'energie atomique et aux energies alternatives (CEA)
* Copyright (C) 2021 Institute of Bioorganic Chemistry Polish Academy of Science (PSNC)
* All rights reserved.
*
Expand Down Expand Up @@ -41,6 +41,7 @@
#include "pdi/logger.h"
#include "pdi/plugin.h"
#include "pdi/ref_any.h"
#include "pdi/timer.h"

#include "plugin_store.h"

Expand All @@ -57,6 +58,9 @@ class PDI_EXPORT Global_context: public Context
/// Global logger of PDI, should be constructed first, destroyed last
Logger m_logger;

/// Global timer of PDI
Timer m_timer;

/// Datatype_template constructors available in PDI
std::unordered_map<std::string, Datatype_template_parser> m_datatype_parsers;

Expand Down Expand Up @@ -119,6 +123,8 @@ class PDI_EXPORT Global_context: public Context

Logger& logger() override;

Timer& timer() override;

Datatype_template_sptr datatype(PC_tree_t node) override;

void add_datatype(const std::string&, Datatype_template_parser) override;
Expand Down
4 changes: 4 additions & 0 deletions pdi/src/pdi.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "pdi/paraconf_wrapper.h"
#include "pdi/plugin.h"
#include "pdi/ref_any.h"
#include "pdi/timer.h"

#include "global_context.h"

Expand Down Expand Up @@ -170,6 +171,7 @@ try {
g_transaction.clear();
g_transaction_data.clear();
Global_context::init(conf);
Global_context::context().timer().startTimer("PDI");
return PDI_OK;
} catch (const Error& e) {
return g_error_context.return_err(e);
Expand All @@ -184,6 +186,8 @@ try {
Paraconf_wrapper fw;
g_transaction.clear();
g_transaction_data.clear();
Global_context::context().timer().stopTimer("PDI");
Global_context::context().timer().printReport();
Global_context::finalize();
return PDI_OK;
} catch (const Error& e) {
Expand Down
Loading
Loading