aboutsummaryrefslogtreecommitdiff
path: root/benchmarks/sdisorder/sdisorder.c
blob: 8698c77d96a2ac5aff86ac32b52b4282803526ed (plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "util.h"

#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>


#ifndef MLP
  #define MLP 32
#endif
#ifndef STEP
#define STEP 16
#endif


void InitStream(uint *a, uint n) {
  for (uint i=0; i<n; i++)
    a[i] = (i+STEP) % n;
}

// TODO: Verify this does the random shuffling well
void ShuffleStream(uint *a, uint n) {
  if (n>1) {
    uint i;
    for (i = 0; i < n-1; i++) {
      uint j = (i + rand() / (RAND_MAX / (n-i)+1)) % n;
        uint t = a[j];
        a[j] = a[i];
        a[i] = t;
    }
  }
}


int Chase(uint *a, uint n, uint iterations) {
  uint loc[MLP];
  for (uint m=0; m<MLP; m++)
    loc[m] = (m * (n/MLP) + m) % n;

  for (uint k=0; k<iterations; k++) {
    for (uint i=0; i<n/MLP; i++) {
      for (uint m=0; m<MLP; m++) {
        loc[m] = a[loc[m]];
      }
    }
  }
  for (uint m=0; m<MLP; m++) {
    if (loc[m] < 0) {
      //printf("woah\n");
    }
  }
  return loc[n];
}


void RandGenBench(int n) {
  long total=0;
  for (int i=0; i<n; i++) {
    total += (rand() % 1) + 1;
  }
}


void thread_entry(int cid, int nc)
{
  while (cid != 0) {
    clogMem(1<<16, 64>>2,1<<7);
  }
}

int main(int argc, char* argv[]) {

  uint num_iters = 1;
  uint length = 1<<16;
  uint randomize = 0;

  uint stream[length];
  InitStream(stream, length);

  if (randomize) {
    ShuffleStream(stream, length);
  }

  randomize = Chase(stream, length, num_iters);

}