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_vcluster
Commits
e4065cc7
Commit
e4065cc7
authored
Aug 09, 2016
by
Yaroslav
Browse files
SGather with packer working, but needs modularization
parent
f1aad62b
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/VCluster_semantic.ipp
View file @
e4065cc7
...
...
@@ -9,6 +9,74 @@
private:
// Structures that do an unpack, depending on the existence of max_prop inside 'send'
//
template<bool result, typename T, typename S>
struct unpack_selector
{
template<int ... prp> static void call_unpack(S & recv, openfpm::vector<BHeapMemory> & recv_buf, openfpm::vector<size_t> * sz = NULL)
{
std::cout << "Sz.size(): " << sz->size() << std::endl;
std::cout << "Unp: " << demangle(typeid(T).name()) << std::endl;
for (size_t i = 0 ; i < recv_buf.size() ; i++)
{
std::cout << "Recv_buf.get(i).size(): " << recv_buf.get(i).size() << std::endl;
T unp;
ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(recv_buf.get(i).size(),recv_buf.get(i)));
mem.incRef();
Unpack_stat ps;
Unpacker<T,HeapMemory>::template unpack<prp...>(mem, unp, ps);
// Merge the information
recv.add(unp);
/*if (sz != NULL)
sz->get(i) = unp.size();*/
}
}
};
//
template<typename T, typename S>
struct unpack_selector<true, T, S>
{
template<int ... prp> static void call_unpack(S & recv, openfpm::vector<BHeapMemory> & recv_buf, openfpm::vector<size_t> * sz = NULL)
{
for (size_t i = 0 ; i < recv_buf.size() ; i++)
{
// calculate the number of received elements
size_t n_ele = recv_buf.get(i).size() / sizeof(typename T::value_type);
// add the received particles to the vector
PtrMemory * ptr1 = new PtrMemory(recv_buf.get(i).getPointer(),recv_buf.get(i).size());
// create vector representation to a piece of memory already allocated
openfpm::vector<typename T::value_type,PtrMemory,typename memory_traits_lin<typename T::value_type>::type, memory_traits_lin,openfpm::grow_policy_identity> v2;
v2.setMemory(*ptr1);
// resize with the number of elements
v2.resize(n_ele);
// Merge the information
recv.add(v2);
if (sz != NULL)
sz->get(i) = v2.size();
}
}
};
template<typename T>
struct call_serialize_variadic {};
...
...
@@ -25,49 +93,11 @@ private:
Packer<T,HeapMemory>::template pack<prp...>(mem,send,sts);
}
template<typename T, typename S> inline static void call_unpack(S & recv, openfpm::vector<BHeapMemory> & recv_buf,
Unpack_stat & ps,
openfpm::vector<size_t> * sz = NULL)
template<typename T, typename S> inline static void call_unpack(S & recv, openfpm::vector<BHeapMemory> & recv_buf, openfpm::vector<size_t> * sz = NULL)
{
if (has_pack_agg<typename T::value_type, prp...>::result::value == true)
{
for (size_t i = 0 ; i < recv_buf.size() ; i++)
{
T unp;
ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(recv_buf.get(i).size(),recv_buf.get(i)));
mem.incRef();
Unpacker<T,HeapMemory>::template unpack<prp...>(mem, unp, ps);
// Merge the information
recv.add(unp);
}
}
else
{
for (size_t i = 0 ; i < recv_buf.size() ; i++)
{
// calculate the number of received elements
size_t n_ele = recv_buf.get(i).size() / sizeof(typename T::value_type);
// add the received particles to the vector
PtrMemory * ptr1 = new PtrMemory(recv_buf.get(i).getPointer(),recv_buf.get(i).size());
// create vector representation to a piece of memory already allocated
openfpm::vector<typename T::value_type,PtrMemory,typename memory_traits_lin<typename T::value_type>::type, memory_traits_lin,openfpm::grow_policy_identity> v2;
const bool result = has_pack_agg<typename T::value_type, prp...>::result::value == false && is_vector<T>::value == true;
v2.setMemory(*ptr1);
// resize with the number of elements
v2.resize(n_ele);
// Merge the information
recv.add(v2);
if (sz != NULL)
sz->get(i) = v2.size();
}
}
unpack_selector<result, T, S>::template call_unpack<prp...>(recv, recv_buf, sz);
}
};
...
...
@@ -77,24 +107,27 @@ private:
template<bool cond, typename T, typename S>
struct pack_unpack_cond
{
static void packingRequest(T & send, size_t & tot_size)
static void packingRequest(T & send, size_t & tot_size
, openfpm::vector<size_t> & sz
)
{
typedef typename ::generate_indexes<int, has_max_prop<T, has_value_type<T>::value>::number, MetaFuncOrd>::result ind_prop_to_pack;
// Packer<T,HeapMemory>::packRequest< prop_to_pack::data >(send,tot_size);
call_serialize_variadic<ind_prop_to_pack>::call_pr(send,tot_size);
std::cout << "Tot_size: " << tot_size << std::endl;
sz.add(tot_size);
}
static void packing(ExtPreAlloc<HeapMemory> & mem, T & send, Pack_stat & sts)
static void packing(ExtPreAlloc<HeapMemory> & mem, T & send, Pack_stat & sts
, openfpm::vector<const void *> & send_buf
)
{
typedef typename ::generate_indexes<int, has_max_prop<T, has_value_type<T>::value>::number, MetaFuncOrd>::result ind_prop_to_pack;
//Packer<T,HeapMemory>::pack< prop_to_pack::data >(mem,send,sts);
call_serialize_variadic<ind_prop_to_pack>::call_pack(mem,send,sts);
send_buf.add(mem.getPointerBase());
}
static void unpacking(S & recv, openfpm::vector<BHeapMemory> & recv_buf,
Unpack_stat & ps,
openfpm::vector<size_t> * sz = NULL)
static void unpacking(S & recv, openfpm::vector<BHeapMemory> & recv_buf, openfpm::vector<size_t> * sz = NULL)
{
typedef typename ::generate_indexes<int, has_max_prop<T, has_value_type<T>::value>::number, MetaFuncOrd>::result ind_prop_to_pack;
call_serialize_variadic<ind_prop_to_pack>::template call_unpack<T,S>(recv, recv_buf,
ps,
sz);
call_serialize_variadic<ind_prop_to_pack>::template call_unpack<T,S>(recv, recv_buf, sz);
}
};
...
...
@@ -103,21 +136,40 @@ private:
template<typename T, typename S>
struct pack_unpack_cond<false, T, S>
{
static void packingRequest(T & send, size_t & tot_size)
static void packingRequest(T & send, size_t & tot_size
, openfpm::vector<size_t> & sz
)
{
//tot_size = send.size()*sizeof(typename T::value_type);
Packer<T,HeapMemory>::packRequest(send,tot_size);
std::cout << "Inside SGather pack request (no prp) " << std::endl;
std::cout << "Tot_size: " << tot_size << std::endl;
if (has_pack<typename T::value_type>::type::value == true)
{
//tot_size = send.size()*sizeof(typename T::value_type);
std::cout << "Inside SGather pack request (no prp) " << std::endl;
Packer<T,HeapMemory>::packRequest(send,tot_size);
std::cout << "Tot_size: " << tot_size << std::endl;
sz.add(tot_size);
}
else
{
sz.add(send.size()*sizeof(typename T::value_type));
}
}
static void packing(ExtPreAlloc<HeapMemory> & mem, T & send, Pack_stat & sts)
static void packing(ExtPreAlloc<HeapMemory> & mem, T & send, Pack_stat & sts
, openfpm::vector<const void *> & send_buf
)
{
Packer<T,HeapMemory>::pack(mem,send,sts);
std::cout << "Inside SGather pack (no prp) " << std::endl;
if (has_pack<typename T::value_type>::type::value == true)
{
Packer<T,HeapMemory>::pack(mem,send,sts);
send_buf.add(mem.getPointer());
}
else
{
std::cout << "Inside SGather pack (no prp) (no pack inside) " << std::endl;
send_buf.add(send.getPointer());
}
}
static void unpacking(S & recv, openfpm::vector<BHeapMemory> & recv_buf,
Unpack_stat & ps,
openfpm::vector<size_t> * sz = NULL)
static void unpacking(S & recv, openfpm::vector<BHeapMemory> & recv_buf, openfpm::vector<size_t> * sz = NULL)
{
std::cout << "Inside SGather unpack (no prp) " << std::endl;
if (has_pack<typename T::value_type>::type::value == true)
...
...
@@ -129,15 +181,19 @@ private:
ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(recv_buf.get(i).size(),recv_buf.get(i)));
mem.incRef();
Unpack_stat ps;
Unpacker<T,HeapMemory>::unpack(mem, unp, ps);
// Merge the information
recv.add(unp);
}
}
else
{
std::cout << "Inside SGather unpack (no prp) (no pack inside) " << std::endl;
for (size_t i = 0 ; i < recv_buf.size() ; i++)
{
...
...
@@ -244,10 +300,8 @@ template<typename T, typename S> void process_receive_buffer(S & recv, openfpm::
{
if (sz != NULL)
sz->resize(recv_buf.size());
Unpack_stat ps;
pack_unpack_cond<has_max_prop<T, has_value_type<T>::value>::value, T, S>::unpacking(recv, recv_buf,
ps,
sz);
pack_unpack_cond<has_max_prop<T, has_value_type<T>::value>::value, T, S>::unpacking(recv, recv_buf, sz);
}
public:
...
...
@@ -339,10 +393,6 @@ template<typename T, typename S> bool SGather(T & send, S & recv, openfpm::vecto
// Send and recv multiple messages
sendrecvMultipleMessagesNBX(send_req.size(),NULL,NULL,NULL,msg_alloc,&bi);
// Convert the received byte into number of elements
/*for (size_t i = 0 ; i < sz.size() ; i++)
sz.get(i) /= sizeof(typename T::value_type);*/
// process the received information
process_receive_buffer<T,S>(recv,&sz);
...
...
@@ -362,7 +412,9 @@ template<typename T, typename S> bool SGather(T & send, S & recv, openfpm::vecto
//Pack requesting
pack_unpack_cond<has_max_prop<T, has_value_type<T>::value>::value, T, S>::packingRequest(send, tot_size);
openfpm::vector<size_t> sz;
pack_unpack_cond<has_max_prop<T, has_value_type<T>::value>::value, T, S>::packingRequest(send, tot_size, sz);
HeapMemory pmem;
...
...
@@ -372,14 +424,9 @@ template<typename T, typename S> bool SGather(T & send, S & recv, openfpm::vecto
//Packing
Pack_stat sts;
pack_unpack_cond<has_max_prop<T, has_value_type<T>::value>::value, T, S>::packing(mem, send, sts);
openfpm::vector<const void *> send_buf;
send_buf.add(mem.getPointer());
openfpm::vector<size_t> sz;
sz.add(send.size()*sizeof(typename T::value_type));
pack_unpack_cond<has_max_prop<T, has_value_type<T>::value>::value, T, S>::packing(mem, send, sts, send_buf);
// receive information
base_info bi(NULL,prc,sz);
...
...
src/VCluster_semantic_unit_tests.hpp
View file @
e4065cc7
...
...
@@ -8,6 +8,8 @@
#ifndef OPENFPM_VCLUSTER_SRC_VCLUSTER_SEMANTIC_UNIT_TESTS_HPP_
#define OPENFPM_VCLUSTER_SRC_VCLUSTER_SEMANTIC_UNIT_TESTS_HPP_
#include "Grid/grid_util_test.hpp"
struct
Aexample
{
size_t
a
;
...
...
@@ -387,6 +389,155 @@ BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather_2)
}
}
BOOST_AUTO_TEST_CASE
(
Vcluster_semantic_gather_3
)
{
Vcluster
&
vcl
=
create_vcluster
();
if
(
vcl
.
getProcessingUnits
()
>=
32
)
return
;
openfpm
::
vector
<
size_t
>
v1
;
v1
.
resize
(
vcl
.
getProcessUnitID
());
for
(
size_t
i
=
0
;
i
<
vcl
.
getProcessUnitID
()
;
i
++
)
v1
.
get
(
i
)
=
5
;
openfpm
::
vector
<
openfpm
::
vector
<
size_t
>>
v2
;
vcl
.
SGather
(
v1
,
v2
,
1
);
if
(
vcl
.
getProcessUnitID
()
==
1
)
{
size_t
n
=
vcl
.
getProcessingUnits
();
BOOST_REQUIRE_EQUAL
(
v2
.
size
(),
n
-
1
);
bool
is_five
=
true
;
for
(
size_t
i
=
0
;
i
<
v2
.
size
()
;
i
++
)
{
for
(
size_t
j
=
0
;
j
<
v2
.
get
(
i
).
size
()
;
j
++
)
is_five
&=
(
v2
.
get
(
i
).
get
(
j
)
==
5
);
}
BOOST_REQUIRE_EQUAL
(
is_five
,
true
);
}
vcl
.
SGather
(
v1
,
v2
,
0
);
if
(
vcl
.
getProcessUnitID
()
==
0
)
{
size_t
n
=
vcl
.
getProcessingUnits
();
BOOST_REQUIRE_EQUAL
(
v2
.
size
(),
n
);
bool
is_five
=
true
;
for
(
size_t
i
=
0
;
i
<
v2
.
size
()
;
i
++
)
{
for
(
size_t
j
=
0
;
j
<
v2
.
get
(
i
).
size
()
;
j
++
)
is_five
&=
(
v2
.
get
(
i
).
get
(
j
)
==
5
);
}
BOOST_REQUIRE_EQUAL
(
is_five
,
true
);
}
}
BOOST_AUTO_TEST_CASE
(
Vcluster_semantic_gather_4
)
{
Vcluster
&
vcl
=
create_vcluster
();
if
(
vcl
.
getProcessingUnits
()
>=
32
)
return
;
size_t
sz
[]
=
{
16
,
16
};
grid_cpu
<
2
,
Point_test
<
float
>>
g1
(
sz
);
g1
.
setMemory
();
fill_grid
<
2
>
(
g1
);
openfpm
::
vector
<
grid_cpu
<
2
,
Point_test
<
float
>>>
v2
;
vcl
.
SGather
(
g1
,
v2
,
0
);
typedef
Point_test
<
float
>
p
;
if
(
vcl
.
getProcessUnitID
()
==
0
)
{
size_t
n
=
vcl
.
getProcessingUnits
();
BOOST_REQUIRE_EQUAL
(
v2
.
size
(),
n
);
bool
match
=
true
;
for
(
size_t
i
=
0
;
i
<
v2
.
size
()
;
i
++
)
{
auto
it
=
v2
.
get
(
i
).
getIterator
();
while
(
it
.
isNext
())
{
grid_key_dx
<
2
>
key
=
it
.
get
();
match
&=
(
v2
.
get
(
i
).
template
get
<
p
::
x
>(
key
)
==
g1
.
template
get
<
p
::
x
>(
key
));
match
&=
(
v2
.
get
(
i
).
template
get
<
p
::
y
>(
key
)
==
g1
.
template
get
<
p
::
y
>(
key
));
match
&=
(
v2
.
get
(
i
).
template
get
<
p
::
z
>(
key
)
==
g1
.
template
get
<
p
::
z
>(
key
));
match
&=
(
v2
.
get
(
i
).
template
get
<
p
::
s
>(
key
)
==
g1
.
template
get
<
p
::
s
>(
key
));
match
&=
(
v2
.
get
(
i
).
template
get
<
p
::
v
>(
key
)[
0
]
==
g1
.
template
get
<
p
::
v
>(
key
)[
0
]);
match
&=
(
v2
.
get
(
i
).
template
get
<
p
::
v
>(
key
)[
1
]
==
g1
.
template
get
<
p
::
v
>(
key
)[
1
]);
match
&=
(
v2
.
get
(
i
).
template
get
<
p
::
v
>(
key
)[
2
]
==
g1
.
template
get
<
p
::
v
>(
key
)[
2
]);
match
&=
(
v2
.
get
(
i
).
template
get
<
p
::
t
>(
key
)[
0
][
0
]
==
g1
.
template
get
<
p
::
t
>(
key
)[
0
][
0
]);
match
&=
(
v2
.
get
(
i
).
template
get
<
p
::
t
>(
key
)[
0
][
1
]
==
g1
.
template
get
<
p
::
t
>(
key
)[
0
][
1
]);
match
&=
(
v2
.
get
(
i
).
template
get
<
p
::
t
>(
key
)[
0
][
2
]
==
g1
.
template
get
<
p
::
t
>(
key
)[
0
][
2
]);
match
&=
(
v2
.
get
(
i
).
template
get
<
p
::
t
>(
key
)[
1
][
0
]
==
g1
.
template
get
<
p
::
t
>(
key
)[
1
][
0
]);
match
&=
(
v2
.
get
(
i
).
template
get
<
p
::
t
>(
key
)[
1
][
1
]
==
g1
.
template
get
<
p
::
t
>(
key
)[
1
][
1
]);
match
&=
(
v2
.
get
(
i
).
template
get
<
p
::
t
>(
key
)[
1
][
2
]
==
g1
.
template
get
<
p
::
t
>(
key
)[
1
][
2
]);
match
&=
(
v2
.
get
(
i
).
template
get
<
p
::
t
>(
key
)[
2
][
0
]
==
g1
.
template
get
<
p
::
t
>(
key
)[
2
][
0
]);
match
&=
(
v2
.
get
(
i
).
template
get
<
p
::
t
>(
key
)[
2
][
1
]
==
g1
.
template
get
<
p
::
t
>(
key
)[
2
][
1
]);
match
&=
(
v2
.
get
(
i
).
template
get
<
p
::
t
>(
key
)[
2
][
2
]
==
g1
.
template
get
<
p
::
t
>(
key
)[
2
][
2
]);
++
it
;
}
}
BOOST_REQUIRE_EQUAL
(
match
,
true
);
}
}
BOOST_AUTO_TEST_CASE
(
Vcluster_semantic_gather_5
)
{
Vcluster
&
vcl
=
create_vcluster
();
if
(
vcl
.
getProcessingUnits
()
>=
32
)
return
;
openfpm
::
vector
<
openfpm
::
vector
<
size_t
>>
v1
;
openfpm
::
vector
<
size_t
>
v3
;
v3
.
resize
(
vcl
.
getProcessUnitID
());
for
(
size_t
i
=
0
;
i
<
vcl
.
getProcessUnitID
()
;
i
++
)
v3
.
get
(
i
)
=
5
;
v1
.
add
(
v3
);
v1
.
add
(
v3
);
v1
.
add
(
v3
);
openfpm
::
vector
<
openfpm
::
vector
<
openfpm
::
vector
<
size_t
>>>
v2
;
vcl
.
SGather
(
v1
,
v2
,
0
);
if
(
vcl
.
getProcessUnitID
()
==
0
)
{
size_t
n
=
vcl
.
getProcessingUnits
();
BOOST_REQUIRE_EQUAL
(
v2
.
size
(),
n
);
bool
is_five
=
true
;
for
(
size_t
i
=
0
;
i
<
v2
.
size
()
;
i
++
)
{
for
(
size_t
j
=
0
;
j
<
v2
.
get
(
i
).
size
()
;
j
++
)
is_five
&=
(
v2
.
get
(
i
).
get
(
j
)
==
5
);
}
BOOST_REQUIRE_EQUAL
(
is_five
,
true
);
}
}
BOOST_AUTO_TEST_SUITE_END
()
#endif
/* OPENFPM_VCLUSTER_SRC_VCLUSTER_SEMANTIC_UNIT_TESTS_HPP_ */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment