/
main.c
executable file
·85 lines (62 loc) · 1.83 KB
/
main.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
static char const cvsid[] = "$Id: main.c,v 2.1 2005/06/14 22:16:51 jls Exp $";
/*
* Copyright 2005 SRC Computers, Inc. All Rights Reserved.
*
* Manufactured in the United States of America.
*
* SRC Computers, Inc.
* 4240 N Nevada Avenue
* Colorado Springs, CO 80907
* (v) (719) 262-0213
* (f) (719) 262-0223
*
* No permission has been granted to distribute this software
* without the express permission of SRC Computers, Inc.
*
* This program is distributed WITHOUT ANY WARRANTY OF ANY KIND.
*/
#include <libmap.h>
#include <stdlib.h>
#define MAX_OBM_SIZE 512000
void subr (double d_arr[], double *res, int m, int64_t *tm, int mapnum);
int main (int argc, char *argv[]) {
FILE *res_map, *res_cpu;
int i, num;
double *D_src, res, acc;
int64_t tm;
int mapnum = 0;
if ((res_map = fopen ("res_map.flt", "w")) == NULL) {
fprintf (stderr, "failed to open file 'res_map.flt'\n");
exit (1);
}
if ((res_cpu = fopen ("res_cpu.flt", "w")) == NULL) {
fprintf (stderr, "failed to open file 'res_cpu.flt'\n");
exit (1);
}
if (argc < 2) {
fprintf (stderr, "need number of elements as arg\n");
exit (1);
}
if (sscanf (argv[1], "%d", &num) < 1) {
fprintf (stderr, "need number of elements as arg\n");
exit (1);
}
if ((num < 1) || (num > MAX_OBM_SIZE)) {
fprintf (stderr, "number of elements must be in the range 1 through %d\n", MAX_OBM_SIZE);
exit (1);
}
D_src = (double*) malloc (num * sizeof (double));
srandom (99);
acc = 0.0;
for (i=0; i<num; i++) {
D_src[i] = (double)random() / random();
acc += D_src[i];
}
fprintf (res_cpu, "%lf\n", acc);
map_allocate (1);
subr (D_src, &res, num, &tm, mapnum);
printf ("%lld clocks\n", tm);
fprintf (res_map, "%lf\n", res);
map_free (1);
exit(0);
}