@@ -25,17 +25,23 @@ typedef struct Orb{
25
25
double vy;
26
26
double vz;
27
27
double m;
28
- short st;
28
+ double st;
29
29
}Orb;
30
30
31
31
#define G 0.000005
32
32
#define MIN_DIST 1.0
33
33
const int unitSize = 8 ;// unitSize:每个计算单位的大小,多少个float
34
- double wide = 1000 ;
34
+ double wide = 10000 ;
35
35
double mass = 10 ;
36
36
double velo = 0.005 ;
37
37
int saveTimes = 0 ;
38
38
39
+ void calcGravity (Orb*o, Orb*ta, double dist, double *gx, double *gy, double *gz);
40
+ void calcOne (Orb*o, int oId, Orb*olist, int nUnit);
41
+ Orb* newOrbList (int nUnit, int style);
42
+ void deleteOrbList (Orb *olist);
43
+ void initOrbList (Orb *olist, int nUnit, int style);
44
+
39
45
/* calc gravity between two*/
40
46
void calcGravity (Orb*o, Orb*ta, double dist, double *gx, double *gy, double *gz) {
41
47
double a = ta->m / (dist*dist) * G;
@@ -82,7 +88,9 @@ Orb* newOrbList(int nUnit, int style) {
82
88
}
83
89
84
90
void deleteOrbList (Orb *olist) {
85
-
91
+ if (olist != NULL ) {
92
+ delete (olist);
93
+ }
86
94
}
87
95
void initOrbList (Orb *olist, int nUnit, int style) {
88
96
int i = 0 ;
@@ -129,6 +137,32 @@ int main()
129
137
return 0 ;
130
138
}
131
139
140
+ cudaError_t calcOrbsWithCuda (Orb* olist, int nUnit, int nTimes) {
141
+ int * dev_a = 0 ;
142
+ int * dev_b = 0 ;
143
+ cudaError_t cudaStatus;
144
+
145
+ // Choose which GPU to run on, change this on a multi-GPU system.
146
+ cudaStatus = cudaSetDevice (0 );
147
+ if (cudaStatus != cudaSuccess) {
148
+ fprintf (stderr, " cudaSetDevice failed! Do you have a CUDA-capable GPU installed?" );
149
+ goto Error;
150
+ }
151
+
152
+ // Allocate GPU buffers for three vectors (two input, one output) .
153
+ cudaStatus = cudaMalloc ((void **)&dev_a, nUnit * sizeof (Orb));
154
+ if (cudaStatus != cudaSuccess) {
155
+ fprintf (stderr, " cudaMalloc failed!" );
156
+ goto Error;
157
+ }
158
+
159
+ Error:
160
+ cudaFree (dev_a);
161
+ cudaFree (dev_b);
162
+
163
+ return cudaStatus;
164
+ }
165
+
132
166
// Helper function for using CUDA to add vectors in parallel.
133
167
cudaError_t addWithCuda (int *c, const int *a, const int *b, unsigned int size)
134
168
{
0 commit comments