OpenFPM_data  0.1.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Namespaces Functions Variables Typedefs Friends
openfpm Namespace Reference

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

Data Structures

class  vector
 Implementation of 1-D std::vector like structure. More...
 
class  vector_key_iterator
 Vector iterator. More...
 
class  vector< T, HeapMemory, grow_policy_double, STD_VECTOR >
 Implementation of 1-D std::vector like structure. More...
 
class  vector< T, Memory, grow_p, OPENFPM_NATIVE >
 Implementation of 1-D std::vector like structure. More...
 
class  grow_policy_identity
 Grow policy define how the vector should grow every time we exceed the size. More...
 
class  grow_policy_double
 Grow policy define how the vector should grow every time we exceed the size. More...
 
class  grow_policy_page
 Grow policy define how the vector should grow every time we exceed the size. More...
 
struct  vect_isel
 

Typedefs

template<typename T >
using vector_std = vector< T, HeapMemory, openfpm::grow_policy_double, STD_VECTOR >
 
typedef grow_policy_double vector_grow_policy_default
 default grow policy
 

Detailed Description

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

It analyze the type given and it select correctly the implementation for vector.

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
Memmemory 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

// Subdivisions
size_t div[3] = {16,16,16};
// grid info
grid_sm<3,void> g_info(div);
grid_key_dx<3> start(1,1,1);
grid_key_dx<3> stop(14,14,14);
// Create a grid iterator (start and stop included)
grid_key_dx_iterator_sub<3> g_it(g_info,start,stop);
// Iterate on all the elements
while (g_it.isNext())
{
grid_key_dx<3> key = g_it.get();
// set the grid key to zero without any reason ( to avoid warning compilations )
key.zero();
count++;
++g_it;
}
BOOST_REQUIRE_EQUAL(count, (size_t)14*14*14);

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.template get<b::p1>(key)[0] = key.get(0);
g1.template get<b::p2>(key)[1] = key.get(1);
++it;
}
g2 = g1;
Template Parameters
typeto analyze

[Example]

vect_isel<T>::value

will return 1 for std base implementation will return 2 for openfpm native implementation

Basically the openfpm native implementation require that T has some specific structure, this class check for it, if T does not have this structure it fall to the case 1