forked from tromp/cuckoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcuckoo_miner.cpp
55 lines (53 loc) · 1.72 KB
/
cuckoo_miner.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
// Cuckoo Cycle, a memory-hard proof-of-work
// Copyright (c) 2013-2014 John Tromp
#include "cuckoo_miner.h"
#include <unistd.h>
int main(int argc, char **argv) {
int nthreads = 1;
int maxsols = 8;
int ntrims = 1 + (PART_BITS+3)*(PART_BITS+4)/2;
const char *header = "";
int c;
while ((c = getopt (argc, argv, "h:m:n:t:")) != -1) {
switch (c) {
case 'h':
header = optarg;
break;
case 'm':
maxsols = atoi(optarg);
break;
case 'n':
ntrims = atoi(optarg);
break;
case 't':
nthreads = atoi(optarg);
break;
}
}
printf("Looking for %d-cycle on cuckoo%d(\"%s\") with 50%% edges, %d trims, %d threads\n",
PROOFSIZE, SIZESHIFT, header, ntrims, nthreads);
u64 edgeBytes = HALFSIZE/8, nodeBytes = TWICE_WORDS*sizeof(u32);
int edgeUnit, nodeUnit;
for (edgeUnit=0; edgeBytes >= 1024; edgeBytes>>=10,edgeUnit++) ;
for (nodeUnit=0; nodeBytes >= 1024; nodeBytes>>=10,nodeUnit++) ;
printf("Using %d%cB edge and %d%cB node memory.\n",
(int)edgeBytes, " KMGT"[edgeUnit], (int)nodeBytes, " KMGT"[nodeUnit]);
cuckoo_ctx ctx(header, nthreads, ntrims, maxsols);
thread_ctx *threads = (thread_ctx *)calloc(nthreads, sizeof(thread_ctx));
assert(threads);
for (int t = 0; t < nthreads; t++) {
threads[t].id = t;
threads[t].ctx = &ctx;
assert(pthread_create(&threads[t].thread, NULL, worker, (void *)&threads[t]) == 0);
}
for (int t = 0; t < nthreads; t++)
assert(pthread_join(threads[t].thread, NULL) == 0);
free(threads);
for (unsigned s = 0; s < ctx.nsols; s++) {
printf("Solution");
for (int i = 0; i < PROOFSIZE; i++)
printf(" %lx", (long)ctx.sols[s][i]);
printf("\n");
}
return 0;
}