Skip to content

Commit

Permalink
Manifoldmath: more performant implementation of project_parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
Moritz committed Apr 20, 2022
1 parent d07ce03 commit aca472f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
12 changes: 6 additions & 6 deletions core/src/engine/Manifoldmath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ namespace Manifoldmath
{
void project_parallel( vectorfield & vf1, const vectorfield & vf2 )
{
vectorfield vf3 = vf1;
project_orthogonal( vf3, vf2 );
// TODO: replace the loop with Vectormath Kernel
#pragma omp parallel for
for( unsigned int i = 0; i < vf1.size(); ++i )
vf1[i] -= vf3[i];
scalar proj = Vectormath::dot(vf1, vf2);
Backend::par::apply( vf1.size(), [vf1 = vf1.data(), vf2 = vf2.data(), proj] SPIRIT_LAMBDA (int idx)
{
vf1[idx] = proj * vf2[idx];
}
);
}

void project_orthogonal( vectorfield & vf1, const vectorfield & vf2 )
Expand Down
10 changes: 7 additions & 3 deletions core/src/engine/Manifoldmath.cu
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <engine/Vectormath.hpp>
#include <engine/Manifoldmath.hpp>
#include <engine/Backend_par.hpp>
#include <utility/Constants.hpp>

#include <Eigen/Dense>
Expand All @@ -18,9 +19,12 @@ namespace Engine
{
void project_parallel(vectorfield & vf1, const vectorfield & vf2)
{
vectorfield vf3 = vf1;
project_orthogonal(vf3, vf2);
Vectormath::add_c_a(-1, vf3, vf1);
scalar proj = Vectormath::dot(vf1, vf2);
Backend::par::apply( vf1.size(), [vf1 = vf1.data(), vf2 = vf2.data(), proj] SPIRIT_LAMBDA (int idx)
{
vf1[idx] = proj * vf2[idx];
}
);
}

__global__ void cu_project_orthogonal(Vector3 *vf1, const Vector3 *vf2, scalar proj, size_t N)
Expand Down

0 comments on commit aca472f

Please sign in to comment.