-
Notifications
You must be signed in to change notification settings - Fork 8
/
util.c
67 lines (55 loc) · 1.12 KB
/
util.c
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
/*
Stencil Probe utilities
Helper functions for the probe.
*/
#include <stdio.h>
#include <stdlib.h>
#include "util.h"
#include "cycle.h"
/*
This initializes the array A to be all 1's.
This is nearly superfluous (could use memset), but
provides convenience and consistency nonetheless...
*/
void StencilInit(int nx,int ny,int nz, /* size of the array */
double *A){ /* the array to initialize to 1s */
long last = nx*ny*nz;
long i;
for(i=0;i<last;i++)
#ifdef RANDOMVALUES
A[i]=(float)rand()/RAND_MAX;
#else
A[i]=1.0;
#endif
}
/*
This function determines ticks per second.
Inspired by OSKI function (bebop.cs.berkeley.edu)
*/
double seconds_per_tick()
{
ticks t0,t1;
unsigned int i = 3;
double spt = 0;
while (spt <= 0)
{
t0=getticks();
sleep(i);
t1=getticks();
spt = (double)i / elapsed(t1,t0);
i++;
}
return spt;
}
/*
Function to clear the cache, preventing data items in cache
from making subsequent trials run faster.
*/
void clear_cache()
{
int i;
float* tarray, accum;
tarray = (float*) malloc(sizeof(float)*1310720);
for (i=0,accum=0; i<1310719; i++)
tarray[i] = 1.0;
}