Commit 50a97ff6 authored by Pietro Incardona's avatar Pietro Incardona

Adding missing files

parent c78ac493
File added
File added
File added
......@@ -213,10 +213,18 @@ else
NVCCFLAGS+="$NVCCFLAGS -O3 "
fi
##########
## Check for LIBHILBERT
AX_LIB_HILBERT([],[echo "Cannot detect libhilbert, use the --with-libhilbert option if it is not installed in the default location"
exit 210])
####### include openfpm_devices include path
INCLUDES_PATH+="-I. -Iconfig -I../../openfpm_devices/src -I../../openfpm_io/src"
####### Checking for GPU support
AX_CUDA
......
# ===========================================================================
#
# ===========================================================================
#
# SYNOPSIS
#
# AX_LIB_HILBERT()
#
# DESCRIPTION
#
# This macro provides tests of the availability of libHilbert library.
#
#
# The macro adds a --with-libhilbert option accepting one of three values:
#
# no - do not check for the libhilbert library.
# yes - do check for libhilbert library in standard locations.
# path - complete path to the libhilbert library.
#
# If libhilbert is successfully found, this macro calls
#
# AC_SUBST(LIBHILBERT_INCLUDE)
# AC_SUBST(LIBHILBERT_LIB)
# AC_DEFINE(HAVE_LIBHILBERT)
#
# and sets with_libhilbert="yes"
#
# If libhilbert is disabled or not found, this macros sets with_libhilbert="no"
#
# Your configuration script can test $with_libhilbert to take any further
# actions. LIBHILBERT_{INCLUDE,LIB} may be used when building with C or C++.
#
# To use the macro, one would code one of the following in "configure.ac"
# before AC_OUTPUT:
#
# 1) dnl Check for libhilbert support
# AX_LIB_HILBERT()
#
# One could test $with_libhilbert for the outcome or display it as follows
#
# echo "libhilbert support: $with_libhilbert"
#
# You could also for example, override the default CC in "configure.ac"
#
# LICENSE
#
# Copyright (c) 2009 Timothy Brown <tbrown@freeshell.org>
# Copyright (c) 2010 Rhys Ulerich <rhys.ulerich@gmail.com>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 12
AC_DEFUN([AX_LIB_HILBERT], [
AC_MSG_CHECKING(for libhilbert library)
AC_REQUIRE([AC_PROG_CC])
#
# User hints...
#
AC_ARG_VAR([LIBHILBERT], [Libhilbert library location])
AC_ARG_WITH([libhilbert],
[AC_HELP_STRING([--with-libhilbert],
[user defined path to LIBHILBERT library])],
[
if test -n "$LIBHILBERT" ; then
AC_MSG_RESULT(yes)
with_libhilbert=$LIBHILBERT
elif test "$withval" != no ; then
AC_MSG_RESULT(yes)
with_libhilbert=$withval
else
AC_MSG_RESULT(no)
fi
],
[
if test -n "$PETSC" ; then
with_libhilbert=$PETSC
AC_MSG_RESULT(yes)
else
with_petsc=/usr
if test ! -f "$with_libhilbert/include/hilbertKey.h" ; then
with_libhilbert=/usr/local
if test ! -f "$with_libhilbert/include/hilbertKey.h" ; then
with_libhilbert=""
AC_MSG_RESULT(failed)
else
AC_MSG_RESULT(yes)
fi
else
AC_MSG_RESULT(yes)
fi
fi
])
#
# locate LIBHILBERT library
#
if test -n "$with_libhilbert" ; then
old_CC=$CC
old_CFLAGS=$CFLAGS
old_LDFLAGS=$LDFLAGS
CFLAGS="-I$with_libhilbert/include "
LDFLAGS="-L$with_libhilbert/lib "
CC=$CXX
AC_LANG_SAVE
AC_LANG_C
AC_CHECK_HEADER([hilbertKey.h],libhilbert_h=yes,## Copy LIB and include in the target directory
AC_MSG_WARN([could not find header file hilbertKey.h]))
AC_CHECK_LIB([libhilbert],[getIntCoordFromHKey],libhilbert_lib=yes,AC_MSG_WARN([could not find libhilbert]))
AC_LANG_RESTORE
CFLAGS=$old_CFLAGS
LDFLAGS=$old_LDFLAGS
CC=$old_CC
AC_MSG_CHECKING(LIBHILBERT in $with_libhilbert)
if test x"$libhilbert_lib" = x"yes" -a x"$libhilbert_h" = x"yes" ; then
AC_SUBST(LIBHILBERT_INCLUDE, [-I$with_libhilbert/include])
AC_SUBST(LIBHILBERT_LIB, ["-L$with_libhilbert/lib -llibhilbert"])
AC_MSG_RESULT(ok)
AC_DEFINE(HAVE_LIBHILBERT,1,[Define if you have LIBHILBERT library])
else
AC_MSG_RESULT(failed)
fi
fi
#
#
#
if test x = x"$LIBHILBERT_LIB" ; then
ifelse([$2],,[],[$2])
:
else
ifelse([$1],,[],[$1])
:
fi
])dnl AX_LIB_HILBERT
/*
* grid_key_dx_iterator_hilbert.hpp
*
* Created on: Feb 24, 2016
* Author: yaroslav
*/
#ifndef OPENFPM_DATA_SRC_GRID_GRID_KEY_DX_ITERATOR_HILBERT_HPP_
#define OPENFPM_DATA_SRC_GRID_GRID_KEY_DX_ITERATOR_HILBERT_HPP_
extern "C"
{
#include "hilbertKey.h"
}
/*
*
* Grid key class iterator, iterate through the grid elements following an
* hilbert space filling curve
*
* \param dim dimensionality of the grid
*
* ### Grid iterator declaration and usage
* \snippet grid_unit_tests.hpp Grid iterator test usage
*
*/
template<unsigned int dim>
class grid_key_dx_iterator_hilbert
{
#ifdef DEBUG
// Actual status of the iterator, when the iterator is not initialized cannot be used
// and reinitialize must be called
bool initialized = false;
#endif
//A hilbert key
uint64_t hkey = 0;
//Order of a hilbert curve
size_t m;
grid_sm<dim,void> grid_base;
protected:
grid_key_dx<dim> gk;
public:
/*! \brief Constructor require a grid_sm<dim,T>
*
* \param g info of the grid on which iterate
*/
grid_key_dx_iterator_hilbert(int32_t m)
:m(m)
{
// create from m the correct grid_sm
size_t dims[dim];
//Set the 2^m value to the each elements of dims[]
for (size_t i = 0 ; i < dim ; i++)
dims[i] = 1 << m;
//Set grid_sm dimensions
grid_base.setDimensions(dims);
reset();
#ifdef DEBUG
initialized = true;
#endif
}
/*! \brief Get the next element
*
* \return the next grid_key
*
*/
grid_key_dx_iterator_hilbert<dim> & operator++()
{
//An integer to handle errors
int err;
hkey++;
//Array to handle output
uint64_t nextCoord[dim];
//Get the coordinates of the next cell
getIntCoordFromHKey(nextCoord, m, dim, hkey, &err);
//Set the new coordinates
for (size_t i = 0; i < dim; i++)
gk.set_d(i, nextCoord[i]);
return *this;
}
/*! \brief Check if there is the next element
*
* Check if there is the next element
*
* \return true if there is the next, false otherwise
*
*/
bool isNext()
{
if ( hkey < (size_t)1 << (m*dim))
{
//! we did not reach the end of the grid
return true;
}
//! we reach the end of the grid
return false;
}
/*! \brief Get the actual key
*
* Get the actual key
*
* \return the actual key
*
*/
const grid_key_dx<dim> & get()
{
return gk;
}
/*! \brief Reset the iterator (it restart from the beginning)
*
*/
void reset()
{
//! Initialize to 0 the index
for (size_t i = 0 ; i < dim ; i++)
gk.set_d(i,0);
}
};
#endif /* OPENFPM_DATA_SRC_GRID_GRID_KEY_DX_ITERATOR_HILBERT_HPP_ */
LINKLIBS = $(PTHREAD_LIBS) $(OPT_LIBS) $(BOOST_LDFLAGS) $(BOOST_PROGRAM_OPTIONS_LIB) $(CUDA_LIBS) $(BOOST_IOSTREAMS_LIB) $(LOCAL_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(BOOST_CHRONO_LIB) $(BOOST_TIMER_LIB) $(BOOST_SYSTEM_LIB)
LINKLIBS = $(LIBHILBERT_LIB) $(PTHREAD_LIBS) $(OPT_LIBS) $(BOOST_LDFLAGS) $(BOOST_PROGRAM_OPTIONS_LIB) $(CUDA_LIBS) $(BOOST_IOSTREAMS_LIB) $(LOCAL_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(BOOST_CHRONO_LIB) $(BOOST_TIMER_LIB) $(BOOST_SYSTEM_LIB)
if BUILDCUDA
CUDA_SOURCES=../../openfpm_devices/src/memory/CudaMemory.cu
......@@ -9,9 +9,9 @@ endif
noinst_PROGRAMS = mem_map
mem_map_SOURCES = ../../openfpm_devices/src/Memleak_check.cpp main.cpp $(CUDA_SOURCES) ../../openfpm_devices/src/memory/HeapMemory.cpp ../../openfpm_devices/src/memory/PtrMemory.cpp
mem_map_CXXFLAGS = $(CUDA_CFLAGS) $(INCLUDES_PATH) $(BOOST_CPPFLAGS) -I/usr/local/include -I/usr/local/libhilbert/include
mem_map_CXXFLAGS = $(LIBHILBERT_INCLUDE) $(CUDA_CFLAGS) $(INCLUDES_PATH) $(BOOST_CPPFLAGS) -I/usr/local/include -I/usr/local/libhilbert/include
mem_map_CFLAGS = $(CUDA_CFLAGS)
mem_map_LDADD = $(LINKLIBS) -L/usr/local/libhilbert/lib -lhilbert
mem_map_LDADD = $(LINKLIBS)
nobase_include_HEADERS= data_type/scalar.hpp data_type/aggregate.hpp \
Graph/graph_unit_tests.hpp Graph/map_graph.hpp \
......
/*
* CellListFast_hilb.hpp
*
* Created on: May 17, 2016
* Author: Yaroslav Zaluzhnyi
*/
#ifndef OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTFAST_HILB_HPP_
#define OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTFAST_HILB_HPP_
#include "CellListFast.hpp"
#include "CellListIterator.hpp"
extern "C"
{
#include "hilbertKey.h"
}
/* !Brief Class for FAST hilbert cell list implementation
*
* \see CellList<dim,T,FAST,transform,base>
*
* \tparam dim Dimansionality of the space
* \tparam T type of the space float, double, complex
* \tparam base Base structure that store the information
*
*/
template<unsigned int dim, typename T, unsigned int impl=FAST, typename transform = no_transform<dim,T>, typename base=openfpm::vector<size_t>>
class CellList_hilb : public CellList<dim,T,impl,transform,base>
{
private:
// Ghost marker
size_t g_m = 0;
// vector for storing the cell keys
openfpm::vector<size_t> keys;
// vector for storing the particle keys
openfpm::vector<size_t> p_keys;
//Order of an hilbert curve
size_t m;
/*! \brief Get an hilbert key from the coordinates and add to the getKeys vector
*
* \param gk grid key
*
*/
void get_hkey(grid_key_dx<dim> gk)
{
//An integer to handle errors
int err;
uint64_t point[dim];
for (size_t i = 0; i < dim; i++)
{
point[i] = gk.get(i);
}
size_t hkey = getHKeyFromIntCoord(m, dim, point, &err);
this->getKeys().add(hkey);
}
/*! \brief Get get the coordinates from hilbert key, linearize and add to the getKeys vector
*
*
*
*/
void linearize_hkeys()
{
//An integer to handle errors
int err;
//Array to handle output
uint64_t coord[dim];
this->getKeys().sort();
openfpm::vector<size_t> keys_new;
for(size_t i = 0; i < this->getKeys().size(); i++)
{
getIntCoordFromHKey(coord, m, dim, this->getKeys().get(i), &err);
for (size_t j = 0 ; j < dim ; j++) {coord[j] += this->getPadding(j);}
keys_new.add(this->getGrid().LinIdPtr(coord));
}
this->getKeys().swap(keys_new);
}
public:
/*! Initialize the cell list
*
* \param box Domain where this cell list is living
* \param div grid size on each dimension
* \param g_m_new A ghost marker
* \param pad padding cell
* \param slot maximum number of slot
*
*/
void Initialize(const Box<dim,T> & box, const size_t (&div)[dim], size_t g_m_new, const size_t pad = 1, size_t slot=STARTING_NSLOT)
{
CellList<dim,T,impl,transform,base>::Initialize(box,div,pad,slot);
g_m = g_m_new;
size_t sz[dim];
for (size_t i = 0; i < dim ; i++)
sz[i] = this->getGrid().size(i) - 2*pad;
grid_sm<dim,void> gs_small(sz);
size_t a = gs_small.size(0);
for (size_t i = 1 ; i < dim ; i++)
{
if (a < gs_small.size(i))
a = gs_small.size(i);
}
for (m = 0; ; m++)
{
if ((1ul << m) >= a)
break;
}
//std::cout << "An order of a corresponding hilberts curve is " << m << std::endl;
grid_key_dx_iterator<dim> it(gs_small);
while (it.isNext())
{
auto gk = it.get();
// Get an hilbert key of each cell and add to 'keys' vector
this->get_hkey(gk);
++it;
}
// Sort and linearize hilbert keys
this->linearize_hkeys();
}
CellList_hilb()
:CellList<dim,T,impl,transform,base>()
{};
/*! \brief Return cellkeys vector
*
* \return vector of cell keys
*
*/
inline openfpm::vector<size_t> & getKeys()
{
return keys;
}
/*! \brief return the ghost marker
*
* \return ghost marker
*
*/
inline size_t get_gm()
{
return g_m;
}
/*! \brief return the celllist iterator (across cells)
*
* \return an iterator
*
*/
inline Cell_list_iterator<CellList_hilb<dim,T,impl,transform,base>> getIterator()
{
return Cell_list_iterator<CellList_hilb<dim,T,impl,transform,base>>(*this);
}
};
#endif /* OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTFAST_HILB_HPP_ */
/*
* CellListIt.hpp
*
* Created on: May 18, 2016
* Author: Yaroslav Zaluzhnyi
*/
#ifndef OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTITERATOR_HPP_
#define OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTITERATOR_HPP_
template<typename T>
class Cell_list_iterator
{
private:
T & NN;
// Cells counter
size_t cell_count;
// Particles counter
size_t p_count;
/*! \brief Handles incrementing of cells and particles counters
*
*/
inline void fp()
{
++p_count;
if (p_count >= NN.getNelements(NN.getKeys().get(cell_count)))
{
p_count = 0;
++cell_count;
while (cell_count < NN.getKeys().size() && NN.getNelements(NN.getKeys().get(cell_count)) == 0)
{
++cell_count;
}
}
}
public:
// Constructor
Cell_list_iterator(T & NN)
:NN(NN)
{
reset();
}
// Destructor
~Cell_list_iterator()
{
}
/*! \brief Get the next element
*
* \return cell list iterator
*
*/
inline Cell_list_iterator operator++()
{
fp();
while (isNext() && this->get() >= NN.get_gm())
{
fp();
}
return *this;
}
/*! \brief Checks if there is a next element
*
* \return true if there is the next, false otherwise
*
*/
inline bool isNext()
{
if (cell_count >= NN.getKeys().size())
{
return false;
}
return true;
}
/*! \brief Get the real particle id
*
* \return the real particle id
*
*/
inline size_t get()
{
auto cell_id = NN.getKeys().get(cell_count);
auto p = NN.get(cell_id,p_count);
return p;
}
/*! \brief Reset an iterator (set the counters to the first valid ones)
*
*/
void reset()
{
cell_count = 0;
p_count = -1;
this->operator++();
}
};
#endif /* OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTITERATOR_HPP_ */
/*
* CellListIterator_test.hpp
*
* Created on: May 7, 2016
* Author: Yaroslav Zaluzhnyi
*/
#ifndef OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTITERATOR_TEST_HPP_
#define OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTITERATOR_TEST_HPP_
#include "NN/CellList/CellListIterator.hpp"
#include "NN/CellList/CellListFast_hilb.hpp"