forked from sth1997/GraphSet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotif_counting.py
53 lines (43 loc) · 1.58 KB
/
motif_counting.py
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
import os
from utils import *
from settings import *
GRAPHS = ["mico", "patents", "orkut", "livejournal"]
motif_sizes = [4]
def motif_counting(
is_gpu: bool = False,
bin_path: str = "../build/bin",
log_path: str = "../reproduce_log/motif_counting",
result_path: str = "../reproduce_result",
):
log_path = log_path + ("_gpu" if is_gpu else "_cpu")
if not os.path.exists(log_path):
os.makedirs(log_path)
result_path = result_path
if not os.path.exists(result_path):
os.makedirs(result_path)
result_path = (
f"{result_path}/motif_counting" + ("_gpu" if is_gpu else "_cpu") + ".csv"
)
data = []
data.append(["Size"] + GRAPHS)
execute_name = "gpu_mc" if is_gpu else "motif_counting_test"
for size in motif_sizes:
tmp = [size]
for graph in GRAPHS:
log_name = f"{log_path}/{graph}_mc{size}.log"
command = f"{bin_path}/{execute_name} {DATA_PATH}/{graph}.g {size} 1>{log_name}"
print(command, flush=True)
result = os.system(COMMAND_PREFIX + command)
tmp.append(read_time_cost(log_name))
if result != 0:
return 1
data.append(tmp)
write_table(data, result_path)
return 0
if __name__ == "__main__":
print("Reproducing motif counting results. (Time: 6 hours)")
print("Reproducing motif counting results on CPU...")
assert motif_counting(is_gpu=False) == 0
print("Reproducing motif counting results on GPU...")
assert motif_counting(is_gpu=True) == 0
print("Reproducing motif counting results done.")