-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathtest.cpp
More file actions
64 lines (58 loc) · 1.56 KB
/
test.cpp
File metadata and controls
64 lines (58 loc) · 1.56 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
#include <iostream>
#include <unistd.h>
#include "dataTypesAndContainers.h"
#include "noiseSource.h"
int main(int argc, char*argv[])
{
int c;
int n = 1;
while((c=getopt(argc,argv,"n:")) != -1)
switch(c)
{
case 'n': n = atoi(optarg); break;
case '?':
if(optopt=='c')
std::cerr<<"Option -" << optopt << "requires an argument.\n";
else if(isprint(optopt))
std::cerr<<"Unknown option '-" << optopt << "'.\n";
else
std::cerr << "Unknown option character.\n";
return 1;
default:
abort();
};
#ifdef ENABLE_CUDA
printf("cuda enabled. x = %i\n",n);
#endif
//initialize with data
GPUArray<float2> test(n);
float2 intSum; intSum.x=0;intSum.y=0;
{
ArrayHandle<float2> t(test);
for (int ii = 0; ii < n; ++ii)
{
t.data[ii].x = ii;
t.data[ii].y = -ii;
intSum = intSum - t.data[ii];
}
}
float sum1 = 0;
float sum2 = 0;
#ifdef ENABLE_CUDA
//sum reduction on device?
UNWRITTENCODE("not done yet");
#else
noiseSource noise(false);
{//sum reduction on host
ArrayHandle<float2> t(test);
for (int ii = 0; ii < n; ++ii)
{
sum1 += t.data[ii].x;
sum2 += t.data[ii].y + noise.getRealUniform(-.1,.1);
}
}
#endif
std::cout << sum1<< " " << sum2 << std::endl;
std::cout << intSum.x<< " " << intSum.y << std::endl;
return 0;
};