11#include " source_base/module_out/binstream.h"
22#include " source_base/global_function.h"
3- #include " source_base/timer.h"
43#include " source_base/vector3.h"
54#include " source_base/module_parallel/para_mpi_func.h"
65#include " rhog_io.h"
76#include < numeric>
87#include < unistd.h>
98
9+ namespace
10+ {
11+ inline void warn (std::ostream* os,
12+ const Parallel::ParaWorld& pw_world,
13+ const std::string& file,
14+ const std::string& desc)
15+ {
16+ if (pw_world.rank () == 0 && os != nullptr )
17+ {
18+ *os << " " << file << " warning : " << desc << std::endl;
19+ }
20+ }
21+ } // namespace
22+
1023bool ModuleIO::read_rhog (const std::string& filename,
1124 const ModulePW::PW_Basis* pw_rhod,
1225 const int nspin,
1326 std::complex <double >** rhog,
14- const Parallel::ParaWorld& pw_world)
27+ const Parallel::ParaWorld& pw_world,
28+ std::ostream* os_warning)
1529{
16- ModuleBase::TITLE (" ModuleIO" , " read_rhog" );
17- ModuleBase::timer::start (" ModuleIO" , " read_rhog" );
18-
1930 const int nx = pw_rhod->nx ;
2031 const int ny = pw_rhod->ny ;
2132 const int nz = pw_rhod->nz ;
@@ -41,8 +52,7 @@ bool ModuleIO::read_rhog(const std::string& filename,
4152
4253 if (error)
4354 {
44- ModuleBase::WARNING (" ModuleIO::read_rhog" , " Can't open file " + filename);
45- ModuleBase::timer::end (" ModuleIO" , " read_rhog" );
55+ warn (os_warning, pw_world, " ModuleIO::read_rhog" , " Can't open file " + filename);
4656 return false ;
4757 }
4858
@@ -59,24 +69,23 @@ bool ModuleIO::read_rhog(const std::string& filename,
5969 }
6070 if (npwtot_in > pw_rhod->npwtot )
6171 {
62- ModuleBase::WARNING ( " ModuleIO::read_rhog" , " some planewaves in file are not used" );
72+ warn (os_warning, pw_world, " ModuleIO::read_rhog" , " some planewaves in file are not used" );
6373 }
6474 else if (npwtot_in < pw_rhod->npwtot )
6575 {
66- ModuleBase::WARNING ( " ModuleIO::read_rhog" , " some planewaves in file are missing" );
76+ warn (os_warning, pw_world, " ModuleIO::read_rhog" , " some planewaves in file are missing" );
6777 }
6878 if (nspin_in < nspin)
6979 {
70- ModuleBase::WARNING ( " ModuleIO::read_rhog" , " some spin channels in file are missing" );
80+ warn (os_warning, pw_world, " ModuleIO::read_rhog" , " some spin channels in file are missing" );
7181 }
7282 }
7383
7484 Parallel::bcast_bool (error, pw_world);
7585
7686 if (error)
7787 {
78- ModuleBase::WARNING (" ModuleIO::read_rhog" , " gamma_only read from file is inconsistent with INPUT" );
79- ModuleBase::timer::end (" ModuleIO" , " read_rhog" );
88+ warn (os_warning, pw_world, " ModuleIO::read_rhog" , " gamma_only read from file is inconsistent with INPUT" );
8089 return false ;
8190 }
8291
@@ -176,7 +185,6 @@ bool ModuleIO::read_rhog(const std::string& filename,
176185 {
177186 ifs.close ();
178187 }
179- ModuleBase::timer::end (" ModuleIO" , " read_rhog" );
180188 return true ;
181189}
182190
@@ -186,11 +194,9 @@ bool ModuleIO::write_rhog(const std::string& fchg,
186194 const int nspin,
187195 const ModuleBase::Matrix3& GT ,
188196 std::complex <double >** rhog,
189- const Parallel::ParaWorld& pw_world)
197+ const Parallel::ParaWorld& pw_world,
198+ std::ostream* os_warning)
190199{
191- ModuleBase::TITLE (" ModuleIO" , " write_rhog" );
192- ModuleBase::timer::start (" ModuleIO" , " write_rhog" );
193-
194200 // only rank 0 in the domain writes the header; all ranks cooperate
195201 // on sequential writes synchronized by barriers.
196202 const int irank = pw_world.rank ();
@@ -210,8 +216,7 @@ bool ModuleIO::write_rhog(const std::string& fchg,
210216 ofs.open (fchg, std::ios::binary);
211217 if (!ofs)
212218 {
213- ModuleBase::WARNING_QUIT (" ModuleIO::write_rhog" , " File I/O failure: cannot open file " + fchg);
214- ModuleBase::timer::end (" ModuleIO" , " write_rhog" );
219+ warn (os_warning, pw_world, " ModuleIO::write_rhog" , " File I/O failure: cannot open file " + fchg);
215220 return false ;
216221 }
217222 ofs.write (reinterpret_cast <char *>(&size), sizeof (size));
@@ -306,7 +311,6 @@ bool ModuleIO::write_rhog(const std::string& fchg,
306311 }
307312 Parallel::barrier (pw_world);
308313 }
309- ModuleBase::timer::end (" ModuleIO" , " write_rhog" );
310314 return true ;
311315}
312316
0 commit comments