11#include " read_txt_input_list.h"
22
3- #include " src_io/read_txt_tools.h"
4- #include " module_base/global_variable.h"
5-
6- #include " src_lcao/serialization_cereal.h"
7- #include < cereal/archives/binary.hpp>
8- #include < mpi.h>
9- #include < sstream>
103
114namespace Read_Txt_Input
125{
@@ -32,102 +25,10 @@ namespace Read_Txt_Input
3225 throw std::out_of_range (std::to_string (input_item.value_read_size )+std::to_string (size_low)+std::to_string (size_up));
3326 }
3427
35- void Input_List::read_and_convert (const std::string &file_name)
36- {
37- this ->set_items ();
38- if (GlobalV::MY_RANK==0 )
39- {
40- this ->read (file_name);
41- this ->check_transform ();
42- this ->default2 ();
43- this ->out (GlobalV::global_out_dir + file_name);
44- }
45- this ->bcast ();
46- this ->convert ();
47- }
48-
4928 void Input_List::set_items ()
5029 {
5130 set_items_general ();
5231 set_items_pw ();
5332 }
5433
55- void Input_List::read (const std::string &file_name)
56- {
57- const std::map<std::string, std::vector<std::string>> inputs_read
58- = Read_Txt_Tools::read_file_to_map (file_name, {" #" ," \\ " });
59- for (const auto & input_read : inputs_read)
60- {
61- const auto ptr = list.find (input_read.first );
62- if (ptr==list.end ())
63- throw std::out_of_range (" input_read.first" );
64- if (input_read.second .size () > ptr->second .value .size ())
65- throw std::out_of_range (" size error" );
66- for (size_t i=0 ; i<input_read.second .size (); ++i)
67- ptr->second .value [i].s = input_read.second [i];
68- ptr->second .value_read_size = input_read.second .size ();
69- }
70- }
71-
72- void Input_List::check_transform ()
73- {
74- for (auto &item : this ->list )
75- item.second .check_transform (item.second );
76- }
77-
78- void Input_List::default2 ()
79- {
80- for (auto &item : this ->list )
81- item.second .default2 (this ->list );
82- }
83-
84- void Input_List::out (const std::string &file_name) const
85- {
86- std::ofstream ofs (file_name);
87- for (const std::string &label : add_order)
88- {
89- ofs<<label<<" \t " ;
90- for (const Input_Value &value : this ->list .at (label).value )
91- ofs<<value.s <<" " ;
92- ofs<<" \t # " <<this ->list .at (label).annotation <<std::endl;
93- }
94- }
95-
96- void Input_List::bcast ()
97- {
98- #ifdef USE_CEREAL_SERIALIZATION
99- if (GlobalV::MY_RANK==0 )
100- {
101- std::stringstream ss;
102- {
103- cereal::BinaryOutputArchive ar (ss);
104- ar (this ->list );
105- }
106- const int size = ss.str ().size ();
107- MPI_Bcast ( const_cast <int *>(&size), 1 , MPI_INT, 0 , MPI_COMM_WORLD );
108- MPI_Bcast ( const_cast <char *>(ss.str ().c_str ()), size, MPI_CHAR, 0 , MPI_COMM_WORLD );
109- }
110- else
111- {
112- int size;
113- MPI_Bcast ( &size, 1 , MPI_INT, 0 , MPI_COMM_WORLD );
114- std::vector<char > c (size);
115- MPI_Bcast ( c.data (), size, MPI_CHAR, 0 , MPI_COMM_WORLD );
116- std::stringstream ss;
117- ss.rdbuf ()->pubsetbuf (c.data (),size);
118- {
119- cereal::BinaryInputArchive ar (ss);
120- ar (this ->list );
121- }
122- }
123- #else
124- #error Input_List::bcast() needs cereal
125- #endif
126- }
127-
128- void Input_List::convert ()
129- {
130- for (auto &item : this ->list )
131- item.second .convert (item.second );
132- }
13334}
0 commit comments