Skip to content

Commit

Permalink
test coeff in parallelfor
Browse files Browse the repository at this point in the history
  • Loading branch information
HenningScheufler committed Oct 6, 2024
1 parent 929d37e commit e2af6cd
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions test/dsl/coeff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,65 @@ TEST_CASE("Coeff")
REQUIRE(hostResF.data()[1] == 12.0);
REQUIRE(hostResF.data()[2] == 12.0);
}

SECTION("evaluation in parallelFor" + execName)
{
size_t size = 3;

NeoFOAM::Field<NeoFOAM::scalar> fieldA(exec, size, 0.0);
NeoFOAM::Field<NeoFOAM::scalar> fieldB(exec, size, 1.0);

SECTION("span")
{
Coeff coeff = fieldB; // is a span with uniform value 1.0
{
NeoFOAM::parallelFor(
fieldA, KOKKOS_LAMBDA(const size_t i) { return coeff[i] + 2.0; }
);
};
auto hostFieldA = fieldA.copyToHost();
REQUIRE(coeff.hasSpan() == true);
REQUIRE(hostFieldA[0] == 3.0);
REQUIRE(hostFieldA[1] == 3.0);
REQUIRE(hostFieldA[2] == 3.0);
}

SECTION("scalar")
{
NeoFOAM::Field<NeoFOAM::scalar> fieldA(exec, size, 0.0);

Coeff coeff = Coeff(2.0);
{
NeoFOAM::parallelFor(
fieldA, KOKKOS_LAMBDA(const size_t i) { return coeff[i] + 2.0; }
);
};
auto hostFieldA = fieldA.copyToHost();
REQUIRE(coeff.hasSpan() == false);
REQUIRE(hostFieldA[0] == 4.0);
REQUIRE(hostFieldA[1] == 4.0);
REQUIRE(hostFieldA[2] == 4.0);
}

SECTION("span and scalar")
{
NeoFOAM::Field<NeoFOAM::scalar> fieldA(exec, size, 0.0);
NeoFOAM::Field<NeoFOAM::scalar> fieldB(exec, size, 1.0);
Coeff coeff {-5.0,fieldB};
{
NeoFOAM::parallelFor(
fieldA, KOKKOS_LAMBDA(const size_t i) { return coeff[i] + 2.0; }
);
};
auto hostFieldA = fieldA.copyToHost();
REQUIRE(coeff.hasSpan() == true);
REQUIRE(hostFieldA[0] == -3.0);
REQUIRE(hostFieldA[1] == -3.0);
REQUIRE(hostFieldA[2] == -3.0);
}

}



}

0 comments on commit e2af6cd

Please sign in to comment.