Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F75491062
ref_set.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Aug 2, 13:41
Size
7 KB
Mime Type
text/x-c++
Expires
Sun, Aug 4, 13:41 (2 d)
Engine
blob
Format
Raw Data
Handle
19557278
Attached To
rLIBMULTISCALE LibMultiScale
ref_set.cc
View Options
/**
* @file ref_set.cc
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Mon Sep 08 23:40:22 2014
*
* @brief This file contains the interface of containers of references 4 the
* migration system
*
* @section LICENSE
*
* Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne)
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* LibMultiScale is free software: you can redistribute it and/or modify it
* under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* LibMultiScale is distributed in the hope that it will be useful, but
* WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with LibMultiScale. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#include <boost/preprocessor.hpp>
/* -------------------------------------------------------------------------- */
#include "lib_continuum.hh"
#include "lib_dd.hh"
#include "lib_md.hh"
#include "lm_common.hh"
#include "ref_set.hh"
#include "trace_atom.hh"
/* -------------------------------------------------------------------------- */
// #define PROC_INVALID -1
__BEGIN_LIBMULTISCALE__
/* -------------------------------------------------------------------------- */
// attach a vector of data to the set
// template <typename Ref> void RefSet<Ref>::attachData(AttachedObject &obj) {
// LM_ASSERT(std::find(attached.begin(), attached.end(), &obj) ==
// attached.end(),
// "obj " << &obj << " was alread attached in the past");
// attached.push_back(&obj);
// }
/* -------------------------------------------------------------------------- */
// detach a vector of data from the set
// template <typename Ref> void RefSet<Ref>::detachData(AttachedObject &obj) {
// UInt size = attached.size();
// for (UInt i = 0; i < size; ++i) {
// if (attached[i] == &obj) {
// attached[i] = attached[size - 1];
// attached.resize(size - 1);
// break;
// }
// }
// }
// /* --------------------------------------------------------------------------
// */
template
<
typename
Ref
>
void
RefSet
<
Ref
>::
declareSentAtoms
(
MapRefToUInt
&
,
MapUIntToRefList
&
sent_reverse
)
{
DUMP
(
"declare atoms sent for set "
<<
name
,
DBG_INFO
);
// clear maps
sent
.
clear
();
sent_indexes
.
clear
();
// loop over the sent atoms to build ordered buffer list
for
(
auto
&&
[
proc
,
listsent
]
:
sent_reverse
)
{
for
(
auto
&&
at
:
listsent
)
{
sent
[
proc
].
push_back
(
at
);
sent_indexes
[
proc
].
push_back
(
at
.
getIndex
());
}
}
for
(
auto
&&
[
proc
,
list_sent
]
:
sent
)
{
DUMP
(
"I am supposed to send "
<<
list_sent
.
size
()
<<
" atoms to proc "
<<
proc
<<
" for global set"
,
DBG_INFO
);
}
}
/* -------------------------------------------------------------------------- */
template
<
typename
Ref
>
void
RefSet
<
Ref
>::
declareRecvAtoms
(
MapUIntToRefList
&
recv_atoms
)
{
DUMP
(
"declare atoms received for set "
<<
name
,
DBG_INFO
);
recv
.
clear
();
recv_indexes
.
clear
();
for
(
auto
&&
[
proc
,
recvlist
]
:
recv_atoms
)
{
for
(
auto
&&
ref
:
recvlist
)
{
recv
[
proc
].
push_back
(
ref
);
recv_indexes
[
proc
].
push_back
(
ref
.
getIndex
());
}
}
for
(
auto
&&
[
proc
,
recvlist
]
:
recv_indexes
)
{
DUMP
(
"I am supposed to recv "
<<
recvlist
.
size
()
<<
" atoms from proc "
<<
proc
<<
" for global set"
,
DBG_INFO
);
}
}
/* -------------------------------------------------------------------------- */
template
<
typename
Ref
>
void
RefSet
<
Ref
>::
packAttachedData
(
std
::
map
<
UInt
,
PackBuffer
>
&
buffer
)
{
typename
MapUIntToUIntList
::
iterator
it
;
typename
MapUIntToUIntList
::
iterator
end
;
for
(
it
=
sent_indexes
.
begin
(),
end
=
sent_indexes
.
end
();
it
!=
end
;
++
it
)
{
UInt
proc
=
(
*
it
).
first
;
std
::
vector
<
UInt
>
listsent
=
(
*
it
).
second
;
if
(
proc
==
UINT_MAX
)
continue
;
DUMP
(
"list_sent size "
<<
listsent
.
size
(),
DBG_INFO
);
DUMP
(
"attached_size "
<<
attached
.
size
(),
DBG_INFO
);
DUMP
(
"will pack "
<<
listsent
.
size
()
*
attached
.
size
()
<<
" "
<<
buffer
[
proc
].
size
(),
DBG_INFO
);
for
(
UInt
i
=
0
;
i
<
listsent
.
size
();
++
i
)
{
for
(
UInt
j
=
0
;
j
<
attached
.
size
();
++
j
)
{
attached
[
j
]
->
packData
(
listsent
[
i
],
buffer
[
proc
],
proc
);
}
}
}
}
/* -------------------------------------------------------------------------- */
template
<
typename
Ref
>
void
RefSet
<
Ref
>::
unpackAttachedData
(
std
::
map
<
UInt
,
PackBuffer
>
&
buffer
)
{
typename
MapUIntToUIntList
::
iterator
it
;
typename
MapUIntToUIntList
::
iterator
end
;
for
(
it
=
recv_indexes
.
begin
(),
end
=
recv_indexes
.
end
();
it
!=
end
;
++
it
)
{
UInt
proc
=
(
*
it
).
first
;
std
::
vector
<
UInt
>
listrecv
=
(
*
it
).
second
;
if
(
proc
==
UINT_MAX
)
continue
;
DUMP
(
"list_recv size "
<<
listrecv
.
size
(),
DBG_INFO
);
DUMP
(
"attached_size "
<<
attached
.
size
(),
DBG_INFO
);
DUMP
(
"will unpack "
<<
listrecv
.
size
()
*
attached
.
size
()
<<
" "
<<
buffer
[
proc
].
remainingSize
(),
DBG_INFO
);
for
(
UInt
i
=
0
;
i
<
listrecv
.
size
();
++
i
)
{
for
(
UInt
j
=
0
;
j
<
attached
.
size
();
++
j
)
{
attached
[
j
]
->
unpackData
(
listrecv
[
i
],
buffer
[
proc
],
proc
);
}
}
}
}
/* -------------------------------------------------------------------------- */
template
<
typename
Ref
>
void
RefSet
<
Ref
>::
resize
()
{
UInt
sz
=
container
.
size
();
for
(
UInt
j
=
0
;
j
<
attached
.
size
();
++
j
)
{
attached
[
j
]
->
resize
(
sz
);
}
}
/* -------------------------------------------------------------------------- */
template
<
typename
Ref
>
void
RefSet
<
Ref
>::
moveAttachedValues
(
UInt
i_src
,
UInt
i_dest
)
{
if
(
i_src
==
i_dest
)
return
;
IF_REF_TRACED
(
container
.
get
(
i_src
),
"traced atom moved from index "
<<
i_src
<<
" to index "
<<
i_dest
<<
" for container "
<<
&
container
);
DUMP
(
"atom moved from index "
<<
i_src
<<
" to index "
<<
i_dest
<<
" for container "
<<
&
container
,
DBG_INFO
);
for
(
UInt
j
=
0
;
j
<
attached
.
size
();
++
j
)
{
attached
[
j
]
->
moveAttachedValues
(
i_src
,
i_dest
);
}
}
/* -------------------------------------------------------------------------- */
#define DECLARE_REF_SET(n, data, obj) \
template class RefSet< \
ContainerArray<typename BOOST_PP_TUPLE_ELEM(3, 0, obj)::RefPoint>>; \
template class RefSet<typename BOOST_PP_TUPLE_ELEM(3, 0, \
obj)::ContainerPoints>;
BOOST_PP_SEQ_FOR_EACH
(
DECLARE_REF_SET
,
f
,
LIST_ATOM_MODEL
)
BOOST_PP_SEQ_FOR_EACH
(
DECLARE_REF_SET
,
f
,
LIST_DD_MODEL
)
BOOST_PP_SEQ_FOR_EACH
(
DECLARE_REF_SET
,
f
,
LIST_CONTINUUM_MODEL
)
#undef DECLARE_REF_SET
__END_LIBMULTISCALE__
Event Timeline
Log In to Comment