ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
test_function.h
Go to the documentation of this file.
1#ifndef TEST_FUNCTION_H
2#define TEST_FUNCTION_H
3
4#include<sstream>
5#include<fstream>
6#include <vector>
7#include <valarray>
8#include <array>
9#include <set>
10#include <string>
11#ifdef __MPI
12#include<mpi.h>
13#endif
14#include<sys/time.h>
15
16// Peize Lin add 2015-11-11
17#ifdef __MPI
18static void MPI_RANK_OFSTREAM( const std::string& file_name, std::stringstream &content )
19{
20 std::stringstream file;
21 int my_rank; MPI_Comm_rank(MPI_COMM_WORLD,&my_rank);
22 file<<file_name<<"_"<<my_rank;
23
24 std::ofstream ofs(file.str().c_str(), std::ofstream::app);
25 ofs<<content.str();
26
27 content.str("");
28 ofs.close();
29}
30#endif
31
32// Peize Lin add 2016-06-06
33template<typename T1,typename T2>
34static std::ostream & operator<<( std::ostream & os, const std::pair<T1,T2> &p )
35{
36 os<<"<"<<p.first<<","<<p.second<<">";
37 return os;
38}
39
40// Peize Lin add 2016-06-06
41template<typename T>
42static std::ostream & operator<<( std::ostream & os, const std::vector<T> &v )
43{
44 os<<"[";
45 for( const T &i : v )
46 os<<i<<std::endl;
47 os<<"]";
48 return os;
49}
50
51// Peize Lin add 2016-06-06
52template<typename T>
53static std::ostream & operator<<( std::ostream & os, const std::valarray<T> &v )
54{
55 os<<"[";
56 for( const T &i : v )
57 os<<i<<std::endl;
58 os<<"]";
59 return os;
60}
61
62// Peize Lin add 2016-06-06
63template<typename T, size_t N>
64static std::ostream & operator<<( std::ostream & os, const std::array<T,N> &v )
65{
66 os<<"[";
67 for( const T &i : v )
68 os<<i<<"\t";
69 os<<"]";
70 return os;
71}
72
73// Peize Lin add 2016-06-06
74template<typename T>
75static std::ostream & operator<<( std::ostream & os, const std::set<T> &v )
76{
77 os<<"(";
78 for( const T &i : v )
79 os<<i<<"\t";
80 os<<")";
81 return os;
82}
83
84// Peize Lin add 2016-06-06
85template<typename T1, typename T2>
86static std::ostream & operator<<( std::ostream & os, const std::map<T1,T2> &v )
87{
88 for( const auto &i : v )
89// os<<"{"<<i.first<<":"<<i.second<<"}"<<"\t";
90 os<<i.first<<std::endl<<i.second<<std::endl;
91 return os;
92}
93
94// Peize Lin add 2016-10-10
95static double cal_time( const timeval &t_begin )
96{
97 timeval t_end;
98 gettimeofday( &t_end, NULL);
99 return (double)(t_end.tv_sec-t_begin.tv_sec) + (double)(t_end.tv_usec-t_begin.tv_usec)/1000000.0;
100}
101
102// Peize Lin add 2016-10-10
103static double cut_time( timeval &t )
104{
105 const double time = cal_time(t);
106 gettimeofday( &t, NULL);
107 return time;
108}
109
110// Peize Lin add 2019-12-12
111static std::vector<double> get_memory(const int N)
112{
113 std::vector<double> m;
114 std::string s;
115 std::ifstream ifs("/proc/meminfo");
116 ifs>>s>>s;
117 m.push_back(stoi(s)/1024);
118 for(int i=1; i<N; ++i)
119 {
120 ifs>>s>>s>>s;
121 m.push_back(stoi(s)/1024);
122 }
123 ifs.close();
124 return m;
125}
126
127#endif // TEST_FUNCTION_H
#define N
Definition exp.cpp:24
#define T
Definition exp.cpp:237
int4 i[880]
Definition sincos.cpp:28
std::ostream & operator<<(std::ostream &os, const Tensor &tensor)
Overloaded operator<< for the Tensor class.
Definition tensor.cpp:329
file(GLOB ATen_CORE_SRCS "*.cpp") set(ATen_CPU_SRCS $
Definition CMakeLists.txt:1