GitLab will be upgraded to the 12.10.14-ce.0 on 28 Sept 2020 at 2.00pm (AEDT) to 2.30pm (AEDT). During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to us at N110 (b) CSIT building.

Commit 8ca55cf7 authored by John Zhang's avatar John Zhang

C version of the binary tree benchmark; modified RPython version of the...

C version of the binary tree benchmark; modified RPython version of the benchmark to follow the same pattern as C
parent b5983e73
......@@ -15,6 +15,16 @@ btree:
source: targetbtree.py
environ:
PYPY_USESSION_BASENAME: "${MUBENCH_TASKSET_NAME}_${MUBENCH_TASK_NAME}"
rpyc_no_gc:
language:
name: rpython
backend: c
source: targetbtree.py
environ:
PYPY_USESSION_BASENAME: "${MUBENCH_TASKSET_NAME}_${MUBENCH_TASK_NAME}"
compiler:
flags:
- --gc=none
rpyzebu:
language:
name: rpython
......@@ -27,3 +37,16 @@ btree:
vmargs:
- --gc-immixspace-size=524288000 # 500M
- --gc-lospace-size=104587600 # 100M
c_O3:
language: c
source: btree.c
compiler:
flags:
- -O3
c_O3_set_null:
language: c
source: btree.c
compiler:
flags:
- -O3
- -DBTREE_DELETE_TREE_SETNULL
/* The Computer Language Benchmarks Game
* http://benchmarksgame.alioth.debian.org/
contributed by Kevin Carson
compilation:
gcc -O3 -fomit-frame-pointer -funroll-loops -static binary-trees.c -lm
icc -O3 -ip -unroll -static binary-trees.c -lm
*reset*
modified by John Zhang
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "callback.h"
typedef struct tn {
struct tn* left;
struct tn* right;
} treeNode;
#ifdef BTREE_DELETE_TREE_SETNULL
#define DELETE_TREE(t) t = NULL
#else // default to call free
#define DELETE_TREE(t) DeleteTree(t)
#endif
treeNode* NewTreeNode(treeNode* left, treeNode* right)
{
treeNode* new;
new = (treeNode*)malloc(sizeof(treeNode));
new->left = left;
new->right = right;
return new;
} /* NewTreeNode() */
treeNode* BottomUpTree(unsigned long depth)
{
if (depth > 0)
return NewTreeNode(BottomUpTree(depth - 1), BottomUpTree(depth - 1));
else
return NewTreeNode(NULL, NULL);
} /* BottomUpTree() */
unsigned long ItemCheck(treeNode* tree)
{
if (tree->left == NULL)
return 1;
else
return 1 + ItemCheck(tree->left) + ItemCheck(tree->right);
} /* ItemCheck() */
void DeleteTree(treeNode* tree)
{
if (tree->left != NULL)
{
DeleteTree(tree->left);
DeleteTree(tree->right);
}
free(tree);
} /* DeleteTree() */
unsigned long bm_main(unsigned long N)
{
unsigned long minDepth, maxDepth, stretchDepth;
treeNode *stretchTree, *longLivedTree, *tempTree;
unsigned long check, iterations;
minDepth = 4;
maxDepth = (minDepth + 2) > N ? (minDepth + 2) : N;
stretchDepth = maxDepth + 1;
check = 0;
stretchTree = BottomUpTree(stretchDepth);
check += ItemCheck(stretchTree);
DELETE_TREE(stretchTree);
longLivedTree = BottomUpTree(maxDepth);
for (unsigned long depth = minDepth; depth <= maxDepth; depth += 2)
{
iterations = 1 << (maxDepth + minDepth - depth);
for (unsigned long i = 1; i <= iterations; i++)
{
tempTree = BottomUpTree(depth);
check += ItemCheck(tempTree);
DELETE_TREE(tempTree);
tempTree = NULL;
} /* for(i = 1...) */
} /* for(depth = minDepth...) */
check += ItemCheck(longLivedTree);
DELETE_TREE(longLivedTree);
return check;
}
int main(int argc, char* argv[])
{
unsigned long N, check;
struct Callback* cb;
cb = cb_init(argv[1]);
N = atol(argv[2]);
cb_begin(cb, NULL);
check = bm_main(N);
cb_end(cb, NULL);
printf("total check = %li\n", check);
cb_report(cb);
return 0;
} /* main() */
......@@ -4,82 +4,50 @@
# contributed by Antoine Pitrou
# modified by Dominique Wahli and Daniel Nanz
# modified by Joerg Baumann
# modified by John Zhang into RPython
# modified by John Zhang into RPython, following the pattern of the C equivalent
class Node:
def __init__(self, l, r):
self.l = l
self.r = r
def make_tree(d):
def bottom_up_tree(d):
if d > 0:
d -= 1
return Node(make_tree(d), make_tree(d))
return Node(bottom_up_tree(d - 1), bottom_up_tree(d - 1))
return Node(None, None)
def check_tree(node):
def item_check(node):
l = node.l
r = node.r
if l is None:
return 1
else:
return 1 + check_tree(l) + check_tree(r)
return 1 + item_check(l) + item_check(r)
def make_check(itde, make=make_tree, check=check_tree):
i, d = itde
return check(make(d))
def bm_main(N, min_depth=4):
minDepth = 4
maxDepth = (minDepth + 2) if (minDepth + 2) > N else N
stretchDepth = maxDepth + 1
check = 0
stretchTree = bottom_up_tree(stretchDepth)
check += item_check(stretchTree)
stretchTree = None # rely on GC to free memory
def get_argchunks(i, d, chunksize=5000):
longLivedTree = bottom_up_tree(maxDepth)
assert chunksize % 2 == 0
chunk = []
for k in range(1, i + 1):
chunk.extend([(k, d)])
if len(chunk) == chunksize:
yield chunk
chunk = []
if len(chunk) > 0:
yield chunk
for depth in range(minDepth, maxDepth + 1, 2):
iterations = 1 << (maxDepth + minDepth - depth)
def proc_chunk(chunk):
acc = 0
for c in chunk:
acc += make_check(c)
return acc
def bm_main(n, min_depth=4):
max_depth = max(min_depth + 2, n)
stretch_depth = max_depth + 1
print 'stretch tree of depth %d\t check: %d' % \
(stretch_depth, make_check((0, stretch_depth)))
long_lived_tree = make_tree(max_depth)
mmd = max_depth + min_depth
chunksize=5000
for d in range(min_depth, stretch_depth, 2):
i = 1 << (mmd - d)
cs = 0
# for argchunk in get_argchunks(i,d):
# cs += sum(map(make_check, argchunk))
# inlined get_argchunks
chunk = []
for k in range(1, i + 1):
chunk.extend([(k, d)])
if len(chunk) == chunksize:
cs += proc_chunk(chunk)
chunk = []
if len(chunk) > 0:
cs += proc_chunk(chunk)
print "%d\t trees of depth %d\t check: %d" % (i, d, cs)
print 'long lived tree of depth %d\t check: %d' % (max_depth, check_tree(long_lived_tree))
for i in range(1, iterations):
tempTree = bottom_up_tree(depth)
check += item_check(tempTree)
tempTree = None
check += item_check(longLivedTree)
longLivedTree = None
return check
def target(driver, args):
......@@ -88,13 +56,14 @@ def target(driver, args):
def main(argv):
cb_param = argv[1]
n = int(argv[2])
N = int(argv[2])
cb = cb_cls(cb_param)
cb.begin()
bm_main(n)
check = bm_main(N)
cb.end()
print "total check = %d" % check
cb.report()
return 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment