Skip to content

Commit c2bfaa1

Browse files
authored
Aux scripts
1 parent b5fcc43 commit c2bfaa1

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

metacompiler.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
if (count($argv) < 2)
3+
die("Usage: {@$argv[0]} code.cu\n");
4+
5+
$code = file_get_contents($argv[1]);
6+
7+
$jobs = preg_match_all('/class\s+(\w+?)\: public AbstractJob\s*{(.*?)};/sm', $code, $matches, PREG_SET_ORDER);
8+
// print_r($matches);
9+
$count = count($matches);
10+
11+
/// Part1: Job types enum
12+
$enum = [];
13+
for ($i=0;$i< $count; ++$i) {
14+
$jobname = $matches[$i][1];
15+
$jobname = str_replace("Job", "", $jobname);
16+
$enum[] = $jobname;
17+
}
18+
$enum_str = "enum JobTypes {\n\tAbstract,\n\t";
19+
$enum_str .= join(",\n\t", $enum);
20+
$enum_str .= "\n};\n";
21+
22+
echo $enum_str;
23+
24+
25+
26+
/// Part2: Iter call function
27+
$iter =[];
28+
for ($i=0;$i<$count; ++$i)
29+
$iter[]= "if (job->job_type == JobTypes::{$enum[$i]})\n\t(({$enum[$i]}Job *)job)->iter(id, d_offsets, d_edges, n, m);";
30+
31+
$iter_str = join("\nelse ", $iter);
32+
$iter_str .= PHP_EOL. 'else printf("Unsupported job type!\n");' . PHP_EOL;
33+
echo $iter_str;
34+
35+
/// Part3: FusionJob union
36+
$typedata = [];
37+
for ($i=0;$i<$count;++$i) {
38+
preg_match('#//PRAGMA: job data\n(.*?)\n//PRAGMA#ms', $matches[$i][2], $data);
39+
$data=$data[1];
40+
$data=explode("\n", $data);
41+
$data=array_map('trim', $data);
42+
43+
$typedata[$i] = [];
44+
foreach ($data as $datum) {
45+
preg_match('/(.*?)\s+(.*?);/', $datum, $match);
46+
$type = $match[1];
47+
$name = $match[2];
48+
while ($name[0] == '*')
49+
{
50+
$name = substr($name, 1);
51+
$type .= "*";
52+
if (!(substr($type, -1) == '*' or $type == 'i64' or $type =='double' or $type == 'u64'))
53+
echo "Warning: Type '{$type}' may not be 8 bytes. I suggest using only 8 byte types in jobs.\n";
54+
}
55+
$typedata[$i][] = ['type' => $type, 'name' => $name];
56+
}
57+
}
58+
$max = 0;
59+
for ($i=0; $i<count($typedata); ++$i) {
60+
$max=max($max, count($typedata[$i]));
61+
}
62+
// print_r($typedata);
63+
$union = [];
64+
for ($i=0;$i<$max;++$i) {
65+
$values = [];
66+
for ($j=0;$j<$count; ++$j) {
67+
if (isset($typedata[$j][$i]))
68+
$values[] = $typedata[$j][$i]['type'] . " " . $typedata[$j][$i]['name'];
69+
}
70+
while (count($values) > 1 && $values[0] == $values[1]) {
71+
array_shift($values);
72+
}
73+
$union[$i] = $values;
74+
75+
}
76+
// print_r($union);
77+
78+
$union_str = "struct FusionJob: public AbstractJob {\n";
79+
foreach ($union as $u) {
80+
if (count($u) > 1) {
81+
$union_str.= "\tunion {\n";
82+
foreach ($u as $item) {
83+
$union_str .= "\t\t{$item};\n";
84+
}
85+
$union_str .= "\t};\n";
86+
}
87+
else
88+
$union_str.= "\t{$u[0]};\n";
89+
}
90+
$union_str .= "};\n";
91+
echo $union_str;

setup-graphs.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
3+
DIR=$1
4+
5+
mkdir -p "$DIR"
6+
7+
# Patent Citation Network (CP)
8+
# Number of Vertices: 6.0 M
9+
# Number of Edges : 16.5 M
10+
wget -P "$DIR" https://snap.stanford.edu/data/cit-Patents.txt.gz
11+
mv "$DIR/cit-Patents.txt.gz" "$DIR/cit-patents.txt.gz"
12+
gunzip "$DIR/cit-patents.txt.gz"
13+
SNAPtoAdj "$DIR/cit-patents.txt" "$DIR/cit-patents"
14+
15+
# LiveJournal Social Network (LJ)
16+
# Number of Vertices: 4.8 M
17+
# Number of Edges : 69.0 M
18+
wget -P "$DIR" https://snap.stanford.edu/data/soc-LiveJournal1.txt.gz
19+
mv "$DIR/soc-LiveJournal1.txt.gz" "$DIR/soc-livejournal1.txt.gz"
20+
gunzip "$DIR/soc-livejournal1.txt.gz"
21+
SNAPtoAdj "$DIR/soc-livejournal1.txt" "$DIR/soc-livejournal1"
22+
23+
# Pokec Social Network (PS)
24+
# Number of Vertices: 1.6 M
25+
# Number of Edges : 30.6 M
26+
wget -P "$DIR" https://snap.stanford.edu/data/soc-pokec-relationships.txt.gz
27+
gunzip "$DIR/soc-pokec-relationships.txt.gz"
28+
SNAPtoAdj "$DIR/soc-pokec-relationships.txt" "$DIR/soc-pokec-relationships"
29+
30+
# Wikipedia Talk Network (WT)
31+
# Number of Vertices: 2.4 M
32+
# Number of Edges : 5.0 M
33+
wget -P "$DIR" https://snap.stanford.edu/data/wiki-Talk.txt.gz
34+
mv "$DIR/wiki-Talk.txt.gz" "$DIR/wiki-talk.txt.gz"
35+
gunzip "$DIR/wiki-talk.txt.gz"
36+
SNAPtoAdj "$DIR/wiki-talk.txt" "$DIR/wiki-talk"

0 commit comments

Comments
 (0)