catalinux / cpublaster (public) (License: GPLv3) (since 2016-02-05) (hash sha1)
This project tries to alleviate the aliasing problems of the modern CPUs.
It is a preloadable shared object.
List of commits:
Subject Hash Author Date (UTC)
misc stuff 4fd71d53ef3ec365a78624b413bb080c87f15866 Catalin(ux) M. BOIE 2016-02-10 16:42:53
First version 5d3e80a68d1033b11b5e91d7d25be107f586e4db Catalin(ux) M. BOIE 2012-07-20 15:49:54
Commit 4fd71d53ef3ec365a78624b413bb080c87f15866 - misc stuff
Author: Catalin(ux) M. BOIE
Author date (UTC): 2016-02-10 16:42
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2016-02-10 16:42
Parent(s): 5d3e80a68d1033b11b5e91d7d25be107f586e4db
Signing key:
Tree: 79b7a0782f44ecd7e89bd64041b5994802776bee
File Lines added Lines deleted
test1.c 134 0
test1.sh 10 0
File test1.c added (mode: 100644) (index 0000000..8f32fbe)
1 #define _GNU_SOURCE 500
2
3 #include <unistd.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <time.h>
7 #include <sys/time.h>
8 #include <string.h>
9
10 void test1(double *a, double *b, double *c, double *d,
11 unsigned int rounds, unsigned int array_size)
12 {
13 unsigned int i, j;
14
15 for (i = 0; i < rounds; i++) {
16 for (j = 0; j < array_size; j++) {
17 a[j] += b[j];
18 c[j] += d[j];
19 }
20 }
21 }
22
23 void test2(double *a, double *b, double *c, double *d,
24 unsigned int rounds, unsigned int array_size)
25 {
26 unsigned int i, j;
27
28 for (i = 0; i < rounds; i++) {
29 for (j = 0; j < array_size; j++)
30 a[j] += b[j];
31
32 for (j = 0; j < array_size; j++)
33 c[j] += d[j];
34 }
35 }
36
37 int main(int argc, char *argv[])
38 {
39 struct timespec s, e;
40 unsigned int array_size, offset, i, size, t, junk = 256000;
41 unsigned long diff, sum, min;
42 double *a, *b0, *b, *c0, *c, *d0, *d;
43
44 if (argc != 3) {
45 printf("Usage: %s <array_size> <offset>\n", argv[0]);
46 return 1;
47 }
48
49 array_size = strtoul(argv[1], NULL, 10);
50 offset = strtoul(argv[2], NULL, 10);
51
52 /* a */
53 size = array_size * sizeof(double) + junk;
54 a = (double *) malloc(size);
55 if (a == NULL) {
56 printf("Cannot alloc %u bytes!\n", size);
57 return 1;
58 }
59
60 /* b */
61 size = offset + array_size * sizeof(double) + junk;
62 b0 = (double *) malloc(size);
63 if (b0 == NULL) {
64 printf("Cannot alloc %u bytes!\n", size);
65 return 1;
66 }
67 b = (double *) ((unsigned char *) b0 + offset);
68
69 /* c */
70 size = offset * 2 + array_size * sizeof(double) + junk;
71 c0 = (double *) malloc(size);
72 if (c0 == NULL) {
73 printf("Cannot alloc %u bytes!\n", size);
74 return 1;
75 }
76 c = (double *) ((unsigned char *) c0 + offset * 2);
77
78 /* d */
79 size = offset * 3 + array_size * sizeof(double) + junk;
80 d0 = (double *) malloc(size);
81 if (d0 == NULL) {
82 printf("Cannot alloc %u bytes!\n", size);
83 return 1;
84 }
85 d = (double *) ((unsigned char *) d0 + offset * 3);
86
87 printf("array_size=%u array_size_bytes=%lu offset=%u"
88 " a=%p b=%p c=%p d=%p"
89 " b-a=%x c-a=%x d-a=%x\n",
90 array_size, array_size * sizeof(double), offset,
91 a, b, c, d,
92 abs(b - a), abs(c - a), abs(d - a));
93
94 for (t = 1; t <= 2; t++) {
95 sum = 0;
96 min = 0;
97 printf(" elap%u=", t);
98 for (i = 0; i < 10; i++) {
99 size = array_size * sizeof(double);
100 memset(a, 0, size);
101 memset(b, 0, size);
102 memset(c, 0, size);
103 memset(d, 0, size);
104
105 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &s);
106 if (t == 1)
107 test1(a, b, c, d, 1, array_size);
108 else
109 test2(a, b, c, d, 1, array_size);
110 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &e);
111
112 diff = (e.tv_sec - s.tv_sec) * 1000000 + (e.tv_nsec - s.tv_nsec) / 1000;
113 printf(",%lu.%06lus",
114 diff / 1000000, diff % 1000000);
115 sum += diff;
116
117 if (min == 0)
118 min = diff;
119 if (min > diff)
120 min = diff;
121 }
122 printf(" avg[%u]=%lu.%06lu min[%u]=%lu.%06lus\n",
123 t, sum / 10 / 1000000, (sum / 10) % 1000000,
124 t, min / 1000000, min % 1000000);
125 }
126 printf("\n");
127
128 free(d0);
129 free(c0);
130 free(b0);
131 free(a);
132
133 return 0;
134 }
File test1.sh added (mode: 100755) (index 0000000..4e36772)
1 #!/bin/sh
2
3 export CPUBLASTER_VERBOSE=1
4 export CPUBLASTER_LOG=test1.log
5
6 #export LD_DEBUG=libs
7 export LD_PRELOAD="${LD_PRELOAD}:./cpublaster.so"
8
9 #strace -o test1.strace -s100 -f "$@"
10 "$@"
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/catalinux/cpublaster

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/catalinux/cpublaster

Clone this repository using git:
git clone git://git.rocketgit.com/user/catalinux/cpublaster

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main