Page MenuHomec4science

reference_manager.hh
No OneTemporary

File Metadata

Created
Sat, Jun 1, 01:18

reference_manager.hh

/**
* @file reference_manager.hh
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Mon Sep 08 23:40:22 2014
*
* @brief This is the manager of reference and coherency with migrations
*
* @section LICENSE
*
* Copyright INRIA and CEA
*
* The LibMultiScale is a C++ parallel framework for the multiscale
* coupling methods dedicated to material simulations. This framework
* provides an API which makes it possible to program coupled simulations
* and integration of already existing codes.
*
* This Project was initiated in a collaboration between INRIA Futurs Bordeaux
* within ScAlApplix team and CEA/DPTA Ile de France.
* The project is now continued at the Ecole Polytechnique Fédérale de Lausanne
* within the LSMS/ENAC laboratory.
*
* This software is governed by the CeCILL-C license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-C
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*
*/
#ifndef __LIBMULTISCALE_REFERENCE_MANAGER_HH__
#define __LIBMULTISCALE_REFERENCE_MANAGER_HH__
/* -------------------------------------------------------------------------- */
#include "ref_set.hh"
#include "ref_subset.hh"
#include "reference_manager_interface.hh"
#include <map>
#include <mpi.h>
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
template <typename Ref>
class ReferenceManager : public ReferenceManagerInterface {
public:
using GlobalContainer = typename Ref::Domain::ContainerPoints;
using BufferMap = std::map<UInt, PackBuffer>;
using MapRefToUInt = std::map<Ref, UInt, typename Ref::RefComparator>;
using MapRefToRef = std::map<Ref, Ref, typename Ref::RefComparator>;
using MapUIntToRefList = std::map<UInt, std::vector<Ref>>;
virtual ~ReferenceManager(){};
ReferenceManager(typename Ref::Domain::ContainerPoints &global_container)
: global_set(global_container, "global-container"), have_changed(false){};
//! function that start the updating process of all attached structures
void updateRefSubSets();
//! set the mpi communicator
void setCommGroup(CommGroup &comm);
//! request to manage a subset
void addSubSet(ContainerInterface &sub) override;
//! request to remove a subset
void removeSubSet(const LMID &name) override;
//! request attaching a given vector v with a given container c
void attachVector(ContainerArray<Real> &v, ContainerInterface &c) override;
//! request attaching a given vector v with the global container
void attachVector(ContainerArray<Real> &v, GlobalContainer &cont);
//! request detaching a given vector v with a given container c
void detachVector(ContainerArray<Real> &v, ContainerInterface &c) override;
//! request detaching a given vector v with the global container
void detachVector(ContainerArray<Real> &v, GlobalContainer &cont);
//! request attaching a generic AttachedObject with a given container c
void attachObject(AttachedObject &obj, ContainerInterface &c) override;
//! request detaching a generic AttachedObject with a given container c
void detachObject(AttachedObject &obj, ContainerInterface &c) override;
//! print bilan for concerned container : used only to debug
void printBilan();
//! retreive the mpi context
void acquireContext(const LMObject &obj) override;
protected:
//! generic communication routine to send/recv a bunch of buffers
void exchangeBuffers(BufferMap &toSend, BufferMap &toRecv);
//! translate the references for moved atoms
void translateMovingReferences();
//! pack masks to a BufferMap
void packMasks(MapRefToUInt &masks);
//! unpack masks to a BufferMap
void unpackMasks(MapRefToUInt &masks);
//! clear the buffers and/or create one entry per proc I should com with
void clearPackBuffers();
protected:
//! global set
RefSet<GlobalContainer> global_set;
//! subset array
std::map<LMID, std::shared_ptr<RefSubset<ContainerArray<Ref>>>> subsets;
//! mapping between sent atom ref and new proc owner
MapRefToUInt sent;
//! inverse mapping : sent atoms sorted by receiving processors
MapUIntToRefList sent_byproc;
//! new atoms generated by migration (received)
MapUIntToRefList newatoms;
//! communication buffers to be sent
BufferMap buffers_tosend;
//! communication buffers to be received
BufferMap buffers_torecv;
//! mapping between moved atoms old ref and new ref
MapRefToRef moved;
//! flag to notify if updating of attached references needed
bool have_changed;
//! for debug purpose
void printPackBuffersStatus();
private:
MPI_Comm worldCom;
int rank;
};
/* -------------------------------------------------------------------------- */
template <UInt Dim> class RefPointData;
template <UInt Dim>
struct ReferenceManager<RefPointData<Dim>> : public ReferenceManagerInterface {
void removeSubSet(const LMID &){};
};
/* -------------------------------------------------------------------------- */
template <UInt Dim> class RefGenericElem;
template <UInt Dim>
struct ReferenceManager<RefGenericElem<Dim>>
: public ReferenceManagerInterface {
void removeSubSet(const LMID &){};
};
/* -------------------------------------------------------------------------- */
template <UInt Dim> class RefGenericDDElem;
template <UInt Dim>
struct ReferenceManager<RefGenericDDElem<Dim>>
: public ReferenceManagerInterface {
void removeSubSet(const LMID &){};
};
/* -------------------------------------------------------------------------- */
template <UInt Dim> class RefGenericDDNode;
template <UInt Dim>
struct ReferenceManager<RefGenericDDNode<Dim>>
: public ReferenceManagerInterface {
void removeSubSet(const LMID &){};
};
/* -------------------------------------------------------------------------- */
template <> struct ReferenceManager<double> : public ReferenceManagerInterface {
void removeSubSet(const LMID &) {}
};
/* -------------------------------------------------------------------------- */
template <> struct ReferenceManager<UInt> : public ReferenceManagerInterface {
void removeSubSet(const LMID &) {}
};
/* -------------------------------------------------------------------------- */
class RefElemMeca1D;
template <>
struct ReferenceManager<RefElemMeca1D> : public ReferenceManagerInterface {
void removeSubSet(const LMID &) {}
};
/* -------------------------------------------------------------------------- */
template <UInt Dim> class RefElemAkantu;
template <UInt Dim>
struct ReferenceManager<RefElemAkantu<Dim>> : public ReferenceManagerInterface {
void removeSubSet(const LMID &) {}
};
/* -------------------------------------------------------------------------- */
class RefElemParaDiS;
template <>
struct ReferenceManager<RefElemParaDiS> : public ReferenceManagerInterface {
void removeSubSet(const LMID &) {}
};
/* -------------------------------------------------------------------------- */
__END_LIBMULTISCALE__
#endif /* __LIBMULTISCALE_REFERENCE_MANAGER_HH__ */

Event Timeline