Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/mpi wtime profiler #317

Merged
merged 38 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e449311
always use clock_gettime
balos1 Aug 8, 2023
dbbf8c1
enable profiling and logging in windows github actions
balos1 Aug 8, 2023
7cd4a7c
fix subtraction of times
balos1 Aug 8, 2023
b459ddf
add windows implementation of gettime
balos1 Aug 8, 2023
b51603f
remove cygwin part
balos1 Aug 8, 2023
6964531
fix datatype for ticks
balos1 Aug 11, 2023
6a21559
remove error for no posix
balos1 Aug 11, 2023
cf468c3
declare a timespec if there is not one
balos1 Aug 11, 2023
68100ad
use LARGE_INTEGER
balos1 Aug 11, 2023
5626cf5
add missing windows system includes
balos1 Aug 11, 2023
b8b02b3
update changelog
balos1 Aug 11, 2023
a20e575
need windows.h
balos1 Sep 5, 2023
2d65535
ticks in microseconds
balos1 Sep 5, 2023
1a1c4a7
add profiling test
balos1 Sep 5, 2023
884541f
enable unit tests in Windows short test
balos1 Sep 5, 2023
21c3da4
remove commented out code
balos1 Oct 27, 2023
90717c9
add unit tests of profiler to tarscript
balos1 Oct 27, 2023
ec30aea
organize src targets for windows
balos1 Oct 27, 2023
21006fe
add get functions
balos1 Oct 27, 2023
b61c7cb
only test profiling if enabled
balos1 Oct 27, 2023
3c60571
fix windows includes and resolution
balos1 Oct 27, 2023
a8b0a4d
add new functions to docs
balos1 Oct 27, 2023
9c163a3
Merge branch 'develop' into bugfix/mpi-wtime-profiler
gardner48 Oct 27, 2023
b5d33ba
Merge branch 'develop' into bugfix/mpi-wtime-profiler
gardner48 Oct 29, 2023
ec66531
Apply suggestions from code review
balos1 Oct 30, 2023
69b7a21
simplify ifdef checks
balos1 Oct 30, 2023
99c338b
move C++ profiler parts to their own header file
balos1 Oct 30, 2023
5bfc365
add doc notes
balos1 Oct 30, 2023
41ebdd4
a few minor fixes
balos1 Oct 30, 2023
6713aea
include string header for stod/stoi
balos1 Oct 30, 2023
caeda65
Enable unit tests to build on Windows when access to private function…
balos1 Oct 30, 2023
7aa0e52
use integer 1e9
balos1 Oct 30, 2023
9d6de5b
workaround for cmake 3.12
balos1 Oct 30, 2023
be907b3
typo
balos1 Oct 30, 2023
0a53d76
add slack for timing test
balos1 Oct 30, 2023
55fd98d
update tolerance
balos1 Nov 1, 2023
2bc100c
turn off unit tests on mingw
balos1 Nov 1, 2023
fe77dc9
loosen test tolerance
balos1 Nov 1, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/windows-latest-mingw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -G "MinGW Makefiles" -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
run: cmake -G "MinGW Makefiles" -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DSUNDIALS_BUILD_WITH_PROFILING=ON -DSUNDIALS_LOGGING_LEVEL=2 -DSUNDIALS_TEST_UNITTESTS=ON -DEXAMPLES_ENABLE_CXX=ON

- name: Build
# Build your program with the given configuration
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_STATIC_LIBS=OFF
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_STATIC_LIBS=OFF -DSUNDIALS_BUILD_WITH_PROFILING=ON -DSUNDIALS_LOGGING_LEVEL=2 -DSUNDIALS_TEST_UNITTESTS=ON -DEXAMPLES_ENABLE_CXX=ON

- name: Build
# Build your program with the given configuration
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Fixed scaling bug in `SUNMatScaleAddI_Sparse` for non-square matrices.
Fixed missing soversions in some `SUNLinearSolver` and `SUNNonlinearSolver`
CMake targets.

Added Fortran support for the LAPACK dense `SUNLinearSolver` implementations.
Added Fortran support for the LAPACK dense `SUNLinearSolver` implementation.

Fixed the build system support for MAGMA when using a NVIDIA HPC SDK installation of CUDA
and fixed the targets used for rocBLAS and rocSPARSE.
Expand All @@ -38,6 +38,8 @@ ERK method `ARKODE_SOFRONIOU_SPALETTA_5_3_4`, the sixth order ERK method
the eighth order ERK method `ARKODE_VERNER_13_7_8`, and the ninth order ERK
method `ARKODE_VERNER_16_8_9`.

Changed the `SUNProfiler` so that it does not rely on `MPI_WTime` in any case.
This fixes https://github.com/LLNL/sundials/issues/312.

## Changes to SUNDIALS in release 6.6.1

Expand Down
7 changes: 0 additions & 7 deletions cmake/SundialsSetupCompilers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,6 @@ if(SUNDIALS_POSIX_TIMERS AND POSIX_TIMERS_NEED_POSIX_C_SOURCE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_POSIX_C_SOURCE=${SUNDIALS_POSIX_C_SOURCE}")
endif()

# Check if profiling is being built with no timers.
if(SUNDIALS_BUILD_WITH_PROFILING AND
(NOT ENABLE_CALIPER) AND
(NOT ENABLE_MPI) AND
(NOT SUNDIALS_POSIX_TIMERS))
message(SEND_ERROR "The SUNDIALS native profiler requires POSIX timers or MPI_Wtime, but neither were found.")
endif()
balos1 marked this conversation as resolved.
Show resolved Hide resolved

# ---------------------------------------------------------------
# Check for deprecated attribute with message
Expand Down
4 changes: 4 additions & 0 deletions cmake/macros/SundialsAddLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ macro(sundials_add_library target)
# create the target for the object library
add_library(${obj_target} OBJECT ${sources})

set_target_properties(${obj_target} PROPERTIES FOLDER "obj")

# add all object libraries to object library
if(sundials_add_library_OBJECT_LIBRARIES)
target_link_libraries(${obj_target}
Expand Down Expand Up @@ -229,6 +231,8 @@ macro(sundials_add_library target)

add_library(${_actual_target_name} ${_libtype} $<TARGET_OBJECTS:${obj_target}>)

set_target_properties(${_actual_target_name} PROPERTIES FOLDER "src")

# add any object library dependencies
if(sundials_add_library_OBJECT_LIBRARIES)
if(${_libtype} MATCHES "STATIC")
Expand Down
4 changes: 3 additions & 1 deletion doc/arkode/guide/source/Introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ ERK method ``ARKODE_SOFRONIOU_SPALETTA_5_3_4``, the sixth order ERK method
the eighth order ERK method ``ARKODE_VERNER_13_7_8``, and the ninth order ERK
method ``ARKODE_VERNER_16_8_9``.

Changed the ``SUNProfiler`` so that it does not rely on ``MPI_WTime`` in any case.
This fixes `GitHub Issue #312 <https://github.com/LLNL/sundials/issues/312>`_.

Added Fortran support for the LAPACK dense ``SUNLinearSolver`` implementation.

Changes in v5.6.1
Expand Down Expand Up @@ -993,7 +996,6 @@ utilize a zero initial guess.
A bug was fixed in the ARKODE stepper modules where the stop time may be passed
after resetting the integrator.


Changes in v4.7.0
-----------------

Expand Down
3 changes: 3 additions & 0 deletions doc/cvode/guide/source/Introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ Fixed scaling bug in ``SUNMatScaleAddI_Sparse`` for non-square matrices.
Fixed missing soversions in some ``SUNLinearSolver`` and ``SUNNonlinearSolver``
CMake targets.

Changed the ``SUNProfiler`` so that it does not rely on ``MPI_WTime`` in any case.
This fixes `GitHub Issue #312 <https://github.com/LLNL/sundials/issues/312>`_.

Added Fortran support for the LAPACK dense ``SUNLinearSolver`` implementation.

Changes in v6.6.1
Expand Down
3 changes: 3 additions & 0 deletions doc/cvodes/guide/source/Introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ Fixed scaling bug in ``SUNMatScaleAddI_Sparse`` for non-square matrices.
Fixed missing soversions in some ``SUNLinearSolver`` and ``SUNNonlinearSolver``
CMake targets.

Changed the ``SUNProfiler`` so that it does not rely on ``MPI_WTime`` in any case.
This fixes `GitHub Issue #312 <https://github.com/LLNL/sundials/issues/312>`_.

Added Fortran support for the LAPACK dense ``SUNLinearSolver`` implementation.

Changes in v6.6.1
Expand Down
3 changes: 3 additions & 0 deletions doc/ida/guide/source/Introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ Fixed scaling bug in ``SUNMatScaleAddI_Sparse`` for non-square matrices.
Fixed missing soversions in some ``SUNLinearSolver`` and ``SUNNonlinearSolver``
CMake targets.

Changed the ``SUNProfiler`` so that it does not rely on ``MPI_WTime`` in any case.
This fixes `GitHub Issue #312 <https://github.com/LLNL/sundials/issues/312>`_.

Added Fortran support for the LAPACK dense ``SUNLinearSolver`` implementation.

Changes in v6.6.1
Expand Down
3 changes: 3 additions & 0 deletions doc/idas/guide/source/Introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ Fixed scaling bug in ``SUNMatScaleAddI_Sparse`` for non-square matrices.
Fixed missing soversions in some ``SUNLinearSolver`` and ``SUNNonlinearSolver``
CMake targets.

Changed the ``SUNProfiler`` so that it does not rely on ``MPI_WTime`` in any case.
This fixes `GitHub Issue #312 <https://github.com/LLNL/sundials/issues/312>`_.

Added Fortran support for the LAPACK dense ``SUNLinearSolver`` implementation.

Changes in v5.6.1
Expand Down
3 changes: 3 additions & 0 deletions doc/kinsol/guide/source/Introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ Updated the Tpetra NVector interface to support Trilinos 14.
Fixed a memory leak when destroying a CUDA, HIP, SYCL, or system SUNMemoryHelper
object.

Changed the ``SUNProfiler`` so that it does not rely on ``MPI_WTime`` in any case.
This fixes `GitHub Issue #312 <https://github.com/LLNL/sundials/issues/312>`_.

Changes in v6.6.0
-----------------

Expand Down
1 change: 1 addition & 0 deletions doc/shared/Install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,7 @@ illustration only.
.. cmakeoption:: SUNDIALS_BUILD_WITH_PROFILING

Build SUNDIALS with capabilties for fine-grained profiling.
This requires POSIX timers or the Windows ``profileapi.h`` timers.

Default: OFF

Expand Down
30 changes: 30 additions & 0 deletions doc/shared/sundials/Profiling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ If Caliper is enabled, then users should refer to the `Caliper documentation <ht
for information on getting profiler output. In most cases, this involves
setting the ``CALI_CONFIG`` environment variable.


.. note::

The SUNDIALS profilers requires POSIX timers or the Windows ``profileapi.h`` timers.
balos1 marked this conversation as resolved.
Show resolved Hide resolved

.. warning::

While the SUNDIALS profiling scheme is relatively lightweight, enabling
Expand Down Expand Up @@ -149,6 +154,31 @@ are available.
* Returns zero if successful, or non-zero if an error occurred


.. c:function:: int SUNProfiler_GetElapsedTime(SUNProfiler p, const char* name, double* time)

Get the elapsed time for the timer "name" in seconds.

**Arguments:**
* ``p`` -- a ``SUNProfiler`` object
* ``name`` -- the name for the profiling region of interest
* ``time`` -- upon return, the elapsed time for the timer

**Returns:**
* Returns zero if successful, or non-zero if an error occurred


.. c:function:: int SUNProfiler_GetTimerResolution(SUNProfiler p, double* resolution)

Get the timer resolution in seconds.

**Arguments:**
* ``p`` -- a ``SUNProfiler`` object
* ``resolution`` -- upon return, the resolution for the timer

**Returns:**
* Returns zero if successful, or non-zero if an error occurred


.. c:function:: int SUNProfiler_Print(SUNProfiler p, FILE* fp)

Prints out a profiling summary. When constructed with an MPI comm the summary
Expand Down
57 changes: 19 additions & 38 deletions include/sundials/sundials_profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,21 @@
#include "caliper/cali.h"
#endif

#ifdef __cplusplus /* wrapper to enable C++ usage */
#ifdef __cplusplus /* wrapper to enable C++ usage */
extern "C" {
#endif

typedef struct _SUNProfiler *SUNProfiler;
typedef struct _SUNProfiler* SUNProfiler;

SUNDIALS_EXPORT int SUNProfiler_Create(void* comm, const char* title, SUNProfiler* p);
SUNDIALS_EXPORT int SUNProfiler_Create(void* comm, const char* title,
SUNProfiler* p);
SUNDIALS_EXPORT int SUNProfiler_Free(SUNProfiler* p);
SUNDIALS_EXPORT int SUNProfiler_Begin(SUNProfiler p, const char* name);
SUNDIALS_EXPORT int SUNProfiler_End(SUNProfiler p, const char* name);
SUNDIALS_EXPORT int SUNProfiler_GetTimerResolution(SUNProfiler p,
double* resolution);
SUNDIALS_EXPORT int SUNProfiler_GetElapsedTime(SUNProfiler p, const char* name,
double* time);
SUNDIALS_EXPORT int SUNProfiler_Print(SUNProfiler p, FILE* fp);
SUNDIALS_EXPORT int SUNProfiler_Reset(SUNProfiler p);

Expand All @@ -42,35 +47,29 @@ SUNDIALS_EXPORT int SUNProfiler_Reset(SUNProfiler p);

#define SUNDIALS_MARK_FUNCTION_END(profobj) CALI_MARK_FUNCTION_END

#define SUNDIALS_WRAP_STATEMENT(profobj, name, stmt) CALI_WRAP_STATEMENT(name, stmt)
#define SUNDIALS_WRAP_STATEMENT(profobj, name, stmt) \
CALI_WRAP_STATEMENT(name, stmt)

#define SUNDIALS_MARK_BEGIN(profobj, name) CALI_MARK_BEGIN(name)

#define SUNDIALS_MARK_END(profobj, name) CALI_MARK_END(name)

#ifdef __cplusplus
#define SUNDIALS_CXX_MARK_FUNCTION(projobj) CALI_CXX_MARK_FUNCTION
#endif

#elif defined(SUNDIALS_BUILD_WITH_PROFILING)

#define SUNDIALS_MARK_FUNCTION_BEGIN(profobj) SUNProfiler_Begin(profobj, __func__)
#define SUNDIALS_MARK_FUNCTION_BEGIN(profobj) \
SUNProfiler_Begin(profobj, __func__)

#define SUNDIALS_MARK_FUNCTION_END(profobj) SUNProfiler_End(profobj, __func__)

#define SUNDIALS_WRAP_STATEMENT(profobj, name, stmt) \
SUNProfiler_Begin(profobj, (name)); \
stmt; \
SUNProfiler_End(profobj, (name));
SUNProfiler_Begin(profobj, (name)); \
stmt; \
SUNProfiler_End(profobj, (name));

#define SUNDIALS_MARK_BEGIN(profobj, name) SUNProfiler_Begin(profobj, (name))

#define SUNDIALS_MARK_END(profobj, name) SUNProfiler_End(profobj, (name))

#ifdef __cplusplus
#define SUNDIALS_CXX_MARK_FUNCTION(profobj) sundials::ProfilerMarkScope __ProfilerMarkScope(profobj, __func__)
#endif

#else

#define SUNDIALS_MARK_FUNCTION_BEGIN(profobj)
Expand All @@ -92,27 +91,9 @@ SUNDIALS_EXPORT int SUNProfiler_Reset(SUNProfiler p);
#ifdef __cplusplus
}

namespace sundials
balos1 marked this conversation as resolved.
Show resolved Hide resolved
{
/* Convenience class for C++ codes.
Allows for simpler profiler statements using C++ scoping rules. */
class ProfilerMarkScope
{
public:
ProfilerMarkScope(SUNProfiler prof, const char* name) {
prof_ = prof;
name_ = name;
SUNProfiler_Begin(prof_, name_);
}

~ProfilerMarkScope() {
SUNProfiler_End(prof_, name_);
}
private:
SUNProfiler prof_;
const char* name_;
};
}
/* We include this here for backwards compatibility
(the contents used to be defined here directly) */
#include <sundials/sundials_profiler.hpp>

#endif
#endif /* SUNDIALS_PROFILER_H_ */
#endif /* SUNDIALS_PROFILER_H */
52 changes: 52 additions & 0 deletions include/sundials/sundials_profiler.hpp
balos1 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* -----------------------------------------------------------------
* Programmer: Cody J. Balos @ LLNL
* -----------------------------------------------------------------
* SUNDIALS Copyright Start
* Copyright (c) 2002-2023, Lawrence Livermore National Security
* and Southern Methodist University.
* All rights reserved.
*
* See the top-level LICENSE and NOTICE files for details.
*
* SPDX-License-Identifier: BSD-3-Clause
* SUNDIALS Copyright End
* -----------------------------------------------------------------*/

#ifndef _SUNDIALS_PROFILER_HPP
#define _SUNDIALS_PROFILER_HPP

#include <cstring>
#include <sundials/sundials_config.h>
#include <sundials/sundials_profiler.h>

#if defined(SUNDIALS_BUILD_WITH_PROFILING) && defined(SUNDIALS_CALIPER_ENABLED)
#define SUNDIALS_CXX_MARK_FUNCTION(projobj) CALI_CXX_MARK_FUNCTION
#elif defined(SUNDIALS_BUILD_WITH_PROFILING)
#define SUNDIALS_CXX_MARK_FUNCTION(profobj) \
sundials::ProfilerMarkScope __ProfilerMarkScope(profobj, __func__)
#else
#define SUNDIALS_CXX_MARK_FUNCTION(profobj)
#endif

namespace sundials {
/* Convenience class for C++ codes.
Allows for simpler profiler statements using C++ scoping rules. */
class ProfilerMarkScope
{
public:
ProfilerMarkScope(SUNProfiler prof, const char* name)
{
prof_ = prof;
name_ = name;
SUNProfiler_Begin(prof_, name_);
}

~ProfilerMarkScope() { SUNProfiler_End(prof_, name_); }

private:
SUNProfiler prof_;
const char* name_;
};
} // namespace sundials

#endif /* SUNDIALS_PROFILER_HPP */
2 changes: 2 additions & 0 deletions scripts/shared
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ $tar $tarfile $distrobase/include/sundials/sundials_nonlinearsolver.hpp
$tar $tarfile $distrobase/include/sundials/sundials_nvector_senswrapper.h
$tar $tarfile $distrobase/include/sundials/sundials_nvector.h
$tar $tarfile $distrobase/include/sundials/sundials_profiler.h
$tar $tarfile $distrobase/include/sundials/sundials_profiler.hpp
$tar $tarfile $distrobase/include/sundials/sundials_sycl_policies.hpp
$tar $tarfile $distrobase/include/sundials/sundials_types.h
$tar $tarfile $distrobase/include/sundials/sundials_version.h
Expand Down Expand Up @@ -842,3 +843,4 @@ echo " --- Add unit tests files to $tarfile"
$tar $tarfile $distrobase/test/unit_tests/CMakeLists.txt
$tar $tarfile $distrobase/test/unit_tests/reductions
$tar $tarfile $distrobase/test/unit_tests/sunmemory
$tar $tarfile $distrobase/test/unit_tests/profiling
Loading
Loading