Skip to content

Commit

Permalink
Merge pull request #97 from streeve/timers
Browse files Browse the repository at this point in the history
Separate timers for more detailed information
  • Loading branch information
streeve authored May 29, 2024
2 parents 7251ff6 + 8e3233a commit 2bb8c9d
Show file tree
Hide file tree
Showing 12 changed files with 387 additions and 147 deletions.
9 changes: 9 additions & 0 deletions src/CabanaPD_BodyTerm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include <Cabana_Core.hpp>

#include <CabanaPD_Timer.hpp>

namespace CabanaPD
{

Expand All @@ -24,6 +26,8 @@ struct BodyTerm
{
UserFunctor _user_functor;

Timer _timer;

BodyTerm( UserFunctor user )
: _user_functor( user )
{
Expand All @@ -34,12 +38,17 @@ struct BodyTerm
template <class ExecSpace, class ParticleType>
void apply( ExecSpace, ParticleType& particles, const double time )
{
_timer.start();
Kokkos::RangePolicy<ExecSpace> policy( 0, particles.n_local );
auto user = _user_functor;
Kokkos::parallel_for(
"CabanaPD::BodyTerm::apply", policy,
KOKKOS_LAMBDA( const int p ) { user( p, time ); } );
_timer.stop();
}

auto time() { return _timer.time(); };
auto timeInit() { return 0.0; };
};

template <class UserFunctor>
Expand Down
38 changes: 38 additions & 0 deletions src/CabanaPD_Boundary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include <Cabana_Core.hpp>

#include <CabanaPD_Timer.hpp>

namespace CabanaPD
{

Expand Down Expand Up @@ -51,6 +53,8 @@ struct BoundaryIndexSpace<MemorySpace, RegionBoundary>
index_view_type _view;
index_view_type _count;

Timer _timer;

// Default for empty case.
BoundaryIndexSpace() {}

Expand All @@ -59,6 +63,8 @@ struct BoundaryIndexSpace<MemorySpace, RegionBoundary>
std::vector<RegionBoundary> planes,
const double initial_guess )
{
_timer.start();

_view = index_view_type( "boundary_indices",
particles.n_local * initial_guess );
_count = index_view_type( "count", 1 );
Expand All @@ -74,6 +80,8 @@ struct BoundaryIndexSpace<MemorySpace, RegionBoundary>
{
Kokkos::resize( _view, count_host( 0 ) );
}

_timer.stop();
}

template <class ExecSpace, class Particles>
Expand Down Expand Up @@ -112,6 +120,8 @@ struct BoundaryIndexSpace<MemorySpace, RegionBoundary>
index_functor );
}
}

auto time() { return _timer.time(); };
};

template <class BoundaryType, class ExecSpace, class Particles>
Expand Down Expand Up @@ -141,6 +151,8 @@ struct BoundaryCondition
BCIndexSpace _index_space;
UserFunctor _user_functor;

Timer _timer;

BoundaryCondition( BCIndexSpace bc_index_space, UserFunctor user )
: _index_space( bc_index_space )
, _user_functor( user )
Expand All @@ -157,6 +169,7 @@ struct BoundaryCondition
template <class ExecSpace, class ParticleType>
void apply( ExecSpace, ParticleType& )
{
_timer.start();
auto user = _user_functor;
auto index_space = _index_space._view;
Kokkos::RangePolicy<ExecSpace> policy( 0, index_space.size() );
Expand All @@ -165,12 +178,18 @@ struct BoundaryCondition
auto pid = index_space( b );
user( pid );
} );
_timer.stop();
}

auto time() { return _timer.time(); };
auto timeInit() { return _index_space.time(); };
};

template <class BCIndexSpace>
struct BoundaryCondition<BCIndexSpace, ZeroBCTag>
{
Timer _timer;

template <class ExecSpace, class Particles>
void update( ExecSpace, Particles, RegionBoundary )
{
Expand All @@ -180,6 +199,9 @@ struct BoundaryCondition<BCIndexSpace, ZeroBCTag>
void apply( ExecSpace, ParticleType )
{
}

auto time() { return _timer.time(); };
auto timeInit() { return 0.0; };
};

template <class BCIndexSpace>
Expand All @@ -188,6 +210,8 @@ struct BoundaryCondition<BCIndexSpace, ForceValueBCTag>
double _value;
BCIndexSpace _index_space;

Timer _timer;

BoundaryCondition( const double value, BCIndexSpace bc_index_space )
: _value( value )
, _index_space( bc_index_space )
Expand All @@ -204,6 +228,7 @@ struct BoundaryCondition<BCIndexSpace, ForceValueBCTag>
template <class ExecSpace, class ParticleType>
void apply( ExecSpace, ParticleType& particles )
{
_timer.start();
auto f = particles.sliceForce();
auto index_space = _index_space._view;
Kokkos::RangePolicy<ExecSpace> policy( 0, index_space.size() );
Expand All @@ -214,7 +239,11 @@ struct BoundaryCondition<BCIndexSpace, ForceValueBCTag>
for ( int d = 0; d < 3; d++ )
f( pid, d ) = value;
} );
_timer.stop();
}

auto time() { return _timer.time(); };
auto timeInit() { return _index_space.time(); };
};

template <class BCIndexSpace>
Expand All @@ -223,6 +252,8 @@ struct BoundaryCondition<BCIndexSpace, ForceUpdateBCTag>
double _value;
BCIndexSpace _index_space;

Timer _timer;

BoundaryCondition( const double value, BCIndexSpace bc_index_space )
: _value( value )
, _index_space( bc_index_space )
Expand All @@ -239,6 +270,8 @@ struct BoundaryCondition<BCIndexSpace, ForceUpdateBCTag>
template <class ExecSpace, class ParticleType>
void apply( ExecSpace, ParticleType& particles )
{
_timer.start();

auto f = particles.sliceForce();
auto index_space = _index_space._view;
Kokkos::RangePolicy<ExecSpace> policy( 0, index_space.size() );
Expand All @@ -249,7 +282,12 @@ struct BoundaryCondition<BCIndexSpace, ForceUpdateBCTag>
for ( int d = 0; d < 3; d++ )
f( pid, d ) += value;
} );

_timer.stop();
}

auto time() { return _timer.time(); };
auto timeInit() { return _index_space.time(); };
};

// FIXME: relatively large initial guess for allocation.
Expand Down
39 changes: 36 additions & 3 deletions src/CabanaPD_Comm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <Cabana_Grid.hpp>

#include <CabanaPD_Timer.hpp>
#include <CabanaPD_Types.hpp>

namespace CabanaPD
Expand Down Expand Up @@ -251,6 +252,7 @@ class Comm<ParticleType, PMB>
Comm( ParticleType& particles, int max_export_guess = 100 )
: max_export( max_export_guess )
{
_init_timer.start();
auto local_grid = particles.local_grid;
MPI_Comm_size( local_grid->globalGrid().comm(), &mpi_size );
MPI_Comm_rank( local_grid->globalGrid().comm(), &mpi_rank );
Expand Down Expand Up @@ -281,6 +283,8 @@ class Comm<ParticleType, PMB>

gather_u = std::make_shared<gather_u_type>( *halo, particles._aosoa_u );
gather_u->apply();

_init_timer.stop();
}
~Comm() {}

Expand All @@ -297,10 +301,22 @@ class Comm<ParticleType, PMB>

// We assume here that the particle count has not changed and no resize
// is necessary.
void gatherDisplacement() { gather_u->apply(); }
void gatherDisplacement()
{
_timer.start();
gather_u->apply();
_timer.stop();
}
// No-op to make solvers simpler.
void gatherDilatation() {}
void gatherWeightedVolume() {}

auto timeInit() { return _init_timer.time(); };
auto time() { return _timer.time(); };

protected:
Timer _init_timer;
Timer _timer;
};

template <class ParticleType>
Expand All @@ -313,6 +329,9 @@ class Comm<ParticleType, LPS> : public Comm<ParticleType, PMB>
using base_type::gather_u;
using base_type::halo;

using base_type::_init_timer;
using base_type::_timer;

using gather_m_type =
Cabana::Gather<halo_type, typename ParticleType::aosoa_m_type>;
using gather_theta_type =
Expand All @@ -323,14 +342,28 @@ class Comm<ParticleType, LPS> : public Comm<ParticleType, PMB>
Comm( ParticleType& particles, int max_export_guess = 100 )
: base_type( particles, max_export_guess )
{
_init_timer.start();

gather_m = std::make_shared<gather_m_type>( *halo, particles._aosoa_m );
gather_theta = std::make_shared<gather_theta_type>(
*halo, particles._aosoa_theta );

_init_timer.stop();
}
~Comm() {}

void gatherDilatation() { gather_theta->apply(); }
void gatherWeightedVolume() { gather_m->apply(); }
void gatherDilatation()
{
_timer.start();
gather_theta->apply();
_timer.stop();
}
void gatherWeightedVolume()
{
_timer.start();
gather_m->apply();
_timer.stop();
}
};

} // namespace CabanaPD
Expand Down
8 changes: 4 additions & 4 deletions src/CabanaPD_Force.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class Force;
******************************************************************************/
template <class ForceType, class ParticleType, class NeighListType,
class ParallelType>
void computeForce( const ForceType& force, ParticleType& particles,
void computeForce( ForceType& force, ParticleType& particles,
const NeighListType& neigh_list,
const ParallelType& neigh_op_tag )
{
Expand Down Expand Up @@ -163,7 +163,7 @@ void computeForce( const ForceType& force, ParticleType& particles,

template <class ForceType, class ParticleType, class NeighListType,
class ParallelType>
double computeEnergy( const ForceType force, ParticleType& particles,
double computeEnergy( ForceType& force, ParticleType& particles,
const NeighListType& neigh_list,
const ParallelType& neigh_op_tag )
{
Expand Down Expand Up @@ -192,7 +192,7 @@ double computeEnergy( const ForceType force, ParticleType& particles,
// Forces with bond breaking.
template <class ForceType, class ParticleType, class NeighListType,
class NeighborView, class ParallelType>
void computeForce( const ForceType& force, ParticleType& particles,
void computeForce( ForceType& force, ParticleType& particles,
const NeighListType& neigh_list, NeighborView& mu,
const ParallelType& neigh_op_tag )
{
Expand Down Expand Up @@ -223,7 +223,7 @@ void computeForce( const ForceType& force, ParticleType& particles,
// Energy and damage.
template <class ForceType, class ParticleType, class NeighListType,
class NeighborView, class ParallelType>
double computeEnergy( const ForceType force, ParticleType& particles,
double computeEnergy( ForceType& force, ParticleType& particles,
const NeighListType& neigh_list, NeighborView& mu,
const ParallelType& neigh_op_tag )
{
Expand Down
13 changes: 13 additions & 0 deletions src/CabanaPD_Integrate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include <Kokkos_Core.hpp>

#include <CabanaPD_Particles.hpp>
#include <CabanaPD_Timer.hpp>

namespace CabanaPD
{
Expand All @@ -72,6 +73,7 @@ class Integrator
using exec_space = ExecutionSpace;

double _dt, _half_dt;
Timer _timer;

public:
Integrator( double dt )
Expand All @@ -85,6 +87,8 @@ class Integrator
template <class ParticlesType>
void initialHalfStep( ParticlesType& p )
{
_timer.start();

auto u = p.sliceDisplacement();
auto v = p.sliceVelocity();
auto f = p.sliceForce();
Expand All @@ -105,11 +109,15 @@ class Integrator
Kokkos::RangePolicy<exec_space> policy( 0, v.size() );
Kokkos::parallel_for( "CabanaPD::Integrator::Initial", policy,
init_func );

_timer.stop();
}

template <class ParticlesType>
void finalHalfStep( ParticlesType& p )
{
_timer.start();

auto v = p.sliceVelocity();
auto f = p.sliceForce();
auto rho = p.sliceDensity();
Expand All @@ -125,7 +133,12 @@ class Integrator
Kokkos::RangePolicy<exec_space> policy( 0, v.size() );
Kokkos::parallel_for( "CabanaPD::Integrator::Final", policy,
final_func );

_timer.stop();
}

double timeInit() { return 0.0; };
auto time() { return _timer.time(); };
};

} // namespace CabanaPD
Expand Down
Loading

0 comments on commit 2bb8c9d

Please sign in to comment.