OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer > Class Template Reference

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

Detailed Description

template<unsigned int dim, typename T, typename S, typename linearizer>
class grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >

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

it is basically an N-dimensional Cartesian grid

Template Parameters
dimDimensionality of the grid
Ttype of object the grid store
Memmemory layout

Definition and allocation of a 3D grid on GPU memory

c3.setMemory();

Access a grid c3 of size sz on each direction

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;
}
}
}
Test structure used for several test.
grid_key_dx is the key to access any element in the grid
Definition grid_key.hpp:19
__device__ __host__ void set(a v, T...t)
set the Key from a list of numbers
Definition grid_key.hpp:400
Class for cpu time benchmarking.
Definition timer.hpp:28
void start()
Start the timer.
Definition timer.hpp:90

Access to an N-dimensional grid with an iterator

Definition at line 502 of file map_grid.hpp.

#include <map_grid.hpp>

+ Inheritance diagram for grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >:

Public Types

typedef memory_traits_inte< T >::type layout
 grid layout
 
typedef grid_base_impl< dim, T, S, memory_traits_inte, linearizer >::container container
 Object container for T, it is the return type of get_o it return a object type trough.
 
typedef grid_base_impl< dim, T, S, memory_traits_inte, linearizer >::linearizer_type linearizer_type
 linearizer type Z-morton Hilbert curve , normal striding
 
- Public Types inherited from grid_base_impl< dim, T, S, memory_traits_inte, linearizer >
typedef layout 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 memory_traits_inte< T > layout_base_
 base layout type
 
typedef linearizer linearizer_type
 
typedef T background_type
 
typedef int yes_i_am_grid
 it define that this data-structure is a grid
 
typedef memory_traits_lin< typenameT::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_base () THROW
 Default constructor.
 
 grid_base (const grid_base &g) THROW
 create a grid from another grid
 
 grid_base (grid_base &&g) THROW
 create a grid from another grid
 
 grid_base (const size_t &sz) THROW
 create a grid of size sz on each direction
 
 grid_base (const size_t(&sz)[dim]) THROW
 Constructor allocate memory and give them a representation.
 
template<unsigned int id>
void fill (unsigned char c)
 Fill the memory with a byte.
 
template<unsigned int id>
void * getDeviceBuffer ()
 It return the properties arrays.
 
void convert_key (grid_key_dx< dim > &key_out, const grid_key_dx< dim > &key_in) const
 In this case it just copy the key_in in key_out.
 
T & getBackgroundValue ()
 Get the background value.
 
T & getBackgroundValueAggr ()
 Get the background value.
 
grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer > & operator= (const grid_base_impl< dim, T, S, memory_traits_inte, linearizer > &base)
 assign operator
 
grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer > & operator= (grid_base_impl< dim, T, S, memory_traits_inte, linearizer > &&base)
 assign operator
 
- Public Member Functions inherited from grid_base_impl< dim, T, S, memory_traits_inte, linearizer >
 grid_base_impl () THROW
 Default constructor.
 
 grid_base_impl (const grid_base_impl &g) THROW
 create a grid from another grid
 
 grid_base_impl (const size_t &sz) THROW
 create a grid of size sz on each direction
 
 grid_base_impl (const size_t(&sz)[dim]) THROW
 Constructor.
 
 ~grid_base_impl () THROW
 Destructor.
 
grid_base_impl< dim, T, S, memory_traits_inte > & operator= (const grid_base_impl< dim, T, S, memory_traits_inte > &g)
 It copy a grid.
 
grid_base_impl< dim, T, S, memory_traits_inte > & operator= (grid_base_impl< dim, T, S, memory_traits_inte > &&g)
 It copy a grid.
 
bool operator== (const grid_base_impl< dim, T, S, memory_traits_inte > &g)
 Compare two grids.
 
grid_base_impl< dim, T, S, memory_traits_inteduplicate () const THROW
 create a duplicated version of the grid
 
int size (int i) const
 Get the size if the grid in the direction i.
 
size_t size () const
 return the size of the grid
 
const linearizer & getGrid () const
 Return the internal grid information.
 
void setMemory ()
 Create the object that provide memory.
 
void setMemory (S &m)
 Set the object that provide memory from outside.
 
auto getMemory () -> decltype(boost::fusion::at_c< p >(data_).getMemory())
 Return the memory object.
 
void setMemoryArray (S *m)
 Set the object that provide memory from outside.
 
void * getPointer ()
 Return a plain pointer to the internal data.
 
const void * getPointer () const
 Return a plain pointer to the internal data.
 
r_type insert (const grid_key_dx< dim > &v1)
 In this case insert is equivalent to get.
 
__device__ __host__ r_type get_usafe (const grid_key_dx< dim > &v1)
 Get the reference of the selected element.
 
int getBlockEdgeSize ()
 No blocks here, it return 1.
 
void setGPUInsertBuffer (unsigned int nb, unsigned int nt)
 No blocks here, it does nothing.
 
__device__ __host__ r_type get_unsafe (const grid_key_dx< dim > &v1) const
 Get the const reference of the selected element.
 
__device__ __host__ r_type get (const grid_key_dx< dim > &v1)
 Get the reference of the selected element.
 
__device__ __host__ r_type get (const grid_key_dx< dim > &v1) const
 Get the const reference of the selected element.
 
__device__ __host__ r_type get (const size_t lin_id)
 Get the reference of the selected element.
 
__device__ __host__ const r_type get (size_t lin_id) const
 Get the const reference of the selected element.
 
__device__ __host__ unsigned char getFlag (const grid_key_dx< dim > &v1) const
 Get the point flag (in this case just return 0)
 
encapc< dim, T, layoutget_o (const grid_key_dx< dim > &v1)
 Get the of the selected element as a boost::fusion::vector.
 
const encapc< dim, T, layoutget_o (const grid_key_dx< dim > &v1) const
 Get the of the selected element as a boost::fusion::vector.
 
encapc< dim, T, layoutget_o (size_t v1)
 Get the of the selected element as a boost::fusion::vector.
 
const encapc< dim, T, layoutget_o (size_t v1) const
 Get the of the selected element as a boost::fusion::vector.
 
encapc< dim, T, layoutinsert_o (const grid_key_dx< dim > &v1)
 Get the of the selected element as a boost::fusion::vector.
 
void fill (unsigned char fl)
 Fill the memory with the selected byte.
 
void remove (Box< dim, long int > &section_to_delete)
 Remove all the points in this region.
 
void remove (size_t key)
 Remove one element valid only on 1D.
 
void copyRemoveReset ()
 Reset the queue to remove and copy section of grids.
 
bool isSkipLabellingPossible ()
 This function check if keep geometry is possible for this grid.
 
void copy_to (const grid_base_impl< dim, T, S, memory_traits_inte > &grid_src, const Box< dim, long int > &box_src, const Box< dim, long int > &box_dst)
 copy an external grid into a specific place into this grid
 
void copy_to_prp (const grid_base_impl< dim, T, S, memory_traits_inte > &grid_src, const Box< dim, size_t > &box_src, const Box< dim, size_t > &box_dst)
 copy an external grid into a specific place into this grid
 
void clear ()
 It does nothing.
 
void copy_to_op (const grid_base_impl< dim, T, S, memory_traits_inte > &gs, const Box< dim, size_t > &bx_src, const Box< dim, size_t > &bx_dst)
 copy an external grid into a specific place into this grid
 
void resize (const size_t(&sz)[dim], size_t opt=DATA_ON_HOST|DATA_ON_DEVICE, unsigned int blockSize=1)
 Resize the grid.
 
void resize_no_device (const size_t(&sz)[dim])
 Resize the space.
 
void swap_nomode (grid_base_impl< dim, T, S, memory_traits_inte > &grid)
 It swap the objects A become B and B become A using A.swap(B);.
 
void swap (grid_base_impl< dim, T, S, memory_traits_inte, linearizer > &grid)
 It swap the objects A become B and B become A using A.swap(B);.
 
void swap (grid_base_impl< dim, T, S, memory_traits_inte > &&grid)
 It move the allocated object from one grid to another.
 
__device__ __host__ void set (const grid_key_dx< dim > &key1, const grid_base_impl &g, const grid_key_dx< dim > &key2)
 set only some properties
 
void set (grid_key_dx< dim > dx, const encapc< 1, T, Memory > &obj)
 set an element of the grid
 
void set (grid_key_dx< dim > dx, const T &obj)
 set an element of the grid
 
void set (const grid_key_dx< dim > &key1, const grid_base_impl< dim, T, S, memory_traits_inte > &g, const grid_key_dx< dim > &key2)
 Set an element of the grid from another element of another grid.
 
void set (const size_t key1, const grid_base_impl< dim, T, S, memory_traits_inte > &g, const size_t key2)
 Set an element of the grid from another element of another grid.
 
void set (const grid_key_dx< dim > &key1, const grid_base_impl< dim, T, Mem, memory_traits_inte > &g, const grid_key_dx< dim > &key2)
 Set an element of the grid from another element of another grid.
 
void set_general (const grid_key_dx< dim > &key1, const grid_base_impl< dim, T, Mem, layout_base2 > &g, const grid_key_dx< dim > &key2)
 Set an element of the grid from another element of another grid.
 
grid_key_dx_iterator_sub< dim > getSubIterator (const grid_key_dx< dim > &start, const grid_key_dx< dim > &stop) const
 Return a sub-grid iterator.
 
grid_key_dx_iterator_sub< dim > getSubIterator (size_t m)
 Return a sub-grid iterator.
 
grid_key_dx_iterator< dim > getIterator () const
 Return a grid iterator.
 
grid_key_dx_iterator_sub< dim > getIterator (const grid_key_dx< dim > &start, const grid_key_dx< dim > &stop, bool to_init=false) const
 Return a grid iterator over all points included between start and stop point.
 
void deviceToHost ()
 Synchronize the memory buffer in the device with the memory in the host.
 
void deviceToHost (size_t start, size_t stop)
 Synchronize the memory buffer in the device with the memory in the host.
 
void hostToDeviceNUMA (size_t start, size_t stop)
 Synchronize the memory buffer in the device with the memory in the host (respecting the NUMA domains)
 
void hostToDeviceNUMA ()
 Synchronize the memory buffer in the device with the memory in the host (respecting the NUMA domains)
 
void hostToDevice (size_t start, size_t stop)
 Synchronize the memory buffer in the device with the memory in the host.
 
void hostToDevice ()
 Copy the memory from host to device.
 
grid_gpu_ker< dim, T_, memory_traits_inte, linearizer_type > toKernel ()
 Convert the grid into a data-structure compatible for computing into GPU.
 
const grid_gpu_ker< dim, T_, memory_traits_inte, linearizer_type > toKernel () const
 Convert the grid into a data-structure compatible for computing into GPU.
 
grid_key_dx_iterator< dim, stencil_offset_compute< dim, Np > > getIteratorStencil (const grid_key_dx< dim >(&stencil_pnt)[Np]) const
 Return a grid iterator.
 
layoutget_internal_data_ ()
 return the internal data_
 
const layoutget_internal_data_ () const
 return the internal data_
 
void removeAddUnpackReset ()
 In this case it does nothing.
 
void removeAddUnpackFinalize (const context_type &ctx, int opt)
 In this case it does nothing.
 
void removeCopyToFinalize (const context_type &ctx, int opt)
 In this case it does nothing.
 
void resetFlush ()
 It does nothing.
 

Static Public Member Functions

static void unpack_headers ()
 Stub does not do anything.
 
template<typename stencil = no_stencil>
static grid_key_dx_iterator_sub< dim, stencil > type_of_subiterator ()
 This is a meta-function return which type of sub iterator a grid produce.
 
static constexpr bool isCompressed ()
 Return if in this representation data are stored is a compressed way.
 
static grid_key_dx_iterator< dim > type_of_iterator ()
 This is a meta-function return which type of iterator a grid produce.
 
- Static Public Member Functions inherited from grid_base_impl< dim, T, S, memory_traits_inte, linearizer >
static bool is_unpack_header_supported ()
 Indicate that unpacking the header is supported.
 

Private Types

typedef apply_transform< memory_traits_inte, T >::type T_
 

Private Attributes

background
 

Additional Inherited Members

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

Member Typedef Documentation

◆ container

template<unsigned int dim, typename T , typename S , typename linearizer >
typedef grid_base_impl<dim,T,S,memory_traits_inte,linearizer>::container grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >::container

Object container for T, it is the return type of get_o it return a object type trough.

Definition at line 515 of file map_grid.hpp.

◆ layout

template<unsigned int dim, typename T , typename S , typename linearizer >
typedef memory_traits_inte<T>::type grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >::layout

grid layout

Definition at line 511 of file map_grid.hpp.

◆ linearizer_type

template<unsigned int dim, typename T , typename S , typename linearizer >
typedef grid_base_impl<dim,T,S,memory_traits_inte,linearizer>::linearizer_type grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >::linearizer_type

linearizer type Z-morton Hilbert curve , normal striding

Definition at line 518 of file map_grid.hpp.

◆ T_

template<unsigned int dim, typename T , typename S , typename linearizer >
typedef apply_transform<memory_traits_inte,T>::type grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >::T_
private

Definition at line 504 of file map_grid.hpp.

Constructor & Destructor Documentation

◆ grid_base() [1/5]

template<unsigned int dim, typename T , typename S , typename linearizer >
grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >::grid_base ( )
inline

Default constructor.

Definition at line 521 of file map_grid.hpp.

◆ grid_base() [2/5]

template<unsigned int dim, typename T , typename S , typename linearizer >
grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >::grid_base ( const grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer > &  g)
inline

create a grid from another grid

Parameters
gthe grid to copy

Definition at line 531 of file map_grid.hpp.

◆ grid_base() [3/5]

template<unsigned int dim, typename T , typename S , typename linearizer >
grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >::grid_base ( grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer > &&  g)
inline

create a grid from another grid

Parameters
gthe grid to copy

Definition at line 541 of file map_grid.hpp.

◆ grid_base() [4/5]

template<unsigned int dim, typename T , typename S , typename linearizer >
grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >::grid_base ( const size_t &  sz)
inline

create a grid of size sz on each direction

Parameters
szgrid size in each direction

Definition at line 551 of file map_grid.hpp.

◆ grid_base() [5/5]

template<unsigned int dim, typename T , typename S , typename linearizer >
grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >::grid_base ( const size_t(&)  sz[dim])
inline

Constructor allocate memory and give them a representation.

Definition at line 557 of file map_grid.hpp.

◆ ~grid_base()

template<unsigned int dim, typename T , typename S , typename linearizer >
grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >::~grid_base ( )
inline

Definition at line 679 of file map_grid.hpp.

Member Function Documentation

◆ convert_key()

template<unsigned int dim, typename T , typename S , typename linearizer >
void grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >::convert_key ( grid_key_dx< dim > &  key_out,
const grid_key_dx< dim > &  key_in 
) const
inline

In this case it just copy the key_in in key_out.

Parameters
key_outoutput key
key_ininput key

Definition at line 625 of file map_grid.hpp.

◆ fill()

template<unsigned int dim, typename T , typename S , typename linearizer >
template<unsigned int id>
void grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >::fill ( unsigned char  c)
inline

Fill the memory with a byte.

Definition at line 571 of file map_grid.hpp.

◆ getBackgroundValue()

template<unsigned int dim, typename T , typename S , typename linearizer >
T & grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >::getBackgroundValue ( )
inline

Get the background value.

For dense grid this function is useless

Returns
background value

Definition at line 638 of file map_grid.hpp.

◆ getBackgroundValueAggr()

template<unsigned int dim, typename T , typename S , typename linearizer >
T & grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >::getBackgroundValueAggr ( )
inline

Get the background value.

For dense grid this function is useless

Returns
background value

Definition at line 650 of file map_grid.hpp.

◆ getDeviceBuffer()

template<unsigned int dim, typename T , typename S , typename linearizer >
template<unsigned int id>
void * grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >::getDeviceBuffer ( )
inline

It return the properties arrays.

In case of Cuda memory it return the device pointers to pass to the kernels

This variant does not copy the host memory to the device memory

Definition at line 583 of file map_grid.hpp.

◆ isCompressed()

template<unsigned int dim, typename T , typename S , typename linearizer >
static constexpr bool grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >::isCompressed ( )
inlinestaticconstexpr

Return if in this representation data are stored is a compressed way.

Returns
false this is a normal grid no compression

Definition at line 604 of file map_grid.hpp.

◆ operator=() [1/2]

template<unsigned int dim, typename T , typename S , typename linearizer >
grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer > & grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >::operator= ( const grid_base_impl< dim, T, S, memory_traits_inte, linearizer > &  base)
inline

assign operator

Returns
itself

Definition at line 660 of file map_grid.hpp.

◆ operator=() [2/2]

template<unsigned int dim, typename T , typename S , typename linearizer >
grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer > & grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >::operator= ( grid_base_impl< dim, T, S, memory_traits_inte, linearizer > &&  base)
inline

assign operator

Returns
itself

Definition at line 672 of file map_grid.hpp.

◆ type_of_iterator()

template<unsigned int dim, typename T , typename S , typename linearizer >
static grid_key_dx_iterator< dim > grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >::type_of_iterator ( )
inlinestatic

This is a meta-function return which type of iterator a grid produce.

Returns
the type of the sub-grid iterator

Definition at line 614 of file map_grid.hpp.

◆ type_of_subiterator()

template<unsigned int dim, typename T , typename S , typename linearizer >
template<typename stencil = no_stencil>
static grid_key_dx_iterator_sub< dim, stencil > grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >::type_of_subiterator ( )
inlinestatic

This is a meta-function return which type of sub iterator a grid produce.

Returns
the type of the sub-grid iterator

Definition at line 594 of file map_grid.hpp.

◆ unpack_headers()

template<unsigned int dim, typename T , typename S , typename linearizer >
static void grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >::unpack_headers ( )
inlinestatic

Stub does not do anything.

Definition at line 565 of file map_grid.hpp.

Field Documentation

◆ background

template<unsigned int dim, typename T , typename S , typename linearizer >
T grid_base< dim, T, S, typename memory_traits_inte< T >::type, linearizer >::background
private

Definition at line 506 of file map_grid.hpp.


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