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
be8c849c
Commit
be8c849c
authored
Feb 10, 2016
by
Pietro Incardona
Browse files
Semantic gather
parent
c8ddf7f3
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/VCluster_semantic.ipp
View file @
be8c849c
...
...
@@ -7,6 +7,16 @@
* Author: Pietro Incardona
*/
/*! \brief Reset the receive buffer
*
*
*/
void reset_recv_buf()
{
for (size_t i = 0 ; i < recv_buf.size() ; i++)
recv_buf.get(i).resize(0);
}
/*! \brief Call-back to allocate buffer to receive data
*
* \param msg_i size required to receive the message from i
...
...
@@ -27,10 +37,9 @@ static void * msg_alloc(size_t msg_i ,size_t total_msg, size_t total_p, size_t i
if (recv_buf == NULL)
std::cerr << __FILE__ << ":" << __LINE__ << " Internal error this processor is not suppose to receive\n";
// We need one more slot
recv_buf->add();
recv_buf->resize(ri+1);
recv_buf->
last(
).resize(msg_i);
recv_buf->
get(ri
).resize(msg_i);
// return the pointer
return recv_buf->last().getPointer();
...
...
@@ -62,6 +71,9 @@ static void * msg_alloc(size_t msg_i ,size_t total_msg, size_t total_p, size_t i
*/
template<typename T, typename S> bool SGather(T & send, S & recv,size_t root)
{
// Reset the receive buffer
reset_recv_buf();
// If we are on master collect the information
if (getProcessUnitID() == root)
{
...
...
@@ -92,13 +104,15 @@ template<typename T, typename S> bool SGather(T & send, S & recv,size_t root)
// Merge the information
recv.add(v2);
}
recv.add(send);
}
else
{
// send buffer (master does not send anything) so send req and send_buf
// remain buffer with size 0
openfpm::vector<size_t> send_prc;
send_prc.add(
0
);
send_prc.add(
root
);
openfpm::vector<void *> send_buf;
send_buf.add(send.getPointer());
openfpm::vector<size_t> sz;
...
...
src/VCluster_semantic_unit_tests.hpp
View file @
be8c849c
...
...
@@ -20,78 +20,146 @@ BOOST_AUTO_TEST_SUITE( VCluster_semantic_test )
BOOST_AUTO_TEST_CASE
(
Vcluster_semantic_gather
)
{
Vcluster
&
vcl
=
*
global_v_cluster
;
{
Vcluster
&
vcl
=
*
global_v_cluster
;
if
(
vcl
.
getProcessingUnits
()
>=
32
)
return
;
if
(
vcl
.
getProcessingUnits
()
>=
32
)
return
;
//! [Gather the data on master]
//! [Gather the data on master]
openfpm
::
vector
<
size_t
>
v1
;
v1
.
resize
(
vcl
.
getProcessUnitID
());
openfpm
::
vect
or
<
size_t
>
v1
;
v1
.
resize
(
vcl
.
getProcessUnitID
())
;
f
or
(
size_t
i
=
0
;
i
<
vcl
.
getProcessUnitID
()
;
i
++
)
v1
.
get
(
i
)
=
5
;
for
(
size_t
i
=
0
;
i
<
vcl
.
getProcessUnitID
()
;
i
++
)
v1
.
get
(
i
)
=
5
;
openfpm
::
vector
<
size_t
>
v2
;
openfpm
::
vector
<
size_t
>
v2
;
vcl
.
SGather
(
v1
,
v2
,
0
)
;
vcl
.
SGather
(
v1
,
v2
,
0
);
//! [Gather the data on master]
if
(
vcl
.
getProcessUnitID
()
==
0
)
{
size_t
n
=
vcl
.
getProcessingUnits
();
BOOST_REQUIRE_EQUAL
(
v2
.
size
(),
n
*
(
n
-
1
)
/
2
);
//! [Gather the data on master]
bool
is_five
=
true
;
for
(
size_t
i
=
0
;
i
<
v2
.
size
()
;
i
++
)
is_five
&=
(
v2
.
get
(
i
)
==
5
);
if
(
vcl
.
getProcessUnitID
()
==
0
)
BOOST_REQUIRE_EQUAL
(
is_five
,
true
);
}
}
{
size_t
n
=
vcl
.
getProcessingUnits
();
BOOST_REQUIRE_EQUAL
(
v2
.
size
(),
n
*
(
n
-
1
)
/
2
);
Vcluster
&
vcl
=
*
global_v_cluster
;
if
(
vcl
.
getProcessingUnits
()
>=
32
)
return
;
bool
is_five
=
true
;
for
(
size_t
i
=
0
;
i
<
v2
.
size
()
;
i
++
)
is_five
&=
(
v2
.
get
(
i
)
==
5
);
openfpm
::
vector
<
size_t
>
v1
;
v1
.
resize
(
vcl
.
getProcessUnitID
());
BOOST_REQUIRE_EQUAL
(
is_five
,
true
);
for
(
size_t
i
=
0
;
i
<
vcl
.
getProcessUnitID
()
;
i
++
)
v1
.
get
(
i
)
=
5
;
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
*
(
n
-
1
)
/
2
);
bool
is_five
=
true
;
for
(
size_t
i
=
0
;
i
<
v2
.
size
()
;
i
++
)
is_five
&=
(
v2
.
get
(
i
)
==
5
);
BOOST_REQUIRE_EQUAL
(
is_five
,
true
);
}
}
}
BOOST_AUTO_TEST_CASE
(
Vcluster_semantic_struct_gather
)
{
Vcluster
&
vcl
=
*
global_v_cluster
;
{
Vcluster
&
vcl
=
*
global_v_cluster
;
if
(
vcl
.
getProcessingUnits
()
>=
32
)
return
;
if
(
vcl
.
getProcessingUnits
()
>=
32
)
return
;
//! [Gather the data on master complex]
//! [Gather the data on master complex]
openfpm
::
vector
<
A
>
v1
;
v1
.
resize
(
vcl
.
getProcessUnitID
());
openfpm
::
vector
<
A
>
v1
;
v1
.
resize
(
vcl
.
getProcessUnitID
());
for
(
size_t
i
=
0
;
i
<
vcl
.
getProcessUnitID
()
;
i
++
)
{
v1
.
get
(
i
).
a
=
5
;
v1
.
get
(
i
).
b
=
10.0
;
v1
.
get
(
i
).
c
=
11.0
;
}
for
(
size_t
i
=
0
;
i
<
vcl
.
getProcessUnitID
()
;
i
++
)
{
v1
.
get
(
i
).
a
=
5
;
v1
.
get
(
i
).
b
=
10.0
;
v1
.
get
(
i
).
c
=
11.0
;
}
openfpm
::
vector
<
A
>
v2
;
openfpm
::
vector
<
A
>
v2
;
vcl
.
SGather
(
v1
,
v2
,
0
);
vcl
.
SGather
(
v1
,
v2
,
0
);
//! [Gather the data on master complex]
//! [Gather the data on master complex]
if
(
vcl
.
getProcessUnitID
()
==
0
)
if
(
vcl
.
getProcessUnitID
()
==
0
)
{
size_t
n
=
vcl
.
getProcessingUnits
();
BOOST_REQUIRE_EQUAL
(
v2
.
size
(),
n
*
(
n
-
1
)
/
2
);
bool
is_correct
=
true
;
for
(
size_t
i
=
0
;
i
<
v2
.
size
()
;
i
++
)
{
is_correct
&=
(
v2
.
get
(
i
).
a
==
5
);
is_correct
&=
(
v2
.
get
(
i
).
b
==
10.0
);
is_correct
&=
(
v2
.
get
(
i
).
c
==
11.0
);
}
BOOST_REQUIRE_EQUAL
(
is_correct
,
true
);
}
}
{
size_t
n
=
vcl
.
getProcessingUnits
();
BOOST_REQUIRE_EQUAL
(
v2
.
size
(),
n
*
(
n
-
1
)
/
2
);
Vcluster
&
vcl
=
*
global_v_cluster
;
if
(
vcl
.
getProcessingUnits
()
>=
32
)
return
;
bool
is_correct
=
true
;
for
(
size_t
i
=
0
;
i
<
v2
.
size
()
;
i
++
)
openfpm
::
vector
<
A
>
v1
;
v1
.
resize
(
vcl
.
getProcessUnitID
());
for
(
size_t
i
=
0
;
i
<
vcl
.
getProcessUnitID
()
;
i
++
)
{
is_correct
&=
(
v2
.
get
(
i
).
a
=
=
5
)
;
is_correct
&=
(
v2
.
get
(
i
).
b
=
=
10.0
)
;
is_correct
&=
(
v2
.
get
(
i
).
c
=
=
11.0
)
;
v1
.
get
(
i
).
a
=
5
;
v1
.
get
(
i
).
b
=
10.0
;
v1
.
get
(
i
).
c
=
11.0
;
}
BOOST_REQUIRE_EQUAL
(
is_correct
,
true
);
openfpm
::
vector
<
A
>
v2
;
vcl
.
SGather
(
v1
,
v2
,
1
);
if
(
vcl
.
getProcessUnitID
()
==
1
)
{
size_t
n
=
vcl
.
getProcessingUnits
();
BOOST_REQUIRE_EQUAL
(
v2
.
size
(),
n
*
(
n
-
1
)
/
2
);
bool
is_correct
=
true
;
for
(
size_t
i
=
0
;
i
<
v2
.
size
()
;
i
++
)
{
is_correct
&=
(
v2
.
get
(
i
).
a
==
5
);
is_correct
&=
(
v2
.
get
(
i
).
b
==
10.0
);
is_correct
&=
(
v2
.
get
(
i
).
c
==
11.0
);
}
BOOST_REQUIRE_EQUAL
(
is_correct
,
true
);
}
}
}
...
...
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