@@ -21,42 +21,79 @@ template<class Archive, typename T> void serialize( Archive & ar, Abfs::Vector3_
2121
2222namespace ModuleBase
2323{
24+ template <class Archive , typename T> void serialize ( Archive & ar, Vector3<T> & v ){ ar (v.x ); ar (v.y ); ar (v.z ); }
2425
25- template <class Archive , typename T> void serialize ( Archive & ar, Vector3<T> & v ){ ar (v.x ); ar (v.y ); ar (v.z ); }
26-
27- template <class Archive > void save ( Archive & ar, const matrix & m )
28- {
29- ar (m.nr ); ar (m.nc );
30- ar (cereal::binary_data (m.c , m.nr *m.nc *sizeof (double )));
31- }
32- template <class Archive > void load ( Archive & ar, matrix & m )
33- {
34- int nr, nc;
35- ar (nr); ar (nc);
36- m.create (nr,nc);
37- ar (cereal::binary_data (m.c , m.nr *m.nc *sizeof (double )));
38- }
26+ template <class Archive > void save ( Archive & ar, const matrix & m )
27+ {
28+ ar (m.nr ); ar (m.nc );
29+ ar (cereal::binary_data (m.c , m.nr *m.nc *sizeof (double )));
30+ }
31+ template <class Archive > void load ( Archive & ar, matrix & m )
32+ {
33+ int nr, nc;
34+ ar (nr); ar (nc);
35+ m.create (nr,nc);
36+ ar (cereal::binary_data (m.c , m.nr *m.nc *sizeof (double )));
37+ }
3938}
4039
4140namespace Read_Txt_Input
4241{
43- template <class Archive > void Input_Value::serialize ( Archive & ar )
44- {
45- ar ( this ->b );
46- ar ( this ->i );
47- ar ( this ->d );
48- ar ( this ->s );
42+ template <class Archive > void Input_Value::serialize ( Archive & ar )
43+ {
44+ ar ( this ->b );
45+ ar ( this ->i );
46+ ar ( this ->d );
47+ ar ( this ->s );
48+ }
49+ template <class Archive > void Input_Item::serialize ( Archive & ar )
50+ {
51+ ar ( this ->annotation );
52+ ar ( this ->values );
53+ ar ( this ->values_type );
54+ ar ( this ->label );
55+ ar ( this ->values_size_read );
56+ ar ( this ->values_size_lower_limit );
57+ ar ( this ->values_size_upper_limit );
58+ }
4959}
50- template <class Archive > void Input_Item::serialize ( Archive & ar )
60+
61+
62+
63+ #include < mpi.h>
64+ #include < sstream>
65+
66+ namespace ModuleBase
5167{
52- ar ( this ->annotation );
53- ar ( this ->values );
54- ar ( this ->values_type );
55- ar ( this ->label );
56- ar ( this ->values_size_read );
57- ar ( this ->values_size_lower_limit );
58- ar ( this ->values_size_upper_limit );
59- }
68+ template <typename T>
69+ void bcast_data_cereal (T &data, const MPI_Comm &mpi_comm, const int &rank_bcast)
70+ {
71+ int my_rank; MPI_Comm_rank ( mpi_comm, &my_rank );
72+ if (my_rank==rank_bcast)
73+ {
74+ std::stringstream ss;
75+ {
76+ cereal::BinaryOutputArchive ar (ss);
77+ ar (data);
78+ }
79+ const int size = ss.str ().size ();
80+ MPI_Bcast ( const_cast <int *>(&size), 1 , MPI_INT, rank_bcast, mpi_comm );
81+ MPI_Bcast ( const_cast <char *>(ss.str ().c_str ()), size, MPI_CHAR, rank_bcast, mpi_comm );
82+ }
83+ else
84+ {
85+ int size;
86+ MPI_Bcast ( &size, 1 , MPI_INT, rank_bcast, mpi_comm );
87+ std::vector<char > c (size);
88+ MPI_Bcast ( c.data (), size, MPI_CHAR, rank_bcast, mpi_comm );
89+ std::stringstream ss;
90+ ss.rdbuf ()->pubsetbuf (c.data (),size);
91+ {
92+ cereal::BinaryInputArchive ar (ss);
93+ ar (data);
94+ }
95+ }
96+ }
6097}
6198
6299#endif
0 commit comments