Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Sbalzarini Lab
S
Software
P
Parallel Computing
OpenFPM
openfpm_data
Commits
dbfb2ecf
Commit
dbfb2ecf
authored
Jun 29, 2017
by
Pietro Incardona
Browse files
Adding stencil iterator
parent
dfaf8538
Changes
15
Hide whitespace changes
Inline
Side-by-side
src/Grid/grid_base_impl_layout.hpp
View file @
dbfb2ecf
...
...
@@ -77,6 +77,11 @@ struct mem_get
{
return
boost
::
fusion
::
at_c
<
p
>
(
data_
.
mem_r
->
operator
[](
g1
.
LinId
(
v1
)));
}
static
inline
auto
get_lin
(
const
data_type
&
data_
,
const
g1_type
&
g1
,
const
size_t
lin_id
)
->
decltype
(
boost
::
fusion
::
at_c
<
p
>
(
data_
.
mem_r
->
operator
[](
lin_id
)))
&
{
return
boost
::
fusion
::
at_c
<
p
>
(
data_
.
mem_r
->
operator
[](
lin_id
));
}
};
//! Case memory_traits_inte
...
...
@@ -87,6 +92,11 @@ struct mem_get<p,layout,data_type,g1_type,key_type,1>
{
return
boost
::
fusion
::
at_c
<
p
>
(
data_
).
mem_r
->
operator
[](
g1
.
LinId
(
v1
));
}
static
inline
auto
get_lin
(
const
data_type
&
data_
,
const
g1_type
&
g1
,
size_t
lin_id
)
->
decltype
(
boost
::
fusion
::
at_c
<
p
>
(
data_
).
mem_r
->
operator
[](
lin_id
))
{
return
boost
::
fusion
::
at_c
<
p
>
(
data_
).
mem_r
->
operator
[](
lin_id
);
}
};
...
...
src/Grid/grid_base_implementation.hpp
View file @
dbfb2ecf
...
...
@@ -18,7 +18,7 @@
* \tparam T type store by the grid
* \tparam S Memory pool from where to take the memory
* \tparam layout_ memory layout
* \tpa
e
am layout_base layout memory meta-function (the meta-function used to construct layout_)
* \tpa
r
am layout_base layout memory meta-function (the meta-function used to construct layout_)
*
*/
template
<
unsigned
int
dim
,
typename
T
,
typename
S
,
typename
layout_
,
template
<
typename
>
class
layout_base
>
...
...
@@ -175,7 +175,13 @@ public:
#endif
}
//! Constructor allocate memory and give them a representation
/*! \brief Constructor
*
* It construct a grid of specified size
*
* \param sz array that indicate the size of the grid in each dimension
*
*/
grid_base_impl
(
const
size_t
(
&
sz
)[
dim
])
THROW
:
g1
(
sz
),
isExternal
(
false
)
{
...
...
@@ -198,6 +204,8 @@ public:
*
* \param g grid to copy
*
* \return itself
*
*/
grid_base_impl
<
dim
,
T
,
S
,
layout
,
layout_base
>
&
operator
=
(
const
grid_base_impl
<
dim
,
T
,
S
,
layout
,
layout_base
>
&
g
)
{
...
...
@@ -438,12 +446,55 @@ public:
return
mem_get
<
p
,
layout_base
<
T
>
,
decltype
(
this
->
data_
),
decltype
(
this
->
g1
),
decltype
(
v1
)
>::
get
(
data_
,
g1
,
v1
);
}
/*! \brief Get the reference of the selected element
*
* \param lin_id linearized element that identify the element in the grid
*
* \return the reference of the element
*
*/
template
<
unsigned
int
p
,
typename
r_type
=
decltype
(
mem_get
<
p
,
layout_base
<
T
>,
layout
,
grid_sm
<
dim
,
T
>
,
grid_key_dx
<
dim
>>::
get_lin
(
data_
,
g1
,
0
))
>
inline
r_type
get
(
const
size_t
lin_id
)
{
#ifdef SE_CLASS2
check_valid
(
this
,
8
);
#endif
#ifdef SE_CLASS1
check_init
();
check_bound
(
lin_id
);
#endif
return
mem_get
<
p
,
layout_base
<
T
>
,
decltype
(
this
->
data_
),
decltype
(
this
->
g1
),
grid_key_dx
<
dim
>>::
get_lin
(
data_
,
g1
,
lin_id
);
}
/*! \brief Get the const reference of the selected element
*
* \param lin_id linearized element that identify the element in the grid
*
* \return the const reference of the element
*
*/
template
<
unsigned
int
p
,
typename
r_type
=
decltype
(
mem_get
<
p
,
layout_base
<
T
>,
layout
,
grid_sm
<
dim
,
T
>
,
grid_key_dx
<
dim
>>::
get_lin
(
data_
,
g1
,
0
))
>
inline
const
r_type
get
(
size_t
lin_id
)
const
{
#ifdef SE_CLASS2
check_valid
(
this
,
8
);
#endif
#ifdef SE_CLASS1
check_init
();
check_bound
(
lin_id
);
#endif
return
mem_get
<
p
,
layout_base
<
T
>
,
decltype
(
this
->
data_
),
decltype
(
this
->
g1
),
grid_key_dx
<
dim
>>::
get_lin
(
data_
,
g1
,
lin_id
);
}
/*! \brief Get the of the selected element as a boost::fusion::vector
*
* Get the selected element as a boost::fusion::vector
*
* \param v1 grid_key that identify the element in the grid
*
* \see encap_c
*
* \return an encap_c that is the representation of the object (careful is not the object)
*
*/
inline
encapc
<
dim
,
T
,
layout
>
get_o
(
const
grid_key_dx
<
dim
>
&
v1
)
{
...
...
@@ -463,6 +514,10 @@ public:
*
* \param v1 grid_key that identify the element in the grid
*
* \see encap_c
*
* \return an encap_c that is the representation of the object (careful is not the object)
*
*/
inline
const
encapc
<
dim
,
T
,
layout
>
get_o
(
const
grid_key_dx
<
dim
>
&
v1
)
const
{
...
...
@@ -564,6 +619,7 @@ public:
/*! \brief Remove one element valid only on 1D
*
* \param key element to remove
*
*/
void
remove
(
size_t
key
)
...
...
@@ -599,8 +655,6 @@ public:
#ifdef SE_CLASS2
check_valid
(
this
,
8
);
#endif
// move the data
// data_.swap(grid.data_);
mem_swap
<
T
,
layout_base
<
T
>
,
decltype
(
data_
),
decltype
(
grid
)
>::
swap
(
data_
,
grid
.
data_
);
...
...
@@ -730,7 +784,7 @@ public:
/*! \brief return the size of the grid
*
* Return the size of the grid
*
\return
Return the size of the grid
*
*/
inline
size_t
size
()
const
...
...
@@ -791,12 +845,14 @@ public:
return
grid_key_dx_iterator
<
dim
>
(
g1
);
}
/*! \brief Return a grid iterator over all the point with the exception
* of the ghost part
/*! \brief Return a grid iterator over all points included between start and stop point
*
* Return a grid iterator over all the point with the exception of the
* ghost part
*
* \param start point
* \param stop point
*
* \return a sub-grid iterator
*
*/
...
...
@@ -810,43 +866,13 @@ public:
return
grid_key_dx_iterator_sub
<
dim
>
(
g1
,
start
,
stop
);
}
/*! \brief Return the size of the message needed to pack this object
*
* TODO They just return 0 for now
*
* \return The size of the object to pack this object
*
*
*/
size_t
packObjectSize
()
{
#ifdef SE_CLASS2
check_valid
(
this
,
8
);
#endif
return
0
;
}
/*! \brief It fill the message packet
*
* TODO They just return 0 doing nothing
*
* \return The packet size
*
*
*/
size_t
packObject
(
void
*
mem
)
{
#ifdef SE_CLASS2
check_valid
(
this
,
8
);
#endif
return
0
;
}
/* \brief It return the id of structure in the allocation list
/*
!
\brief It return the id of structure in the allocation list
*
* \see print_alloc and SE_CLASS2
*
* \return the id
*
*/
long
int
who
()
{
...
...
src/Grid/grid_key.hpp
View file @
dbfb2ecf
...
...
@@ -19,7 +19,11 @@ class grid_key_dx
{
public:
// Constructor from expression
/*! \brief Constructor from expression
*
* \param exp grid_key_dx expression
*
*/
template
<
typename
exp1
>
inline
grid_key_dx
(
const
grid_key_dx_expression
<
dim
,
exp1
>
&
exp
)
{
for
(
size_t
i
=
0
;
i
<
dim
;
i
++
)
...
...
@@ -30,7 +34,11 @@ public:
inline
grid_key_dx
()
{}
//! Constructor from initializer list
/*! \brief Constructor from initializer list
*
* \param p1 initializer list
*
*/
inline
grid_key_dx
(
std
::
initializer_list
<
long
int
>
p1
)
{
size_t
i
=
0
;
...
...
@@ -43,34 +51,55 @@ public:
}
}
//! Constructor from an other key
/*! \brief Constructor from an other key
*
* \param key copy constructor
*
*/
inline
grid_key_dx
(
const
grid_key_dx
<
dim
>
&
key
)
:
grid_key_dx
(
key
.
k
)
{
}
//! Constructor from buffer reference
/*! \brief Constructor from buffer reference
*
* \param k reference buffer
*
*/
inline
grid_key_dx
(
const
size_t
(
&
k
)[
dim
])
{
for
(
size_t
i
=
0
;
i
<
dim
;
i
++
)
this
->
k
[
i
]
=
k
[
i
];
}
//! Constructor from buffer reference
/*! \brief Constructor from buffer reference
*
* \param k reference buffer
*
*/
inline
grid_key_dx
(
const
long
int
(
&
k
)[
dim
])
{
for
(
size_t
i
=
0
;
i
<
dim
;
i
++
)
this
->
k
[
i
]
=
k
[
i
];
}
//! Construct a grid key from a list of numbers
/*! \brief Construct a grid key from a list of numbers
*
* \param cmb combination
*
*/
template
<
typename
...
T
>
inline
grid_key_dx
(
const
comb
<
dim
>
&
cmb
)
{
for
(
size_t
i
=
0
;
i
<
dim
;
i
++
)
k
[
i
]
=
cmb
[
i
];
}
//! Construct a grid key from a list of numbers
/*! \brief Construct a grid key from a list of numbers
*
* \param v number
* \param t the other numbers
*
*/
template
<
typename
...
T
>
inline
grid_key_dx
(
const
size_t
v
,
const
T
...
t
)
{
#ifdef DEBUG
...
...
@@ -81,7 +110,7 @@ public:
invert_assign
(
t
...);
}
/* \brief Set to zero the key
/*
!
\brief Set to zero the key
*
*/
inline
void
zero
()
...
...
@@ -90,7 +119,7 @@ public:
k
[
i
]
=
0
;
}
/* \brief Set to one the key
/*
!
\brief Set to one the key
*
*/
inline
void
one
()
...
...
@@ -99,7 +128,7 @@ public:
k
[
i
]
=
1
;
}
/* \brief Set to invalid the key
/*
!
\brief Set to invalid the key
*
*/
inline
void
invalid
()
...
...
@@ -108,7 +137,7 @@ public:
k
[
i
]
=
-
1
;
}
/* \brief Check if the key is invalid (all components set to -1)
/*
!
\brief Check if the key is invalid (all components set to -1)
*
* \return true if it is valid
*
...
...
@@ -124,9 +153,9 @@ public:
return
false
;
}
/* \brief sum a grid_key
/*
!
\brief sum a grid_key
*
* \param comb combination (or relative movement)
* \param
p
comb combination (or relative movement)
*
* \return a grid_key_dx_expression that encapsulate the expression
*
...
...
@@ -139,9 +168,9 @@ public:
return
*
this
;
}
/* \brief sum a grid_key
/*
!
\brief sum a grid_key
*
* \param comb combination (or relative movement)
* \param
p
comb combination (or relative movement)
*
* \return a grid_key_dx_expression that encapsulate the expression
*
...
...
@@ -154,7 +183,7 @@ public:
return
*
this
;
}
/* \brief sum a grid_key to the grid_key
/*
!
\brief sum a grid_key to the grid_key
*
* \param p grid_key to sum
*
...
...
@@ -168,7 +197,7 @@ public:
return
exp_sum
;
}
/* \brief sum an a combination to the grid_key
/*
!
\brief sum an a combination to the grid_key
*
* \param comb combination (or relative movement)
*
...
...
@@ -182,7 +211,7 @@ public:
return
exp_sum
;
}
/* \brief sum an a combination to the grid_key
/*
!
\brief sum an a combination to the grid_key
*
* \param comb combination (or relative movement)
*
...
...
@@ -196,7 +225,7 @@ public:
return
exp_sum
;
}
/* \brief sum an a combination to the grid_key
/*
!
\brief sum an a combination to the grid_key
*
* \param comb combination (or relative movement)
*
...
...
@@ -210,7 +239,7 @@ public:
return
exp_sum
;
}
/* \brief sum this key to another grid expression
/*
!
\brief sum this key to another grid expression
*
* \param cmb expression
*
...
...
@@ -224,7 +253,7 @@ public:
return
exp_sum
;
}
/* \brief Check if two key are the same
/*
!
\brief Check if two key are the same
*
* \param key_t key to check
*
...
...
@@ -253,7 +282,7 @@ public:
}
/* \brief Check if two key are the same
/*
!
\brief Check if two key are the same
*
* \param key_t key to check
*
...
...
src/Grid/grid_sm.hpp
View file @
dbfb2ecf
...
...
@@ -11,6 +11,7 @@
#include "grid_key.hpp"
#include <iostream>
#include "util/mathutil.hpp"
#include "iterators/stencil_type.hpp"
#define PERIODIC 1
#define NON_PERIODIC 0
...
...
@@ -50,13 +51,15 @@ public:
class
CheckExistence
{
public:
/*! \brief Check i
s performed
/*! \brief Check i
f vertex exist
*
* Check i
s performed
* Check i
f exist
*
* \param v_id Vertex id
* \param sz Size limit for the vertex id
*
* \return true if exist
*
*/
static
bool
valid
(
size_t
v_id
,
size_t
sz
)
{
...
...
@@ -64,11 +67,14 @@ public:
}
};
// Declarations;
//! Declaration grid_sm
template
<
unsigned
int
N
,
typename
T
>
class
grid_sm
;
//! Declaration print_warning_on_adjustment
template
<
unsigned
int
dim
>
class
print_warning_on_adjustment
;
template
<
unsigned
int
dim
,
typename
warn
=
print_warning_on_adjustment
<
dim
>
>
class
grid_key_dx_iterator_sub
;
//! Declaration grid_key_dx_iterator_sub
template
<
unsigned
int
dim
,
typename
stencil
=
no_stencil
,
typename
warn
=
print_warning_on_adjustment
<
dim
>
>
class
grid_key_dx_iterator_sub
;
/*! \brief class that store the information of the grid like number of point on each direction and
* define the index linearization by stride
...
...
@@ -92,21 +98,6 @@ class grid_sm
//! size of the grid on each stride (used for linearization)
size_t
sz_s
[
N
];
/*! \brief It multiplicate two number and return the result
*
* It multiplicate two number and return the result, mainly used for LinId
*
* \param a operand 1
* \param b operand 2
*
*/
inline
size_t
mulLin
(
size_t
a
,
size_t
b
)
{
return
a
*
b
;
}
/*! \brief Initialize the basic structure
*
* Initialize the basic structure
...
...
@@ -196,6 +187,8 @@ class grid_sm
public:
/*! \brief Return the box enclosing the grid
*
* \return the box
*
*/
inline
const
Box
<
N
,
size_t
>
&
getBox
()
const
...
...
@@ -221,12 +214,13 @@ public:
*
* Linearize(key1 + key2) = Linearize(key1) + Linearize(key2)
*
*
*
*/
inline
bool
isLinearizeLinear
()
/* inline bool isLinearizeLinear()
{
return true;
}
}
*/
/*! \brief Default constructor
*
...
...
@@ -241,6 +235,8 @@ public:
}
/*! \brief construct a grid from another grid
*
* \param g grid info
*
* construct a grid from another grid, type can be different
*
...
...
src/Grid/grid_sm_unit_tests.hpp
View file @
dbfb2ecf
...
...
@@ -53,7 +53,7 @@ BOOST_AUTO_TEST_CASE( grid_iterator_sub_p )
grid_sm
<
3
,
int
>
gs
(
sz
);
grid_key_dx_iterator_sub_bc
<
3
>
it
(
gs
,
key2
,
key1
,{
PERIODIC
,
PERIODIC
,
PERIODIC
});
grid_key_dx_iterator_sub_bc
<
3
,
no_stencil
>
it
(
gs
,
key2
,
key1
,{
PERIODIC
,
PERIODIC
,
PERIODIC
});
size_t
cnt
=
0
;
...
...
@@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE( grid_iterator_sub_p )
BOOST_REQUIRE_EQUAL
(
cnt
,
216ul
);
grid_key_dx_iterator_sub_bc
<
3
>
it2
(
gs
,
key2
,
key3
,{
PERIODIC
,
PERIODIC
,
PERIODIC
});
grid_key_dx_iterator_sub_bc
<
3
,
no_stencil
>
it2
(
gs
,
key2
,
key3
,{
PERIODIC
,
PERIODIC
,
PERIODIC
});
cnt
=
0
;
...
...
@@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE( grid_iterator_sub_p )
const
grid_key_dx
<
3
>
key4
(
0
,
-
1
,
0
);
const
grid_key_dx
<
3
>
key5
(
2
,
2
,
2
);
grid_key_dx_iterator_sub_bc
<
3
>
it3
(
gs
,
key4
,
key5
,{
NON_PERIODIC
,
PERIODIC
,
NON_PERIODIC
});
grid_key_dx_iterator_sub_bc
<
3
,
no_stencil
>
it3
(
gs
,
key4
,
key5
,{
NON_PERIODIC
,
PERIODIC
,
NON_PERIODIC
});
while
(
it3
.
isNext
())
{
...
...
@@ -121,7 +121,7 @@ BOOST_AUTO_TEST_CASE( grid_iterator_sub_p )
// bc non periodic with out-of-bound
grid_key_dx_iterator_sub_bc
<
3
,
do_not_print_warning_on_adjustment
<
3
>>
it4
(
gs
,
key4
,
key5
,{
NON_PERIODIC
,
NON_PERIODIC
,
NON_PERIODIC
});
grid_key_dx_iterator_sub_bc
<
3
,
no_stencil
,
do_not_print_warning_on_adjustment
<
3
>>
it4
(
gs
,
key4
,
key5
,{
NON_PERIODIC
,
NON_PERIODIC
,
NON_PERIODIC
});
cnt
=
0
;
...
...
@@ -147,7 +147,7 @@ BOOST_AUTO_TEST_CASE( grid_iterator_sub_p )
const
grid_key_dx
<
3
>
key6
(
-
1
,
-
1
,
-
1
);
const
grid_key_dx
<
3
>
key7
(
-
1
,
-
1
,
8
);
grid_key_dx_iterator_sub_bc
<
3
,
do_not_print_warning_on_adjustment
<
3
>>
it5
(
gs
,
key6
,
key7
,{
NON_PERIODIC
,
NON_PERIODIC
,
NON_PERIODIC
});
grid_key_dx_iterator_sub_bc
<
3
,
no_stencil
,
do_not_print_warning_on_adjustment
<
3
>>
it5
(
gs
,
key6
,
key7
,{
NON_PERIODIC
,
NON_PERIODIC
,
NON_PERIODIC
});
cnt
=
0
;
...
...
src/Grid/iterators/grid_iterators_unit_tests.cpp
View file @
dbfb2ecf
...
...
@@ -10,6 +10,7 @@
#include "Grid/iterators/grid_skin_iterator.hpp"
#include "Grid/map_grid.hpp"
#include "data_type/aggregate.hpp"
#include "Grid/iterators/grid_key_dx_iterator_stencil.hpp"
BOOST_AUTO_TEST_SUITE
(
grid_iterators_tests
)
...
...
@@ -105,5 +106,113 @@ BOOST_AUTO_TEST_CASE( grid_skin_iterator_test )
test_skin_iterator
<
3
>
(
bx5
,
bx4
,
g_sm
,
bc
,
7679
);
}
void
test_stencil_iterator
(
grid_sm
<
3
,
void
>
&
g_sm
)
{
grid_cpu
<
3
,
aggregate
<
long
int
>>
gtest
(
g_sm
.
getSize
());
gtest
.
setMemory
();
auto
it
=
gtest
.
getSubIterator
(
0
);
while
(
it
.
isNext
())
{
auto
key
=
it
.
get
();
gtest
.
get
<
0
>
(
key
)
=
key
.
get
(
0
)
+
key
.
get
(
1
)
+
key
.
get
(
2
);
++
it
;
}
grid_key_dx
<
3
>
stencil
[
1
];
stencil
[
0
].
set_d
(
0
,
0
);
stencil
[
0
].
set_d
(
1
,
0
);
stencil
[
0
].
set_d
(
2
,
0
);
bool
ret
=
true
;
grid_key_dx_iterator
<
3
,
stencil_offset_compute
<
3
,
1
>>
gsi
(
g_sm
,
stencil
);
while
(
gsi
.
isNext
()
==
true
)
{
auto
key
=
gsi
.
get
();
auto
lin
=
gsi
.
getStencil
<
0
>
();
ret
&=
(
gtest
.
get
<
0
>
(
lin
)
==
key
.
get
(
0
)
+
key
.
get
(
1
)
+
key
.
get
(
2
));
++
gsi
;
}
BOOST_REQUIRE_EQUAL
(
ret
,
true
);
}
BOOST_AUTO_TEST_CASE
(
grid_iterator_stencil_test
)
{
size_t
sz
[]
=
{
52
,
52
,
52
};
grid_sm
<
3
,
void
>
g_sm
(
sz
);
test_stencil_iterator
(
g_sm
);
}
static
grid_key_dx
<
3
>
star_stencil_3D
[
7
]
=
{{
0
,
0
,
0
},
{
0
,
0
,
-
1
},
{
0
,
0
,
1
},
{
0
,
-
1
,
0
},
{
0
,
1
,
0
},
{
-
1
,
0
,
0
},
{
1
,
0
,
0
}};
void
test_stencil_sub_iterator
(
grid_sm
<
3
,
void
>
&
g_sm
)
{
grid_cpu
<
3
,
aggregate
<
long
int
>>
gtest
(
g_sm
.
getSize
());
gtest
.
setMemory
();
auto
it
=
gtest
.
getSubIterator
(
0
);
while
(
it
.
isNext
())
{
auto
key
=
it
.
get
();
gtest
.
get
<
0
>
(
key
)
=
key
.
get
(
0
)
+
key
.
get
(
1
)
+
key
.
get
(
2
);
++
it
;