-
Notifications
You must be signed in to change notification settings - Fork 0
/
stresscache.cpp
61 lines (49 loc) · 1.13 KB
/
stresscache.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <sys/syscall.h>
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <string.h>
#include <sched.h>
#include <math.h>
#define LOOP 10000
#define MATSIZE 256
// g++ -pthread stresscache.cpp -o stresscache
pthread_t tid[32];
int mat[MATSIZE][MATSIZE];
void * thread1(void *arg)
{
int k = 0;
for (; k < LOOP; k++) {
for ( int i = 0; i < MATSIZE; i++ ) {
for ( int j = 0; j < i; j++ ) {
int aux = mat[i][j];
mat[i][j] = mat[j][i];
mat[j][i] = aux;
}
}
}
return NULL;
}
int main(int argc, const char *argv[])
{
if(argc < 1) {
return -1;
}
int cnt = atoi(argv[1]);
for ( int i = 0; i < MATSIZE; i++ ) {
for ( int j = 0; j < MATSIZE; j++ ) {
mat[i][j] = i+j;
}
}
for(int i = 0; i < cnt; i++) {
pthread_create ( &(tid[i]), NULL, thread1, NULL ) ;
}
for(int i = 0; i < cnt; i++) {
pthread_join(tid[i], NULL);
}
return 0;
}