LLNL / RAJA

RAJA Performance Portability Layer (C++)
BSD 3-Clause "New" or "Revised" License
487 stars 103 forks source link

Add support for array reductions #30

Open rhornung67 opened 8 years ago

rhornung67 commented 8 years ago

We may want to support reduction operations for data beyond scalars.

First, meet with application users and collect use cases from different codes to see what's really needed. For example, do users need reducer objects that take a pointer and a length in their constructors, take a pointer in their reduction operators, and return a pointer to the reduced array in the () operator. The reduced array is equivalent to applying the associated scalar reduction to each element in the array.

Second, document user input. Then, based on what's needed, add issues, prioritize, and schedule work.

Note that we don't need "loc" reductions for this because it doesn't really make sense.

jonesholger commented 8 years ago

.

rhornung67 commented 8 years ago

Interesting pattern to consider:

double* reg_data = ...; // reduction array for regions double* field_data = ...; // field on mesh double* zone2reg_map = ; // mapping mesh zones to regions

forall(0, len, [=](int zone) { int zone_reg = zone2reg_map[zone]; reg_data[zone_reg] += field_data[zone]; } );

A first cut to support this could be to have: RAJA::AtomicArray aa(init_val, max_reg);

Then, the summation inside the loop could be replaced with something like this: aa.plus_equal(zone_reg, field_data[zone]);

Retrieving the value could look this this: result = aa[region];