Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
Reductions

Arcane allows performing the three classic types of reduction (Min, Max, and Sum) on the accelerator. There are two ways to perform reductions:

Reductions via a loop

The classes ReducerMax2, ReducerMin2, and ReducerSum2 allow performing reductions on accelerators. They are used inside loops such as RUNCOMMAND_LOOP1() or RUNCOMMAND_ENUMERATE() or RUNCOMMAND_MAT_ENUMERATE().

First, you must declare an instance of one of the reduction classes and then pass it as an additional parameter to the loops. For example:

#include "arcane/accelerator/Reduce.h"
{
auto command = makeCommand(queue);
Arcane::Accelerator::ReducerMin2<double> minimum_reducer(command);
Arcane::VariableCellReal my_variable = ...;
auto in_my_variable = viewIn(command,my_variable);
command << RUNCOMMAND_ENUMERATE(Cell,cid,allCells(),minimum_reducer)
{
minimum_reducer.combine(in_my_variable[cid]);
};
info() << "MinValue=" << minimum_reducer.reducedValue();
}
Types and macros to manage enumerations of entities on accelerators.
#define RUNCOMMAND_ENUMERATE(ItemTypeName, iter_name, item_group,...)
Macro to iterate over an accelerator on a group of entities.
MeshVariableScalarRefT< Cell, Real > VariableCellReal
Real type quantity at cell center.
Warning
Each instance can only be used once.

It is possible to use multiple reduction instances if you want to perform several reductions at once. For example:

#include "arcane/accelerator/Reduce.h"
{
auto command = makeCommand(queue);
Arcane::Accelerator::ReducerMin2<double> minimum_reducer(command);
Arcane::Accelerator::ReducerMax2<double> maximum_reducer(command);
Arcane::VariableCellReal my_variable = ...;
auto in_my_variable = viewIn(command,my_variable);
command << RUNCOMMAND_ENUMERATE(Cell,cid,allCells(),minimum_reducer,maximum_reducer)
{
minimum_reducer.combine(in_my_variable[cid]);
maximum_reducer.combine(in_my_variable[cid]);
};
info() << "MinValue=" << minimum_reducer.reducedValue();
info() << "MaxValue=" << maximum_reducer.reducedValue();
}

Direct Reductions

The GenericReducer class allows launching a specific command dedicated to reduction. An instance of GenericReducer can be used multiple times.