Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
153 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,3 +1,4 @@ | |||
a.out | a.out | ||
.*.swp | .*.swp | ||
*~ | *~ | ||
*-demo.c |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,46 @@ | |||
#include "timing.h" | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
|
|||
int main(int argc, char **argv) | |||
{ | |||
if (argc != 2) | |||
{ | |||
// STRIP | |||
fprintf(stderr, "need two arguments!\n"); | |||
abort(); | |||
} | |||
|
|||
const long n = atol(argv[1]); | |||
double *x = (double *) malloc(sizeof(double) * n); | |||
if (!x) { perror("alloc x"); abort(); } | |||
double *y = (double *) malloc(sizeof(double) * n); | |||
if (!y) { perror("alloc y"); abort(); } | |||
double *z = (double *) malloc(sizeof(double) * n); | |||
if (!z) { perror("alloc z"); abort(); } | |||
|
|||
for (int i = 0; i < n; ++i) | |||
{ | |||
x[i] = i; | |||
y[i] = 2*i; | |||
} | |||
|
|||
struct timespec time1, time2; | |||
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1); | |||
|
|||
const int ntrips = 2; | |||
for (int trip = 0; trip < ntrips; ++trip) | |||
{ | |||
for (int i = 0; i < n; ++i) | |||
{ | |||
z[i] = x[i] + y[i]; | |||
} | |||
} | |||
|
|||
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2); | |||
double elapsed = timespec_diff_in_seconds(time1,time2)/ntrips; | |||
printf("%f GB/s\n", | |||
3*n*sizeof(double)/1e9/elapsed); | |||
printf("%f GFlops/s\n", | |||
n/1e9/elapsed); | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,33 @@ | |||
#include "timing.h" | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
|
|||
int main(int argc, char **argv) | |||
{ | |||
if (argc != 2) | |||
{ | |||
// FIXME | |||
} | |||
|
|||
const long n = atol(argv[1]); | |||
double *x = (double *) malloc(sizeof(double) * n); | |||
double *y = (double *) malloc(sizeof(double) * n); | |||
double *z = (double *) malloc(sizeof(double) * n); | |||
|
|||
for (int i = 0; i < n; ++i) | |||
{ | |||
x[i] = i; | |||
y[i] = 2*i; | |||
} | |||
|
|||
struct timespec time1, time2; | |||
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1); | |||
|
|||
// FIXME | |||
|
|||
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2); | |||
printf("%f seconds for %d entries\n", | |||
timespec_diff_in_seconds(time1,time2), | |||
n); | |||
} | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,46 @@ | |||
#include "timing.h" | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
|
|||
int main(int argc, char **argv) | |||
{ | |||
if (argc != 2) | |||
{ | |||
// STRIP | |||
fprintf(stderr, "need two arguments!\n"); | |||
abort(); | |||
} | |||
|
|||
const long n = atol(argv[1]); | |||
double *x = (double *) malloc(sizeof(double) * n); | |||
if (!x) { perror("alloc x"); abort(); } | |||
double *y = (double *) malloc(sizeof(double) * n); | |||
if (!y) { perror("alloc y"); abort(); } | |||
double *z = (double *) malloc(sizeof(double) * n); | |||
if (!z) { perror("alloc z"); abort(); } | |||
|
|||
for (int i = 0; i < n; ++i) | |||
{ | |||
x[i] = i; | |||
y[i] = 2*i; | |||
} | |||
|
|||
struct timespec time1, time2; | |||
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1); | |||
|
|||
const int ntrips = 2; | |||
for (int trip = 0; trip < ntrips; ++trip) | |||
{ | |||
for (int i = 0; i < n; ++i) | |||
{ | |||
z[i] = x[i] + y[i]; | |||
} | |||
} | |||
|
|||
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2); | |||
double elapsed = timespec_diff_in_seconds(time1,time2)/ntrips; | |||
printf("%f GB/s\n", | |||
3*n*sizeof(double)/1e9/elapsed); | |||
printf("%f GFlops/s\n", | |||
n/1e9/elapsed); | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,8 +1,23 @@ | |||
000-timing-example.c: | colorscheme evening | ||
|
|||
00-timing-example.c: | |||
- basic timing | - basic timing | ||
- run into all errors | - run into all errors | ||
- -O3 | - -O3 | ||
- enable result printing | - enable result printing | ||
- time again | - time again | ||
|
|
||
001-simple.c: | 01-simple.c: | ||
- simple timing | |||
- run into segfault | |||
- debug it | |||
- what do the numbers mean? | |||
- timing repeatability | |||
- O3 | |||
- set-governor performance/ondemand | |||
- run through a few decades | |||
- why is it doing what it's doing?! | |||
- Control flow overhead | |||
- Cache | |||
|
|||
02-flexible.c: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
#! /bin/sh | |||
|
|||
for i in *-start.c; do | |||
echo cp $i ${i%%-start.c}-demo.c | |||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
#! /bin/sh | |||
|
|||
for i in 0 1 2 3; do | |||
cpufreq-set -g $1 -c 1 | |||
done |