Commit a8f1cdfa authored by i-bird's avatar i-bird

Grid object + tests

parent ca3b7348
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_CANONICAL_SYSTEM
AC_CONFIG_SRCDIR([src/main.cpp])
AM_INIT_AUTOMAKE
AC_CONFIG_HEADER([src/config.h])
m4_ifdef([MYSQL_FOUND],,[m4_include([m4/ax_lib_mysql.m4])])
m4_ifdef([AX_CHECK_COMPILER_FLAGS],,[m4_include([m4/ax_check_compiler_flags.m4])])
m4_ifdef([ACX_PTHREAD],,[m4_include([m4/acx_pthread.m4])])
m4_ifdef([AX_CHECK_CL],,[m4_include([m4/ax_opencl.m4])])
m4_ifdef([AC_PROG_SED],,[m4_include([m4/programs.m4])])
m4_ifdef([AX_BOOST_BASE],,[m4_include([m4/ax_boost_base.m4])])
m4_ifdef([AX_BOOST_PROGRAM_OPTIONS],,[m4_include([m4/ax_boost_program_options.m4])])
m4_ifdef([AX_BOOST_THREAD],,[m4_include([m4/ax_boost_thread.m4])])
m4_ifdef([ACX_MPI],,[m4_include([m4/acx_mpi.m4])])
m4_ifdef([AX_OPENMP],,[m4_include([m4/ax_openmp.m4])])
m4_ifdef([AX_GCC_X86_CPUID],,[m4_include([m4/ax_gcc_x86_cpuid.m4])])
m4_ifdef([AX_GCC_ARCHFLAG],,[m4_include([m4/ax_gcc_archflag.m4])])
CXXFLAGS+=" --std=c++11 "
# Checks for programs.
AC_PROG_CXX
# Checks g++ flags
AC_CANONICAL_HOST
# Check target architetture
AX_GCC_ARCHFLAG([], [CXXFLAGS="$CXXFLAGS $ax_cv_gcc_archflag"], [])
###### Check for debug compilation
AC_MSG_CHECKING(whether to build with debug information)
debuger=no
AC_ARG_ENABLE(debug,
AC_HELP_STRING(
[--enable-debug],
[enable debug data generation (def=no)]
),
debuger="$enableval"
)
AC_MSG_RESULT($debuger)
if test x"$debuger" = x"yes"; then
AC_DEFINE([DEBUG_MODE],[],[Debug])
AC_DEFINE([DEBUG],[],[Debug])
CXXFLAGS="$CXXFLAGS -g3 -Wall -O0 "
else
CXXFLAGS="$CXXFLAGS -Wall -O3 -g3 "
fi
no_avx=no
no_sse42=no
no_sse41=no
no_sse3=no
no_sse2=no
no_sse=no
no_mmx=no
AX_CHECK_COMPILER_FLAGS([-msse4.2],[CXXFLAGS="$CXXFLAGS -mavx"],[no_avx=yes])
AX_CHECK_COMPILER_FLAGS([-msse4.2],[CXXFLAGS="$CXXFLAGS -msse4.2"],[no_sse42=yes])
AX_CHECK_COMPILER_FLAGS([-msse4.1],[CXXFLAGS="$CXXFLAGS -msse4.1"],[no_sse41=yes])
AX_CHECK_COMPILER_FLAGS([-msse3],[CXXFLAGS="$CXXFLAGS -msse3"],[no_sse3=yes])
AX_CHECK_COMPILER_FLAGS([-msse2],[CXXFLAGS="$CXXFLAGS -msse2"],[no_sse2=yes])
AX_CHECK_COMPILER_FLAGS([-msse],[CXXFLAGS="$CXXFLAGS -msse"],[no_sse=yes])
AX_CHECK_COMPILER_FLAGS([-mmmx],[CXXFLAGS="$CXXFLAGS -mmmx"],[no_mmx=yes])
AX_CHECK_COMPILER_FLAGS([-Wno-unused-but-set-variable],[CXXFLAGS="$CXXFLAGS -Wno-unused-but-set-variable"],[])
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_CONFIG_FILES([Makefile src/Makefile])
AC_OUTPUT
echo ""
echo "***********************************"
echo "* *"
arch_str="${ax_cv_gcc_archflag#-march=#-mtune=}"
arch_str="${arch_str#-mtune=}"
n_arch_str=${#arch_str}
for (( X=0; X<23-n_arch_str; X++ ))
do
arch_str="$arch_str "
done
echo "* arch: $arch_str*"
if [ test x"$no_sse42" = x"no" ]; then
echo "* sse4.2: yes *"
else
echo "* sse4.2: no *"
fi
if [ test x"$no_sse41" = x"no" ]; then
echo "* sse4.1: yes *"
else
echo "* sse4.1: no *"
fi
if [ test x"$no_sse3" = x"no" ]; then
echo "* sse3: yes *"
else
echo "* sse3: no *"
fi
if [ test x"$no_sse2" = x"no" ]; then
echo "* sse2: yes *"
else
echo "* sse2: no *"
fi
if [ test x"$no_sse" = x"no" ]; then
echo "* sse: yes *"
else
echo "* sse: no *"
fi
if [ test x"$no_mmx" = x"no" ]; then
echo "* mmx: yes *"
else
echo "* mmx: no *"
fi
if [ test x"$profiler" = x"yes" ]; then
echo "* profiler: yes *"
else
echo "* profiler: no *"
fi
if [ test x"$debuger" = x"yes" ]; then
echo "* debug: yes *"
else
echo "* debug: no *"
fi
if [ test x"$no_64" = x"no" ]; then
echo "* 64 bit: yes *"
else
echo "* 64 bit: no *"
fi
echo "***********************************"
/*typedef size_t part_key;
template<unsigned int dim, typename Tp, typename T, typename Mem>
class Particles
{
size_t n_part;
Mem g_mem;
Mem pos_mem;
Particles(size_t n)
{
g_mem.create(n);
pos_mem.create(dim*n);
n_part = n;
};
T get(size_t id)
{
return g_mem.get(id);
}
Tp get_pos(size_t id)
{
return pos_mem.get(dim*id);
}
};*/
#ifndef POINT_HPP
#define POINT_HPP
#include <boost/fusion/sequence/intrinsic/at_c.hpp>
#include <boost/fusion/include/at_c.hpp>
#include <boost/fusion/container/vector.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/container/vector/vector_fwd.hpp>
#include <boost/fusion/include/vector_fwd.hpp>
template<typename T> class Point
template<typename T> class Point_orig
{
public:
T x;
T y;
T z;
T s;
T v[3];
T t[3][3];
inline void setx(T x_) {x = x_;};
inline void sety(T y_) {y = y_;};
inline void setz(T z_) {z = z_;};
};
\ No newline at end of file
};
// tranformed
template<typename T> class Point
{
public:
typedef boost::fusion::vector<T,T,T,T,T[3],T[3][3]> type;
type data;
static const unsigned int x = 0;
static const unsigned int y = 1;
static const unsigned int z = 2;
static const unsigned int s = 3;
static const unsigned int v = 4;
static const unsigned int t = 5;
inline void setx(T x_) {boost::fusion::at_c<0>(data) = x_;};
inline void sety(T y_) {boost::fusion::at_c<1>(data) = y_;};
inline void setz(T z_) {boost::fusion::at_c<2>(data) = z_;};
};
#endif
......@@ -2,6 +2,8 @@
#include <boost/shared_array.hpp>
#include <vector>
#include <memory.hpp>
#include <initializer_list>
#include <array>
#define HARDWARE 1
......@@ -20,58 +22,213 @@ public:
};
};
template<typename T, typename Mem>
class grid
template<unsigned int dim>
class grid_key_dx
{
size_t size_tot;
std::vector<size_t> sz;
Mem g_mem;
public:
// Static element to calculate total size
grid_key_dx()
{
}
template<typename a, typename ...T>grid_key_dx(a v,T...t)
{
k[dim-1] = v;
invert_assign(t...);
}
template<typename a, typename ...T>void set(a v, T...t)
{
k[dim-1] = v;
invert_assign(t...);
}
mem_id k[dim];
private:
template<typename a, typename ...T>void invert_assign(a v,T...t)
{
k[sizeof...(T)] = v;
invert_assign(t...);
}
size_t totalSize(std::vector<size_t> sz)
template<typename a, typename ...T>void invert_assign(a v)
{
size_t tSz = 1;
for (int i = 0 ; i < sz.size() ; i++)
{
tSz *= sz[i];
}
return tSz;
k[0] = v;
}
};
template<unsigned int dim, unsigned int p>
class grid_key_d
{
public:
grid(std::vector<size_t> sz)
: size_tot(totalSize(sz)), sz(sz)
template<typename a, typename ...T>grid_key_d(a v,T...t)
{
g_mem.create(totalSize(sz));
};
k[dim-1] = v;
invert_assign(t...);
}
~grid() {};
template<typename a, typename ...T>void invert_assign(a v,T...t)
{
k[sizeof...(T)] = v;
invert_assign(t...);
}
template<typename a, typename ...T>void invert_assign(a v)
{
k[0] = v;
}
size_t size()
mem_id k[dim];
};
template<unsigned int p>
class grid_key_1
{
public:
grid_key_1(int i_)
{
return size_tot;
};
k[0] = i_;
}
mem_id k[1];
};
template<unsigned int p>
class grid_key_2
{
public:
grid_key_2(int i_, int j_)
{
k[0] = j_;
k[1] = i_;
}
mem_id k[2];
};
template<unsigned int p>
class grid_key_c3
{
public:
grid_key_c3(mem_id i_, mem_id j_, mem_id k_)
:k{{k_,j_,i_}}
{
}
const std::array<mem_id,3> k;
};
template<unsigned int p>
class grid_key_3
{
public:
grid_key_3(mem_id i_, mem_id j_, mem_id k_)
{
k[0] = k_;
k[1] = j_;
k[2] = i_;
}
mem_id k[3];
};
template<unsigned int p>
class grid_key_4
{
public:
grid_key_4(mem_id u_, mem_id i_, mem_id j_, mem_id k_)
{
k[0] = k_;
k[1] = j_;
k[2] = i_;
k[3] = u_;
}
mem_id k[4];
};
template<unsigned int p>
class grid_key
{
public:
template<unsigned int s>grid_key(grid_key<s> & key)
{
id = key.id;
}
grid_key(size_t sz)
:id(new mem_id[sz])
{
}
void set_d(size_t id_, mem_id val)
{
id[id_] = val;
}
void set(mem_id val1)
{
id[0] = val1;
}
void set(mem_id val1, mem_id val2)
{
id[0] = val2;
id[1] = val1;
}
void set(mem_id val1, mem_id val2, mem_id val3)
{
id[0] = val3;
id[1] = val2;
id[2] = val1;
}
void set(mem_id val1, mem_id val2, mem_id val3, mem_id val4)
{
id[0] = val4;
id[1] = val3;
id[2] = val2;
id[3] = val1;
}
mem_id * getId()
{
return id.get();
}
boost::shared_array<mem_id> id;
};
template<typename T>
class grid<T,memory_null>
class grid
{
size_t size_tot;
std::vector<size_t> sz;
std::vector<size_t> sz_s;
public:
// Static element to calculate total size
size_t totalSize(std::vector<size_t> sz)
size_t totalSize(std::vector<size_t> & sz)
{
size_t tSz = 1;
for (int i = 0 ; i < sz.size() ; i++)
for (size_t i = 0 ; i < sz.size() ; i++)
{
tSz *= sz[i];
}
......@@ -79,11 +236,95 @@ public:
return tSz;
}
grid(std::vector<size_t> sz)
grid(std::vector<size_t> & sz)
: size_tot(totalSize(sz)), sz(sz)
{
sz_s.resize(sz.size());
sz_s[0] = sz[0];
for (size_t i = 1 ; i < sz.size() ; i++)
{
sz_s[i] = sz[i]*sz_s[i-1];
}
};
template<unsigned int dim> mem_id LinId(grid_key_dx<dim> & gk)
{
mem_id lid = gk.k[0];
for (mem_id i = 1 ; i < dim ; i++)
{
lid += gk.k[i] * sz_s[i-1];
}
return lid;
}
template<unsigned int p> mem_id LinId(grid_key_3<p> & gk)
{
mem_id lid = gk.k[0];
lid += gk.k[1]*sz_s[0];
lid += gk.k[2]*sz_s[1];
return lid;
}
template<unsigned int dim, unsigned int p> mem_id LinId(grid_key_d<dim,p> & gk)
{
mem_id lid = gk.k[0];
for (mem_id i = 1 ; i < dim ; i++)
{
lid += gk.k[i] * sz_s[i-1];
}
return lid;
}
mem_id LinId(mem_id * id)
{
mem_id lid = 0;
lid += id[0];
for (mem_id i = 1 ; i < (mem_id)sz.size() ; i++)
{
lid += id[i] * sz_s[i-1];
}
return lid;
}
mem_id LinId(mem_id i)
{
return i;
}
mem_id LinId(mem_id j, mem_id k)
{
mem_id lid = 0;
lid += k;
lid += j*sz_s[0];
return lid;
}
mem_id LinId(mem_id i, mem_id j, mem_id k)
{
mem_id lid = 0;
lid += k;
lid += j*sz_s[0];
lid += i*sz_s[1];
return lid;
}
mem_id LinId(mem_id u, mem_id i, mem_id j, mem_id k)
{
mem_id lid = 0;
lid += k;
lid += j*sz_s[0];
lid += i*sz_s[1];
lid += u*sz_s[2];
return lid;
}
~grid() {};
size_t size()
......@@ -106,8 +347,5 @@ public:
class grid_key
{
mem_id id[];
};
#include "map.hpp"
#include "memory.hpp"
#include "Particle.hpp"
#include <boost/mpl/int.hpp>
#include <typeinfo>
#include <test_1.hpp>
#include <test_2.hpp>
#include <test_3.hpp>
#include <test_4.hpp>
#include <test_5.hpp>
float Wi(float dist_x)
{
if (dist_x <= 1)
return 1.5f*dist_x * dist_x * dist_x - 2.5f * dist_x * dist_x + 1.0f;
else if (dist_x <= 2)
return -0.5f*dist_x * dist_x * dist_x * dist_x + 2.5f * dist_x * dist_x - 4.0f * dist_x + 2.0f;
else
return 0.0;
}
int main()
{
/* tensor<int,3,3,3> c;
tensor<tensor<int,3,3,3>,3,3,3> c2;
tensor<tensor<int,3,3,3>,3,3,3> c2;*/
std::vector<size_t> sz;
sz.push_back(10);
sz.push_back(10);
sz.push_back(10);
sz.push_back(GS_SIZE);
sz.push_back(GS_SIZE);
sz.push_back(GS_SIZE);
grid<int> c3(sz);
grid< tensor<int,3,3,3> > c4(sz);
grid< tensor< tensor<int,3,3,3> ,3,3,3> > c5(sz);
layout_cpu< grid<Point<float>>, memory_cpu<memory_cpu_type<Point<float>>::type> > c3(sz);
// cpu test
std::cout << c.size() << "\n";
std::cout << c2.size() << "\n";
std::cout << c3.size() << "\n";
std::cout << c4.size() << "\n";
std::cout << c5.size() << "\n";*/
test1();
// layout_cpu< Particles<Point<float>, memory_cpu<float> >, particle_key > p1;
test2(c3);
test3(c3);
test4(c3);
test5(c3);
// k.set(2,2,2);
// c3.get(k).x = 6.0;
// std::cout << c3.get(k) << "\n";
// c3.output("vtk");
// iterator test
// auto it1 = c3.iterator();
/* while (it1.next())
{
it1.get().x = it1.getId(0);
it1.get().y = it1.getId(1);
it1.get().z = it1.getId(2);
}*/