Commit 5f2a4d10 authored by Andreas Beckmann's avatar Andreas Beckmann
Browse files

updated examples

parent a232790d
.clang-format
*.o
*.dump
This diff is collapsed.
../01-naive/Makefile
\ No newline at end of file
/*
* Copyright © 2019 Andreas Beckmann <a.beckmann@fz-juelich.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "coulomb_common.hpp"
#include "coulomb_measure.hpp"
template <typename CoulombData>
void naive_coulomb(CoulombData &c, size_t n = 0)
{
typedef typename CoulombData::value_type Real;
//const Real two(2.);
const Real two(runtime_constant(Real(2.)));
n = n ? std::min(c.size(), n) : c.size();
for (size_t j = 0; j < n; ++j)
{
for (size_t i = 0; i < n; ++i)
{
if (i != j)
{
Real dx = c.x(i) - c.x(j);
Real dy = c.y(i) - c.y(j);
Real dz = c.z(i) - c.z(j);
Real squared_dist = std::pow(dx, two) + std::pow(dy, two) + std::pow(dz, two);
c.Fx(i) += dx * c.q(i) * c.q(j) / std::pow(std::sqrt(squared_dist), Real(3));
c.Fy(i) += dy * c.q(i) * c.q(j) / std::pow(std::sqrt(squared_dist), Real(3));
c.Fz(i) += dz * c.q(i) * c.q(j) / std::pow(std::sqrt(squared_dist), Real(3));
}
}
}
}
#if !defined(USE_FLOAT)
typedef double Real;
#else
typedef float Real;
#endif
#if defined(USE_AoS)
typedef CoulombData_AoS<Real> CoulombData;
#elif defined(USE_AoS2)
typedef CoulombData_AoS2<Real> CoulombData;
#elif defined(USE_SoA)
typedef CoulombData_SoA<Real> CoulombData;
#elif defined(USE_AoSoA)
typedef CoulombData_AoSoA<Real> CoulombData;
#endif
int main(int argc, char **argv)
{
mypapi_init();
size_t n = argc > 1 ? atoi(argv[1]) : 10000;
std::shared_ptr<CoulombData> c = make_coulomb_data<CoulombData>(n);
// do some work to heat up a throttled CPU
preheat_coulomb(*c, 10000);
std::string label = "pow(x, {2,3})";
auto function = naive_coulomb<CoulombData>;
if (1)
multimeasure(label, *c, function);
mypapi_cleanup();
}
// vim: et:ts=4:sw=4
/*
* Copyright © 2019 Andreas Beckmann <a.beckmann@fz-juelich.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "coulomb_common.hpp"
#include "coulomb_measure.hpp"
......@@ -40,6 +57,8 @@ typedef CoulombData_AoS<Real> CoulombData;
typedef CoulombData_AoS2<Real> CoulombData;
#elif defined(USE_SoA)
typedef CoulombData_SoA<Real> CoulombData;
#elif defined(USE_AoSoA)
typedef CoulombData_AoSoA<Real> CoulombData;
#endif
......
../01-naive/Makefile
\ No newline at end of file
/*
* Copyright © 2019 Andreas Beckmann <a.beckmann@fz-juelich.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "coulomb_common.hpp"
#include "coulomb_measure.hpp"
......@@ -41,6 +58,8 @@ typedef CoulombData_AoS<Real> CoulombData;
typedef CoulombData_AoS2<Real> CoulombData;
#elif defined(USE_SoA)
typedef CoulombData_SoA<Real> CoulombData;
#elif defined(USE_AoSoA)
typedef CoulombData_AoSoA<Real> CoulombData;
#endif
......
../01-naive/Makefile
\ No newline at end of file
/*
* Copyright © 2019 Andreas Beckmann <a.beckmann@fz-juelich.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "coulomb_common.hpp"
#include "coulomb_measure.hpp"
......@@ -41,6 +58,8 @@ typedef CoulombData_AoS<Real> CoulombData;
typedef CoulombData_AoS2<Real> CoulombData;
#elif defined(USE_SoA)
typedef CoulombData_SoA<Real> CoulombData;
#elif defined(USE_AoSoA)
typedef CoulombData_AoSoA<Real> CoulombData;
#endif
......
include ../Makefile.common
../01-naive/Makefile
\ No newline at end of file
/*
* Copyright © 2019 Andreas Beckmann <a.beckmann@fz-juelich.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "coulomb_common.hpp"
#include "coulomb_measure.hpp"
......@@ -41,6 +58,8 @@ typedef CoulombData_AoS<Real> CoulombData;
typedef CoulombData_AoS2<Real> CoulombData;
#elif defined(USE_SoA)
typedef CoulombData_SoA<Real> CoulombData;
#elif defined(USE_AoSoA)
typedef CoulombData_AoSoA<Real> CoulombData;
#endif
......
../01-naive/Makefile
\ No newline at end of file
/*
* Copyright © 2019 Andreas Beckmann <a.beckmann@fz-juelich.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "coulomb_common.hpp"
#include "coulomb_measure.hpp"
......@@ -46,6 +63,8 @@ typedef CoulombData_AoS<Real> CoulombData;
typedef CoulombData_AoS2<Real> CoulombData;
#elif defined(USE_SoA)
typedef CoulombData_SoA<Real> CoulombData;
#elif defined(USE_AoSoA)
typedef CoulombData_AoSoA<Real> CoulombData;
#endif
......
../01-naive/Makefile
\ No newline at end of file
/*
* Copyright © 2019 Andreas Beckmann <a.beckmann@fz-juelich.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "coulomb_common.hpp"
#include "coulomb_measure.hpp"
template <typename CoulombData>
void naive_coulomb(CoulombData &c, size_t n = 0)
{
typedef typename CoulombData::value_type Real;
n = n ? std::min(c.size(), n) : c.size();
for (size_t i = 0; i < n; ++i)
{
Real xi = c.x(i), yi = c.y(i), zi = c.z(i), qi = c.q(i);
Real Fxi = 0., Fyi = 0., Fzi = 0.;
for (size_t j = 0; j < i; ++j)
{
{
Real dx = xi - c.x(j);
Real dy = yi - c.y(j);
Real dz = zi - c.z(j);
Real squared_dist = dx * dx + dy * dy + dz * dz;
Real inverse_dist = rsqrt_exact(squared_dist);
Real qj_rrr = (c.q(j) * inverse_dist) * (inverse_dist * inverse_dist);
Fxi += dx * qj_rrr;
Fyi += dy * qj_rrr;
Fzi += dz * qj_rrr;
}
}
// avoid iteration and test for (j == i)
for (size_t j = i + 1; j < n; ++j)
{
{
Real dx = xi - c.x(j);
Real dy = yi - c.y(j);
Real dz = zi - c.z(j);
Real squared_dist = dx * dx + dy * dy + dz * dz;
Real inverse_dist = rsqrt_exact(squared_dist);
Real qj_rrr = (c.q(j) * inverse_dist) * (inverse_dist * inverse_dist);
Fxi += dx * qj_rrr;
Fyi += dy * qj_rrr;
Fzi += dz * qj_rrr;
}
}
c.Fx(i) += Fxi * qi;
c.Fy(i) += Fyi * qi;
c.Fz(i) += Fzi * qi;
}
}
#if !defined(USE_FLOAT)
typedef double Real;
#else
typedef float Real;
#endif
#if defined(USE_AoS)
typedef CoulombData_AoS<Real> CoulombData;
#elif defined(USE_AoS2)
typedef CoulombData_AoS2<Real> CoulombData;
#elif defined(USE_SoA)
typedef CoulombData_SoA<Real> CoulombData;
#elif defined(USE_AoSoA)
typedef CoulombData_AoSoA<Real> CoulombData;
#endif
int main(int argc, char **argv)
{
mypapi_init();
size_t n = argc > 1 ? atoi(argv[1]) : 50000;
std::shared_ptr<CoulombData> c = make_coulomb_data<CoulombData>(n);
// do some work to heat up a throttled CPU
preheat_coulomb(*c, 10000);
std::string label = "split inner loop";
auto function = naive_coulomb<CoulombData>;
if (1)
multimeasure(label, *c, function);
mypapi_cleanup();
}
// vim: et:ts=4:sw=4
include ../Makefile.common
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment