OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
grid_cpu< dim, T, S, typename memory_traits_lin< T >::type > Class Template Reference

This is an N-dimensional grid or an N-dimensional array with memory_traits_lin layout. More...

Detailed Description

template<unsigned int dim, typename T, typename S>
class grid_cpu< dim, T, S, typename memory_traits_lin< T >::type >

This is an N-dimensional grid or an N-dimensional array with memory_traits_lin layout.

it is basically an N-dimensional Cartesian grid

Template Parameters
dimDimensionality of the grid
Ttype of object the grid store
Stype of memory HeapMemory CudaMemory
layoutmemory layout

Defining the grid size on each dimension

size_t sz[3] = {16,16,16};

Definition and allocation of a 3D grid on CPU memory

c3.setMemory();

Access a grid c3 of size sz on each direction

typedef Point_test<float> P;
timer t;
t.start();
for (size_t i = 0 ; i < sz ; i++)
{
for (size_t j = 0 ; j < sz ; j++)
{
for (size_t k = 0 ; k < sz ; k++)
{
kk.set(i,j,k);
c3.template get<P::x>(kk) = 1.1f;
c3.template get<P::y>(kk) = 1.2f;
c3.template get<P::z>(kk) = 1.3f;
c3.template get<P::s>(kk) = 1.0f;
c3.template get<P::v>(kk)[0] = 1.0f;
c3.template get<P::v>(kk)[1] = 2.0f;
c3.template get<P::v>(kk)[2] = 3.0f;
c3.template get<P::t>(kk)[0][0] = 1.0f;
c3.template get<P::t>(kk)[0][1] = 2.0f;
c3.template get<P::t>(kk)[0][2] = 3.0f;
c3.template get<P::t>(kk)[1][0] = 4.0f;
c3.template get<P::t>(kk)[1][1] = 5.0f;
c3.template get<P::t>(kk)[1][2] = 6.0f;
c3.template get<P::t>(kk)[2][0] = 7.0f;
c3.template get<P::t>(kk)[2][1] = 8.0f;
c3.template get<P::t>(kk)[2][2] = 9.0f;
}
}
}

Access an N-dimensional grid with an iterator

typedef Point_test<float> P;
grid_key_dx_iterator<dim> key_it = c3.getIterator();
while (key_it.isNext())
{
grid_key_dx<dim> kk = key_it.get();
c3.template get<P::x>(kk) = 1.1f;
c3.template get<P::y>(kk) = 1.2f;
c3.template get<P::z>(kk) = 1.3f;
c3.template get<P::s>(kk) = 1.0f;
c3.template get<P::v>(kk)[0] = 1.0f;
c3.template get<P::v>(kk)[1] = 2.0f;
c3.template get<P::v>(kk)[2] = 3.0f;
c3.template get<P::t>(kk)[0][0] = 1.0f;
c3.template get<P::t>(kk)[0][1] = 2.0f;
c3.template get<P::t>(kk)[0][2] = 3.0f;
c3.template get<P::t>(kk)[1][0] = 4.0f;
c3.template get<P::t>(kk)[1][1] = 5.0f;
c3.template get<P::t>(kk)[1][2] = 6.0f;
c3.template get<P::t>(kk)[2][0] = 7.0f;
c3.template get<P::t>(kk)[2][1] = 8.0f;
c3.template get<P::t>(kk)[2][2] = 9.0f;
++key_it;
}

Iterate only on a sub-set of the grid

Get the full-object in an N-dimensional grid

typedef Point_test<float> P;
grid_key_dx_iterator<dim> key_it = c3.getIterator();
while (key_it.isNext())
{
grid_key_dx<dim> kk = key_it.get();
// Here we get a reference to the object, in reality we get an encapsulated object reference encapc
auto v = c3.get_o(kk);
// An encapsulated object can be accessed like that
// (this will change the value in the grid)
v.template get<P::x>() = 1.1f;
v.template get<P::y>() = 1.2f;
v.template get<P::z>() = 1.3f;
v.template get<P::s>() = 1.0f;
v.template get<P::v>()[0] = 1.0f;
v.template get<P::v>()[1] = 2.0f;
v.template get<P::v>()[2] = 3.0f;
v.template get<P::t>()[0][0] = 1.0f;
v.template get<P::t>()[0][1] = 2.0f;
v.template get<P::t>()[0][2] = 3.0f;
v.template get<P::t>()[1][0] = 4.0f;
v.template get<P::t>()[1][1] = 5.0f;
v.template get<P::t>()[1][2] = 6.0f;
v.template get<P::t>()[2][0] = 7.0f;
v.template get<P::t>()[2][1] = 8.0f;
v.template get<P::t>()[2][2] = 9.0f;
// From an encapsulated reference object you can create
// an object
Point_test<float> obj = c3.get_o(kk);
// And do some operation
obj.fill();
// Note change obj does not change the grid
++key_it;
}

Create a grid g1 and copy into another g2

size_t sz[] = {16,16};
typedef Box<2,float> b;
g1.setMemory();
auto it = g1.getIterator();
while (it.isNext())
{
auto key = it.get();
g1.get<b::p1>(key)[0] = key.get(0);
g1.get<b::p2>(key)[1] = key.get(1);
++it;
}
g2 = g1;

Definition at line 102 of file map_grid.hpp.

#include <map_grid.hpp>

+ Inheritance diagram for grid_cpu< dim, T, S, typename memory_traits_lin< T >::type >:

Public Types

typedef memory_traits_lin< T >
::type 
layout
 type of layout of the structure
 
typedef grid_base_impl< dim, T,
S, typename memory_traits_lin
< T >::type, memory_traits_lin >
::container 
container
 Object container for T, it is the return type of get_o it return a object type trough.
 
- Public Types inherited from grid_base_impl< dim, T, S, memory_traits_lin< T >::type, memory_traits_lin >
typedef memory_traits_lin< T >
::type 
layout_type
 memory layout
 
typedef grid_key_dx< dim > access_key
 Access key.
 
typedef T::type T_type
 boost::vector that describe the data type
 
typedef int yes_i_am_grid
 it define that it is a grid
 
typedef memory_traits_lin
< typename T::type >::type 
memory_lin
 Definition of the layout.
 
typedef encapc< dim, T, layoutcontainer
 Object container for T, it is the return type of get_o it return a object type trough.
 
typedef T value_type
 The object type the grid is storing.
 

Public Member Functions

 grid_cpu () THROW
 Default constructor.
 
 grid_cpu (const grid_cpu< dim, T, S, typename memory_traits_lin< T >::type > &g) THROW
 create a grid from another grid More...
 
 grid_cpu (const size_t &sz) THROW
 create a grid of size sz on each direction More...
 
 grid_cpu (const size_t(&sz)[dim]) THROW
 Constructor allocate memory and give them a representation.
 
grid_cpu< dim, T, S, typename
memory_traits_lin< T >::type > & 
operator= (const grid_base_impl< dim, T, S, layout, memory_traits_lin > &g)
 It copy a grid. More...
 
grid_cpu< dim, T, S, typename
memory_traits_lin< T >::type > & 
operator= (grid_base_impl< dim, T, S, layout, memory_traits_lin > &&g)
 It copy a grid. More...
 
- Public Member Functions inherited from grid_base_impl< dim, T, S, memory_traits_lin< T >::type, memory_traits_lin >
void pack (ExtPreAlloc< S > &mem, Pack_stat &sts) const
 pack a grid selecting the properties to pack More...
 
void pack (ExtPreAlloc< S > &mem, grid_key_dx_iterator_sub< dims > &sub_it, Pack_stat &sts)
 Pack the object into the memory given an iterator. More...
 
void packRequest (size_t &req) const
 Insert an allocation request into the vector. More...
 
void packRequest (grid_key_dx_iterator_sub< dims > &sub, size_t &req)
 Insert an allocation request. More...
 
void unpack (ExtPreAlloc< S > &mem, Unpack_stat &ps)
 unpack a grid More...
 
void unpack (ExtPreAlloc< S > &mem, grid_key_dx_iterator_sub< dims > &sub_it, Unpack_stat &ps)
 unpack the sub-grid object More...
 
 grid_base_impl () THROW
 Default constructor.
 
 grid_base_impl (const grid_base_impl &g) THROW
 create a grid from another grid More...
 
 grid_base_impl (const size_t &sz) THROW
 create a grid of size sz on each direction More...
 
 grid_base_impl (const size_t(&sz)[dim]) THROW
 Constructor. More...
 
 ~grid_base_impl () THROW
 Destructor.
 
grid_base_impl< dim, T, S,
layout, memory_traits_lin > & 
operator= (const grid_base_impl< dim, T, S, layout, memory_traits_lin > &g)
 It copy a grid. More...
 
grid_base_impl< dim, T, S,
layout, memory_traits_lin > & 
operator= (grid_base_impl< dim, T, S, layout, memory_traits_lin > &&g)
 It copy a grid. More...
 
bool operator== (const grid_base_impl< dim, T, S, layout, memory_traits_lin > &g)
 Compare two grids. More...
 
grid_base_impl< dim, T, S,
layout, memory_traits_lin
duplicate () const THROW
 create a duplicated version of the grid More...
 
const grid_sm< dim, T > & getGrid () const
 Return the internal grid information. More...
 
void setMemory ()
 Create the object that provide memory. More...
 
void setMemory (S &m)
 Get the object that provide memory. More...
 
void * getPointer ()
 Return a plain pointer to the internal data. More...
 
const void * getPointer () const
 Return a plain pointer to the internal data. More...
 
r_type get (const grid_key_dx< dim > &v1)
 Get the reference of the selected element. More...
 
const r_type get (const grid_key_dx< dim > &v1) const
 Get the const reference of the selected element. More...
 
r_type get (const size_t lin_id)
 Get the reference of the selected element. More...
 
const r_type get (size_t lin_id) const
 Get the const reference of the selected element. More...
 
encapc< dim, T, layoutget_o (const grid_key_dx< dim > &v1)
 Get the of the selected element as a boost::fusion::vector. More...
 
const encapc< dim, T, layoutget_o (const grid_key_dx< dim > &v1) const
 Get the of the selected element as a boost::fusion::vector. More...
 
encapc< dim, T, layoutget_o (size_t v1)
 Get the of the selected element as a boost::fusion::vector. More...
 
const encapc< dim, T, layoutget_o (size_t v1) const
 Get the of the selected element as a boost::fusion::vector. More...
 
void fill (unsigned char fl)
 Fill the memory with the selected byte. More...
 
void resize (const size_t(&sz)[dim])
 Resize the space. More...
 
void remove (size_t key)
 Remove one element valid only on 1D. More...
 
void swap (grid_base_impl< dim, T, S, layout, memory_traits_lin > &grid)
 It move the allocated object from one grid to another. More...
 
void swap (grid_base_impl< dim, T, S, layout, memory_traits_lin > &&grid)
 It move the allocated object from one grid to another. More...
 
void set (grid_key_dx< dim > dx, const encapc< 1, T, Memory > &obj)
 set an element of the grid More...
 
void set (grid_key_dx< dim > dx, const T &obj)
 set an element of the grid More...
 
void set (const grid_key_dx< dim > &key1, const grid_base_impl< dim, T, S, layout, memory_traits_lin > &g, const grid_key_dx< dim > &key2)
 Set an element of the grid from another element of another grid. More...
 
void set (const size_t key1, const grid_base_impl< dim, T, S, layout, memory_traits_lin > &g, const size_t key2)
 Set an element of the grid from another element of another grid. More...
 
void set (const grid_key_dx< dim > &key1, const grid_base_impl< dim, T, Mem, layout, memory_traits_lin > &g, const grid_key_dx< dim > &key2)
 Set an element of the grid from another element of another grid. More...
 
size_t size () const
 return the size of the grid More...
 
grid_key_dx_iterator_sub< dim > getSubIterator (grid_key_dx< dim > &start, grid_key_dx< dim > &stop) const
 Return a sub-grid iterator. More...
 
grid_key_dx_iterator_sub< dim > getSubIterator (size_t m)
 Return a sub-grid iterator. More...
 
grid_key_dx_iterator< dim > getIterator () const
 Return a grid iterator. More...
 
grid_key_dx_iterator_sub< dim > getIterator (const grid_key_dx< dim > &start, const grid_key_dx< dim > &stop) const
 Return a grid iterator over all points included between start and stop point. More...
 
grid_key_dx_iterator< dim,
stencil_offset_compute< dim,
Np > > 
getIteratorStencil (const grid_key_dx< dim >(&stencil_pnt)[Np]) const
 Return a grid iterator. More...
 
long int who ()
 It return the id of structure in the allocation list. More...
 

Static Public Member Functions

static bool noPointers ()
 This structure has pointers. More...
 
- Static Public Member Functions inherited from grid_base_impl< dim, T, S, memory_traits_lin< T >::type, memory_traits_lin >
static bool pack ()
 
static bool packRequest ()
 
static bool packMem ()
 
static size_t packMem (size_t n, size_t e)
 Calculate the memory size required to pack n elements. More...
 

Additional Inherited Members

- Static Public Attributes inherited from grid_base_impl< dim, T, S, memory_traits_lin< T >::type, memory_traits_lin >
static constexpr unsigned int dims
 expose the dimansionality as a static const
 
- Protected Attributes inherited from grid_base_impl< dim, T, S, memory_traits_lin< T >::type, memory_traits_lin >
layout data_
 Memory layout specification + memory chunk pointer.
 
grid_sm< dim, T > g1
 This is a structure that store all information related to the grid and how indexes are linearized.
 

Constructor & Destructor Documentation

template<unsigned int dim, typename T , typename S >
grid_cpu< dim, T, S, typename memory_traits_lin< T >::type >::grid_cpu ( const grid_cpu< dim, T, S, typename memory_traits_lin< T >::type > &  g)
inline

create a grid from another grid

Template Parameters
Smemory type for allocation
Parameters
gthe grid to copy
memmemory object (only used for template deduction)

Definition at line 128 of file map_grid.hpp.

template<unsigned int dim, typename T , typename S >
grid_cpu< dim, T, S, typename memory_traits_lin< T >::type >::grid_cpu ( const size_t &  sz)
inline

create a grid of size sz on each direction

Template Parameters
Smemory type for allocation
Parameters
szsize if the grid on each directions

Definition at line 140 of file map_grid.hpp.

Member Function Documentation

template<unsigned int dim, typename T , typename S >
static bool grid_cpu< dim, T, S, typename memory_traits_lin< T >::type >::noPointers ( )
inlinestatic

This structure has pointers.

Returns
false

Definition at line 180 of file map_grid.hpp.

template<unsigned int dim, typename T , typename S >
grid_cpu<dim,T,S,typename memory_traits_lin<T>::type>& grid_cpu< dim, T, S, typename memory_traits_lin< T >::type >::operator= ( const grid_base_impl< dim, T, S, layout, memory_traits_lin > &  g)
inline

It copy a grid.

Parameters
ggrid to copy

Definition at line 156 of file map_grid.hpp.

template<unsigned int dim, typename T , typename S >
grid_cpu<dim,T,S,typename memory_traits_lin<T>::type>& grid_cpu< dim, T, S, typename memory_traits_lin< T >::type >::operator= ( grid_base_impl< dim, T, S, layout, memory_traits_lin > &&  g)
inline

It copy a grid.

Parameters
ggrid to copy

Definition at line 168 of file map_grid.hpp.


The documentation for this class was generated from the following file: