exasim-project / NeoFOAM

WIP Prototype of a modern CFD core
19 stars 1 forks source link

added parallelFor and parallelReduce #62

Open HenningScheufler opened 1 month ago

HenningScheufler commented 1 month ago

This PR addes parallelFor and parallelReduce to simplify the implementation of new operation/algorithms

  auto spanA = fieldA.field();
  auto spanB = fieldB.field();
  NeoFOAM::fill(fieldB, 1.0);
  NeoFOAM::parallelFor(
      exec,
      0,
      fieldA.size(),
      KOKKOS_LAMBDA(const int i) { spanA[i] = spanB[i] + 2.0; }
  );

and parallelReduce :

  auto spanB = fieldB.field();
  NeoFOAM::fill(fieldB, 1.0);
  NeoFOAM::scalar sum = 0.0;
  NeoFOAM::parallelReduce(
      exec,
      0,
      5,
      KOKKOS_LAMBDA(const int i, double& lsum) { lsum += spanB[i]; },
      sum
  );
HenningScheufler commented 1 month ago

With this approach we can replace the macro in FieldOperations.H to make them more readable:

template<typename T>
void fill2(NeoFOAM::Field<T>& field, T value)
{
    auto spanField = field.field();
    auto lambda = KOKKOS_LAMBDA(const int i) { spanField[i] = value; };
    return std::visit(
        [&](const auto& e)
        {
            parallelForImpl(
                e,
                0,
                field.size(),
                lambda
            );
        },
        field.exec()
    );
};

@greole @bevanwsjones

Should merged after PR: