-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathhalfhalf.c
More file actions
71 lines (54 loc) · 1.28 KB
/
halfhalf.c
File metadata and controls
71 lines (54 loc) · 1.28 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "delay.h"
#include "queue.h"
#ifndef LOGN_OPS
#define LOGN_OPS 7
#endif
static long nops;
static queue_t * q;
static handle_t ** hds;
void init(int nprocs, int logn) {
/** Use 10^7 as default input size. */
if (logn == 0) logn = LOGN_OPS;
/** Compute the number of ops to perform. */
nops = 1;
int i;
for (i = 0; i < logn; ++i) {
nops *= 10;
}
printf(" Number of operations: %ld\n", nops);
q = align_malloc(PAGE_SIZE, sizeof(queue_t));
queue_init(q, nprocs);
hds = align_malloc(PAGE_SIZE, sizeof(handle_t * [nprocs]));
}
void thread_init(int id, int nprocs) {
hds[id] = align_malloc(PAGE_SIZE, sizeof(handle_t));
queue_register(q, hds[id], id);
}
void thread_exit(int id, int nprocs) {
queue_free(q, hds[id]);
}
void * benchmark(int id, int nprocs) {
void * val = (void *) (intptr_t) (id + 1);
handle_t * th = hds[id];
delay_t state;
delay_init(&state, id);
struct drand48_data rstate;
srand48_r(id, &rstate);
int i;
for (i = 0; i < nops / nprocs; ++i) {
long n;
lrand48_r(&rstate, &n);
if (n % 2 == 0)
enqueue(q, th, val);
else
dequeue(q, th);
delay_exec(&state);
}
return val;
}
int verify(int nprocs, void ** results) {
return 0;
}