Skip to content

Commit

Permalink
Use PerfGraph for profiling (idaholab#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed Sep 7, 2018
1 parent b891718 commit 0e5f621
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
5 changes: 5 additions & 0 deletions include/userobjects/MyTRIMDiracRun.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class MyTRIMDiracRun : public MyTRIMRunBase

/// data such as interstitials and vacancies produced will be stored here
MyTRIMResultList _result_list;

///@{ timers
PerfID _perf_trim;
PerfID _perf_finalize;
///@}
};

#endif // MYTRIMDIRACRUN_H
5 changes: 5 additions & 0 deletions include/userobjects/MyTRIMElementRun.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class MyTRIMElementRun : public MyTRIMRunBase
/// data such as interstitials and vacancies produced will be stored here
MyTRIMResultMap _result_map;

///@{ timers
PerfID _perf_trim;
PerfID _perf_finalize;
///@}

private:
/// zero result to return for elements that have not been touched by the cascades
MyTRIMResult _zero;
Expand Down
3 changes: 3 additions & 0 deletions include/userobjects/MyTRIMRasterizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ class MyTRIMRasterizer : public ElementUserObject

private:
bool _execute_this_timestep;

/// timers
PerfID _perf_finalize;
};

#endif // MYTRIMRASTERIZER_H
17 changes: 13 additions & 4 deletions src/userobjects/MyTRIMDiracRun.C
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ validParams<MyTRIMDiracRun>()
return params;
}

MyTRIMDiracRun::MyTRIMDiracRun(const InputParameters & parameters) : MyTRIMRunBase(parameters)
MyTRIMDiracRun::MyTRIMDiracRun(const InputParameters & parameters)
: MyTRIMRunBase(parameters),
_perf_trim(registerTimedSection("trim", 2)),
_perf_finalize(registerTimedSection("finalize", 2))
{
if (_trim_parameters.desired_npka != 0)
mooseError("Result scaling not supported in MyTRIMDiracRun");
Expand All @@ -52,9 +55,10 @@ MyTRIMDiracRun::execute()
_console << "\nMyTRIM: Running " << _trim_parameters.original_npka << " recoils." << std::endl;

// run threads
Moose::perf_log.push("MyTRIMRecoilLoop", "Solve");
Threads::parallel_reduce(PKARange(_pka_list.begin(), _pka_list.end()), rl);
Moose::perf_log.pop("MyTRIMRecoilLoop", "Solve");
{
TIME_SECTION(_perf_trim);
Threads::parallel_reduce(PKARange(_pka_list.begin(), _pka_list.end()), rl);
}

// fetch the joined data from thread 0
_result_list = rl.getResultList();
Expand All @@ -63,6 +67,11 @@ MyTRIMDiracRun::execute()
void
MyTRIMDiracRun::finalize()
{
TIME_SECTION(_perf_finalize);

if (!_rasterizer.executeThisTimestep())
return;

// for single processor runs we do not need to do anything here
if (_app.n_processors() == 1)
return;
Expand Down
15 changes: 10 additions & 5 deletions src/userobjects/MyTRIMElementRun.C
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ validParams<MyTRIMElementRun>()
}

MyTRIMElementRun::MyTRIMElementRun(const InputParameters & parameters)
: MyTRIMRunBase(parameters), _zero(_nvars)
: MyTRIMRunBase(parameters),
_perf_trim(registerTimedSection("trim", 2)),
_perf_finalize(registerTimedSection("finalize", 2)),
_zero(_nvars)
{
}

Expand All @@ -55,10 +58,10 @@ MyTRIMElementRun::execute()
<< "Result scaling factor: " << _trim_parameters.result_scaling_factor << std::endl;

// run threads
Moose::perf_log.push("MyTRIMRecoilLoop", "Solve");
Threads::parallel_reduce(PKARange(_pka_list.begin(), _pka_list.end()), rl);

Moose::perf_log.pop("MyTRIMRecoilLoop", "Solve");
{
TIME_SECTION(_perf_trim);
Threads::parallel_reduce(PKARange(_pka_list.begin(), _pka_list.end()), rl);
}

// fetch the joined data from thread 0
_result_map = rl.getResultMap();
Expand All @@ -67,6 +70,8 @@ MyTRIMElementRun::execute()
void
MyTRIMElementRun::finalize()
{
TIME_SECTION(_perf_finalize);

if (!_rasterizer.executeThisTimestep())
return;

Expand Down
5 changes: 4 additions & 1 deletion src/userobjects/MyTRIMRasterizer.C
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ MyTRIMRasterizer::MyTRIMRasterizer(const InputParameters & parameters)
_periodic(isCoupled("periodic_var") ? coupled("periodic_var", 0) : coupled("var", 0)),
_accumulated_time(0.0),
_accumulated_time_old(0.0),
_interval(getParam<unsigned int>("interval"))
_interval(getParam<unsigned int>("interval")),
_perf_finalize(registerTimedSection("finalize", 2))
{
if (_nvars == 0)
mooseError("Must couple variables to MyTRIMRasterizer.");
Expand Down Expand Up @@ -370,6 +371,8 @@ MyTRIMRasterizer::threadJoin(const UserObject & y)
void
MyTRIMRasterizer::finalize()
{
TIME_SECTION(_perf_finalize);

// save the accumulated time so that we can properly roll back if the step does not converge
_accumulated_time_old = _accumulated_time;

Expand Down

0 comments on commit 0e5f621

Please sign in to comment.