| 1 | #include <memory>
|
|---|
| 2 | #include<boost/unordered_map.hpp>
|
|---|
| 3 | #include <boost/mpi.hpp>
|
|---|
| 4 | #include <boost/mpi/collectives.hpp>
|
|---|
| 5 | #include <Eigen/Dense>
|
|---|
| 6 |
|
|---|
| 7 | namespace boost
|
|---|
| 8 | {
|
|---|
| 9 | namespace serialization
|
|---|
| 10 | {
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 | /// \brief save the object
|
|---|
| 14 | /// \param ar archive used
|
|---|
| 15 | /// \param g object to load
|
|---|
| 16 | template < class Archive,
|
|---|
| 17 | class S,
|
|---|
| 18 | int Rows_,
|
|---|
| 19 | int Cols_,
|
|---|
| 20 | int Ops_,
|
|---|
| 21 | int MaxRows_,
|
|---|
| 22 | int MaxCols_ >
|
|---|
| 23 | inline void save(Archive &ar,
|
|---|
| 24 | const Eigen::Array<S, Rows_, Cols_, Ops_, MaxRows_, MaxCols_> &g,
|
|---|
| 25 | const unsigned int)
|
|---|
| 26 | {
|
|---|
| 27 | int rows = g.rows();
|
|---|
| 28 | int cols = g.cols();
|
|---|
| 29 | ar &rows;
|
|---|
| 30 | ar &cols;
|
|---|
| 31 | ar &boost::serialization::make_array(g.data(), rows * cols);
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | /// \brief load the object
|
|---|
| 35 | /// \param ar archive used
|
|---|
| 36 | /// \param g object to load
|
|---|
| 37 | template < class Archive,
|
|---|
| 38 | class S,
|
|---|
| 39 | int Rows_,
|
|---|
| 40 | int Cols_,
|
|---|
| 41 | int Ops_,
|
|---|
| 42 | int MaxRows_,
|
|---|
| 43 | int MaxCols_ >
|
|---|
| 44 | inline void load(
|
|---|
| 45 | Archive &ar,
|
|---|
| 46 | Eigen::Array<S, Rows_, Cols_, Ops_, MaxRows_, MaxCols_> &g,
|
|---|
| 47 | const unsigned int)
|
|---|
| 48 | {
|
|---|
| 49 | int rows, cols;
|
|---|
| 50 | ar &rows;
|
|---|
| 51 | ar &cols;
|
|---|
| 52 | g.resize(rows, cols);
|
|---|
| 53 | ar &boost::serialization::make_array(g.data(), rows * cols);
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | /// \brief serialize the object Eigen
|
|---|
| 57 | /// \param ar archive used
|
|---|
| 58 | /// \param g object to load
|
|---|
| 59 | /// \param version useless
|
|---|
| 60 | template < class Archive,
|
|---|
| 61 | class S,
|
|---|
| 62 | int Rows_,
|
|---|
| 63 | int Cols_,
|
|---|
| 64 | int Ops_,
|
|---|
| 65 | int MaxRows_,
|
|---|
| 66 | int MaxCols_ >
|
|---|
| 67 | inline void serialize(
|
|---|
| 68 | Archive &ar,
|
|---|
| 69 | Eigen::Array< S, Rows_, Cols_, Ops_, MaxRows_, MaxCols_> &g,
|
|---|
| 70 | const unsigned int version)
|
|---|
| 71 | {
|
|---|
| 72 | split_free(ar, g, version);
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | } // namespace serialization
|
|---|
| 76 | } // namespace boost
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 | //---/ Wrapper for std::shared_ptr<> /------------------------------------------
|
|---|
| 80 |
|
|---|
| 81 | namespace boost
|
|---|
| 82 | {
|
|---|
| 83 | namespace serialization
|
|---|
| 84 | {
|
|---|
| 85 |
|
|---|
| 86 | template<class Archive, class Type>
|
|---|
| 87 | void save(Archive &archive, const std::shared_ptr<Type> &value, const unsigned int /*version*/)
|
|---|
| 88 | {
|
|---|
| 89 | Type *data = value.get();
|
|---|
| 90 | archive << data;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | template<class Archive, class Type>
|
|---|
| 94 | void load(Archive &archive, std::shared_ptr<Type> &value, const unsigned int /*version*/)
|
|---|
| 95 | {
|
|---|
| 96 | Type *data;
|
|---|
| 97 | archive >> data;
|
|---|
| 98 |
|
|---|
| 99 | typedef std::weak_ptr<Type> WeakPtr;
|
|---|
| 100 | static boost::unordered_map<void *, WeakPtr> hash;
|
|---|
| 101 |
|
|---|
| 102 | if (hash[data].expired())
|
|---|
| 103 | {
|
|---|
| 104 | value = std::shared_ptr<Type>(data);
|
|---|
| 105 | hash[data] = value;
|
|---|
| 106 | }
|
|---|
| 107 | else value = hash[data].lock();
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | template<class Archive, class Type>
|
|---|
| 111 | inline void serialize(Archive &archive, std::shared_ptr<Type> &value, const unsigned int version)
|
|---|
| 112 | {
|
|---|
| 113 | split_free(archive, value, version);
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | }
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | using namespace Eigen;
|
|---|
| 120 |
|
|---|
| 121 | int main(int argc, char *argv[])
|
|---|
| 122 | {
|
|---|
| 123 | boost::mpi::environment env(argc, argv);
|
|---|
| 124 | boost::mpi::communicator world;
|
|---|
| 125 | std::shared_ptr<ArrayXd> t ;
|
|---|
| 126 | boost::mpi:: broadcast(world, t,0);
|
|---|
| 127 | return 0;
|
|---|
| 128 | }
|
|---|