/mobile Handheld Friendly website
x64 Ubuntu : Intel® Q6600® quad-core |
Each table row shows performance measurements for this C++ g++ program with a particular command-line input value N.
| N | CPU secs | Elapsed secs | Memory KB | Code B | ≈ CPU Load |
|---|---|---|---|---|---|
| 12 | 0.05 | 0.04 | ? | 892 | 25% 50% 50% 67% |
| 16 | 0.96 | 0.38 | 592 | 892 | 76% 95% 53% 32% |
| 20 | 32.34 | 9.25 | 360,404 | 892 | 89% 79% 95% 88% |
Read the ↓ make, command line, and program output logs to see how this program was run.
Read binary-trees benchmark to see what this program should do.
gcc (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3
/* The Computer Language Benchmarks Game * http://benchmarksgame.alioth.debian.org/ * * contributed by Jon Harrop * modified by Alex Mizrahi * modified by Andreas Schäfer * very minor omp tweak by The Anh Tran */ #include <iostream> #include <stdlib.h> #include <stdio.h> #include <omp.h> #include <boost/pool/object_pool.hpp> const size_t LINE_SIZE = 64; struct Node { Node *l, *r; int i; Node(int i2) : l(0), r(0), i(i2) {} Node(Node *l2, int i2, Node *r2) : l(l2), r(r2), i(i2) {} int check() const { if (l) return l->check() + i - r->check(); else return i; } }; typedef boost::object_pool<Node> NodePool; Node *make(int i, int d, NodePool &store) { if (d > 0) return store.construct( make(2*i-1, d-1, store), i, make(2*i, d-1, store) ); return store.construct(i); } int GetThreadCount() { cpu_set_t cs; CPU_ZERO(&cs); sched_getaffinity(0, sizeof(cs), &cs); int count = 0; for (int i = 0; i < 8; i++) { if (CPU_ISSET(i, &cs)) count++; } return count; } int main(int argc, char *argv[]) { int min_depth = 4; int max_depth = std::max(min_depth+2, (argc == 2 ? atoi(argv[1]) : 10)); int stretch_depth = max_depth+1; // Alloc then dealloc stretchdepth tree { NodePool store; Node *c = make(0, stretch_depth, store); std::cout << "stretch tree of depth " << stretch_depth << "\t " << "check: " << c->check() << std::endl; } NodePool long_lived_store; Node *long_lived_tree = make(0, max_depth, long_lived_store); // buffer to store output of each thread char *outputstr = (char*)malloc(LINE_SIZE * (max_depth +1) * sizeof(char)); #pragma omp parallel for default(shared) num_threads(GetThreadCount()) schedule(dynamic, 1) for (int d = min_depth; d <= max_depth; d += 2) { int iterations = 1 << (max_depth - d + min_depth); int c = 0; for (int i = 1; i <= iterations; ++i) { NodePool store; Node *a = make(i, d, store), *b = make(-i, d, store); c += a->check() + b->check(); } // each thread write to separate location sprintf(outputstr + LINE_SIZE * d, "%d\t trees of depth %d\t check: %d\n", (2 * iterations), d, c); } // print all results for (int d = min_depth; d <= max_depth; d += 2) printf("%s", outputstr + (d * LINE_SIZE) ); free(outputstr); std::cout << "long lived tree of depth " << max_depth << "\t " << "check: " << (long_lived_tree->check()) << "\n"; return 0; }
Mon, 29 Apr 2013 17:39:23 GMT
MAKE:
/usr/bin/g++ -c -pipe -O3 -fomit-frame-pointer -march=native -fopenmp binarytrees.gpp-6.c++ -o binarytrees.gpp-6.c++.o && \
/usr/bin/g++ binarytrees.gpp-6.c++.o -o binarytrees.gpp-6.gpp_run -fopenmp
rm binarytrees.gpp-6.c++
5.58s to complete and log all make actions
COMMAND LINE:
./binarytrees.gpp-6.gpp_run 20
PROGRAM OUTPUT:
stretch tree of depth 21 check: -1
2097152 trees of depth 4 check: -2097152
524288 trees of depth 6 check: -524288
131072 trees of depth 8 check: -131072
32768 trees of depth 10 check: -32768
8192 trees of depth 12 check: -8192
2048 trees of depth 14 check: -2048
512 trees of depth 16 check: -512
128 trees of depth 18 check: -128
32 trees of depth 20 check: -32
long lived tree of depth 20 check: -1