forked from zongshenmu/GraphPartitioners
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.hpp
More file actions
101 lines (92 loc) · 2.88 KB
/
util.hpp
File metadata and controls
101 lines (92 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//
// Created by muzongshen on 2021/9/18.
//
#pragma once
#include <utility>
#include <chrono>
#include <stdint.h>
#include <sys/stat.h>
#include <glog/logging.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repv(i, n) for (vid_t i = 0; i < n; ++i)
typedef uint32_t vid_t;
const vid_t INVALID_VID = -1;
struct edge_t {
vid_t first, second;
edge_t() : first(0), second(0) {}
edge_t(vid_t first, vid_t second) : first(first), second(second) {}
const bool valid() { return first != INVALID_VID; }
void remove() { first = INVALID_VID; }
};
inline std::string change2tmpdir(const std::string& str)
{
std::string dir_path,file_name;
std::size_t found = str.find_last_of("/");
dir_path=str.substr(0,found);
file_name=str.substr(found+1);
dir_path+="/tmp_partitioning_dir";
std::string cmd="mkdir -p "+dir_path;
int flag=system(cmd.c_str());
if(flag==1){
LOG(FATAL)<<"make tmp dir error!";
}
return dir_path+"/"+file_name;
}
void writea(int f, char *buf, size_t nbytes);
inline std::string binedgelist_name(const std::string &basefilename)
{
std::string new_basefilename=change2tmpdir(basefilename);
std::stringstream ss;
ss << new_basefilename << ".binedgelist";
return ss.str();
}
inline std::string shuffled_binedgelist_name(const std::string &basefilename)
{
std::string new_basefilename=change2tmpdir(basefilename);
std::stringstream ss;
ss << new_basefilename << ".shuffled.binedgelist";
return ss.str();
}
inline std::string degree_name(const std::string &basefilename)
{
std::string new_basefilename=change2tmpdir(basefilename);
std::stringstream ss;
ss << new_basefilename << ".degree";
return ss.str();
}
inline std::string partitioned_name(const std::string &basefilename,const std::string &method, int pnum)
{
std::string new_basefilename=change2tmpdir(basefilename);
std::stringstream ss;
ss << new_basefilename << "."<<method<<".edgepart." << pnum; // chenzi: add partition number to the output file
return ss.str();
}
inline std::string nodesave_name(const std::string &basefilename,const std::string &method, int pnum)
{
std::string new_basefilename=change2tmpdir(basefilename);
std::stringstream ss;
ss << new_basefilename << "."<<method<<".nodes." << pnum; // chenzi: add partition number to the output file
return ss.str();
}
inline bool is_exists(const std::string &name)
{
struct stat buffer;
return (stat(name.c_str(), &buffer) == 0);
}
class Timer
{
private:
std::chrono::system_clock::time_point t1, t2;
double total;
public:
Timer() : total(0) {}
void reset() { total = 0; }
void start() { t1 = std::chrono::system_clock::now(); }
void stop()
{
t2 = std::chrono::system_clock::now();
std::chrono::duration<double> diff = t2 - t1;
total += diff.count();
}
double get_time() { return total; }
};